X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/e0f595e44766e352edfce0aaf5d32be57f448882..0f2ac86f03177aebee66a3890120d9926272cf27:/src/sources/models.py?ds=sidebyside diff --git a/src/sources/models.py b/src/sources/models.py index 0b55c890..efa086a5 100644 --- a/src/sources/models.py +++ b/src/sources/models.py @@ -38,6 +38,10 @@ class Source(models.Model): def get_ocr_directory(self): return f'sources/ocr/{self.pk}/' + def has_upload_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_upload_directory()) + return os.path.isdir(d) and os.listdir(d) + def get_view_files(self): d = self.get_view_directory() return [ @@ -47,6 +51,10 @@ class Source(models.Model): )) ] + def has_view_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_view_directory()) + return os.path.isdir(d) and os.listdir(d) + def get_ocr_files(self): d = os.path.join(settings.MEDIA_ROOT, self.get_ocr_directory()) return [ @@ -54,7 +62,12 @@ class Source(models.Model): for name in sorted(os.listdir(d)) ] + def has_ocr_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_ocr_directory()) + return os.path.isdir(d) and os.listdir(d) + def process(self): + processed_at = now() updir = os.path.join( settings.MEDIA_ROOT, self.get_upload_directory() @@ -71,7 +84,7 @@ class Source(models.Model): self.build_view_directory(updir, d) with utils.replace_dir(ocr_dir) as d: self.build_ocr_directory(updir, d) - self.processed_at = now() + self.processed_at = processed_at self.save(update_fields=['processed_at']) def build_view_directory(self, srcpath, targetpath):