From 1286fa6f2f845144f4dbda361057a10ca02abd7f Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 14 Oct 2022 15:30:08 +0200 Subject: [PATCH 1/8] Version 6.0.0 --- README.rst | 1 + tryton.cfg | 1 + 2 files changed, 2 insertions(+) diff --git a/README.rst b/README.rst index ab62e82..f2bfb6f 100644 --- a/README.rst +++ b/README.rst @@ -17,3 +17,4 @@ Changes *6.0.0 - 14.10.2022* - init + diff --git a/tryton.cfg b/tryton.cfg index f603792..f9732b4 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,3 +5,4 @@ depends: xml: message.xml line.xml + From fa526fa69ecf325d81b25cd70e2322f9ba3396ec Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Tue, 29 Nov 2022 10:30:39 +0100 Subject: [PATCH 3/8] 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 + From 51934f46bc637dc804737f0053bcb9cceb78d2b6 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Tue, 29 Nov 2022 10:37:05 +0100 Subject: [PATCH 4/8] Version 6.0.1 --- README.rst | 4 ++++ tryton.cfg | 2 +- versiondep.txt | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index f2bfb6f..54a2ee6 100644 --- a/README.rst +++ b/README.rst @@ -14,6 +14,10 @@ Requires Changes ======= +*6.0.1 - 29.11.2022* + +- fix: exception when image type unknown + *6.0.0 - 14.10.2022* - init diff --git a/tryton.cfg b/tryton.cfg index f9732b4..59527ab 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.0.0 +version=6.0.1 depends: cashbook xml: diff --git a/versiondep.txt b/versiondep.txt index 7a98af6..a43e322 100644 --- a/versiondep.txt +++ b/versiondep.txt @@ -1 +1 @@ -cashbook;6.0.18;6.0.999;mds +cashbook;6.0.20;6.0.999;mds From 3750a4b0f632ff8022df32a0a233aabf20157d98 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Fri, 30 Dec 2022 23:02:04 +0100 Subject: [PATCH 6/8] depends korrigiert --- line.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/line.py b/line.py index 3949a8b..5569506 100644 --- a/line.py +++ b/line.py @@ -28,17 +28,23 @@ except : image_limit = 2000 +STATES2 = {} +STATES2.update(STATES) +DEPENDS2 = [] +DEPENDS2.extend(DEPENDS) + + class Line(metaclass=PoolMeta): __name__ = 'cashbook.line' media = fields.Binary(string='Image of PDF', filename='media_name', file_id='media_id', store_prefix=store_prefix, - states=STATES, depends=DEPENDS) + states=STATES2, depends=DEPENDS2) media_name = fields.Char(string='File name', states={ 'required': Bool(Eval('media')), - 'readonly': STATES['readonly'], - }, depends=DEPENDS) + 'readonly': STATES2['readonly'], + }, depends=DEPENDS2) media_id = fields.Char(string='File ID', readonly=True) media_mime = fields.Char(string='MIME', readonly=True) media_size = fields.Integer(string='File size', readonly=True) From a149f46dbbd2512187ea533c4c355409a590c1ca Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Mon, 23 Jan 2023 13:11:54 +0100 Subject: [PATCH 7/8] line: show image in tab 'image/pdf' --- line.py | 12 ++++++++++++ locale/de.po | 3 +++ view/line_form.xml | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/line.py b/line.py index 5569506..34e32af 100644 --- a/line.py +++ b/line.py @@ -48,6 +48,18 @@ class Line(metaclass=PoolMeta): media_id = fields.Char(string='File ID', readonly=True) media_mime = fields.Char(string='MIME', readonly=True) media_size = fields.Integer(string='File size', readonly=True) + media_image = fields.Function(fields.Binary(string='Image', readonly=True, + states={ + 'invisible': ~Eval('media_mime', '').in_(['image/png', 'image/jpg', 'image/jpeg']), + }, depends=['media_mime']), + 'on_change_with_media_image') + + @fields.depends('media', 'media_mime') + def on_change_with_media_image(self, name=True): + """ return binary if its a image + """ + if (self.media_mime or '-').startswith('image/'): + return self.media @classmethod def _identify_file(cls, data, mime=True): diff --git a/locale/de.po b/locale/de.po index 052a9fb..7618e5c 100644 --- a/locale/de.po +++ b/locale/de.po @@ -46,3 +46,6 @@ msgctxt "field:cashbook.line,media_size:" msgid "File size" msgstr "Dateigröße" +msgctxt "field:cashbook.line,media_image:" +msgid "Image" +msgstr "Bild" diff --git a/view/line_form.xml b/view/line_form.xml index 6785333..0d80ebc 100644 --- a/view/line_form.xml +++ b/view/line_form.xml @@ -13,10 +13,10 @@ full copyright notices and license terms. -->