fix: exception beim hochladen eines unbekannten bildtypes

This commit is contained in:
Frederik Jaeckel 2022-11-29 10:30:39 +01:00
parent 2933a217e2
commit a3a3d2002e
5 changed files with 19 additions and 2 deletions

View file

@ -1,3 +1,6 @@
syntax: glob syntax: glob
__pycache__/* __pycache__/*
locale/convert_de2en.py locale/convert_de2en.py
build/*
mds_cashbook_media.egg-info/*
dist/*

View file

@ -5,7 +5,7 @@
import mimetypes, magic import mimetypes, magic
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image, UnidentifiedImageError
from trytond.model import fields from trytond.model import fields
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.config import config from trytond.config import config
@ -65,7 +65,10 @@ class Line(metaclass=PoolMeta):
""" """
image_data2 = None image_data2 = None
with BytesIO(image_data) as fhdl: with BytesIO(image_data) as fhdl:
try :
image = Image.open(fhdl, 'r') image = Image.open(fhdl, 'r')
except UnidentifiedImageError:
raise UserError(gettext('cashbook_media.msg_file_unknown_type'))
(width, height) = image.size (width, height) = image.size
if (width > image_limit) or (height > image_limit): if (width > image_limit) or (height > image_limit):

View file

@ -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)" 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)" 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 # # cashbook.line #

View file

@ -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)" 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)" 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:" msgctxt "view:cashbook.line:"
msgid "Image/PDF" msgid "Image/PDF"
msgstr "Image/PDF" msgstr "Image/PDF"

View file

@ -11,6 +11,9 @@ full copyright notices and license terms. -->
<record model="ir.message" id="msg_file_invalid_mime"> <record model="ir.message" id="msg_file_invalid_mime">
<field name="text">The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)</field> <field name="text">The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)</field>
</record> </record>
<record model="ir.message" id="msg_file_unknown_type">
<field name="text">cannot identify image file</field>
</record>
</data> </data>
</tryton> </tryton>