Feature: number of pages of document in documents list

This commit is contained in:
s0llvan
2024-09-21 18:18:19 +00:00
parent 609fa9a212
commit 865856b06d
19 changed files with 318 additions and 58 deletions

View File

@@ -361,6 +361,7 @@ class DocumentViewSet(
"archive_serial_number",
"num_notes",
"owner",
"pages_count",
)
def get_queryset(self):
@@ -444,6 +445,24 @@ class DocumentViewSet(
logger.warning(f"No parser for {mime_type}")
return []
def get_pages_count(self, file, mime_type):
if not os.path.isfile(file):
return None
parser_class = get_parser_class_for_mime_type(mime_type)
if parser_class:
parser = parser_class(progress_callback=None, logging_group=None)
try:
return parser.get_pages_count(file)
except Exception: # pragma: no cover
logger.exception(f"Issue getting pages count for {file}")
# TODO: cover GPG errors, remove later.
return []
else: # pragma: no cover
logger.warning(f"No parser for {mime_type}")
return []
def get_filesize(self, filename):
if os.path.isfile(filename):
return os.stat(filename).st_size