From a3a3d2002e5de09cf957006c7a417803e5a50114 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Tue, 29 Nov 2022 10:30:39 +0100 Subject: [PATCH] fix: exception beim hochladen eines unbekannten bildtypes --- .hgignore | 3 +++ line.py | 7 +++++-- locale/de.po | 4 ++++ locale/en.po | 4 ++++ message.xml | 3 +++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.hgignore b/.hgignore index 1b85cd9..913ee1b 100644 --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,6 @@ syntax: glob __pycache__/* locale/convert_de2en.py +build/* +mds_cashbook_media.egg-info/* +dist/* diff --git a/line.py b/line.py index a7a482d..3949a8b 100644 --- a/line.py +++ b/line.py @@ -5,7 +5,7 @@ import mimetypes, magic from io import BytesIO -from PIL import Image +from PIL import Image, UnidentifiedImageError from trytond.model import fields from trytond.pool import Pool, PoolMeta from trytond.config import config @@ -65,7 +65,10 @@ class Line(metaclass=PoolMeta): """ image_data2 = None with BytesIO(image_data) as fhdl: - image = Image.open(fhdl, 'r') + try : + image = Image.open(fhdl, 'r') + except UnidentifiedImageError: + raise UserError(gettext('cashbook_media.msg_file_unknown_type')) (width, height) = image.size if (width > image_limit) or (height > image_limit): diff --git a/locale/de.po b/locale/de.po index 69df498..052a9fb 100644 --- a/locale/de.po +++ b/locale/de.po @@ -14,6 +14,10 @@ msgctxt "model:ir.message,text:msg_file_invalid_mime" msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)" msgstr "Der Dateityp '%(fmime)s' des Datensatzes '%(recname)s' ist nicht zugelassen. (erlaubt: PNG, JPG, PDF)" +msgctxt "model:ir.message,text:msg_file_unknown_type" +msgid "cannot identify image file" +msgstr "Bilddatei kann nicht identifiziert werden" + ################# # cashbook.line # diff --git a/locale/en.po b/locale/en.po index 956e614..5ff9df6 100644 --- a/locale/en.po +++ b/locale/en.po @@ -10,6 +10,10 @@ msgctxt "model:ir.message,text:msg_file_invalid_mime" msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)" msgstr "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)" +msgctxt "model:ir.message,text:msg_file_unknown_type" +msgid "cannot identify image file" +msgstr "cannot identify image file" + msgctxt "view:cashbook.line:" msgid "Image/PDF" msgstr "Image/PDF" diff --git a/message.xml b/message.xml index d88ff9a..3582d1e 100644 --- a/message.xml +++ b/message.xml @@ -11,6 +11,9 @@ full copyright notices and license terms. --> The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF) + + cannot identify image file +