Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Přidaná ikona pdf #2669

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions webclient/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def get_thumb_icon(cls, file):
"application/rtf": "rtf.png",
"application/vnd.oasis.opendocument.text": "odt.png",
"application/vnd.oasis.opendocument.spreadsheet": "ods.png",
"application/pdf": "pdf.png",
}.get(mime_type, None)
if icon_filename:
file_path = os.path.join(settings.STATICFILES_DIRS[0], "icons", icon_filename)
Expand Down
31 changes: 17 additions & 14 deletions webclient/core/repository_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,31 +699,32 @@ def resize_image(image: BytesIO, large_inner=False):
output_buffer.seek(0)
return output_buffer

if file_name.lower().endswith(".pdf"):
def __generate_thumb_from_icon(file_name: str, file_content: BytesIO, large=False):
from core.models import Soubor

thumb_icon = Soubor.get_thumb_icon(file_content)
if thumb_icon is not None:
file_content = thumb_icon
try:
images = convert_from_bytes(file_content.getvalue(), first_page=1, last_page=1)
image_bytes_io = io.BytesIO()
images[0].save(image_bytes_io, format="PNG")
image_bytes_io.seek(0)
thumbnail = resize_image(image_bytes_io, large)
thumbnail = resize_image(file_content, large)
logger.debug(
"core_repository_connector.__generate_thumb.end", extra={"file_name": file_name, "large": large}
)
return thumbnail
except Exception as err:
logger.debug(
logger.error(
"core_repository_connector.__generate_thumb.error",
extra={"err": err, "file_name": file_name, "large": large},
)
return None
else:
from core.models import Soubor

thumb_icon = Soubor.get_thumb_icon(file_content)
if thumb_icon is not None:
file_content = thumb_icon
if file_name.lower().endswith(".pdf"):
try:
thumbnail = resize_image(file_content, large)
images = convert_from_bytes(file_content.getvalue(), first_page=1, last_page=1)
image_bytes_io = io.BytesIO()
images[0].save(image_bytes_io, format="PNG")
image_bytes_io.seek(0)
thumbnail = resize_image(image_bytes_io, large)
logger.debug(
"core_repository_connector.__generate_thumb.end", extra={"file_name": file_name, "large": large}
)
Expand All @@ -733,7 +734,9 @@ def resize_image(image: BytesIO, large_inner=False):
"core_repository_connector.__generate_thumb.error",
extra={"err": err, "file_name": file_name, "large": large},
)
return None
return __generate_thumb_from_icon(file_name, file_content, large)
else:
return __generate_thumb_from_icon(file_name, file_content, large)

def save_thumbs(self, file_name, file, uuid, update=False, ident_cely_old=None):
logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion webclient/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_cadastre_from_point(point):
)
return katastr
except IndexError:
logger.error("core.utils.get_cadastre_from_point.error", extra={"point_0": point[0], "point_1": point[1]})
logger.warning("core.utils.get_cadastre_from_point.error", extra={"point_0": point[0], "point_1": point[1]})
return None


Expand Down
Binary file added webclient/static/icons/pdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading