From 26bfde6138abea6603e260c642505a286950c8ed Mon Sep 17 00:00:00 2001 From: seiferta Date: Sat, 23 Apr 2016 23:38:41 +0200 Subject: [PATCH] sample layout for fax-checker added and implemented for fez checker. In checker type selection download for sample added --- emonitor/modules/alarms/__init__.py | 4 + emonitor/modules/alarms/alarmutils.py | 25 +- emonitor/modules/alarms/inc/faxchecker_fez.py | 61 ++- .../alarms/templates/admin.alarms.type.html | 3 +- .../translations/de/LC_MESSAGES/modules.mo | Bin 83034 -> 83097 bytes .../translations/de/LC_MESSAGES/modules.po | 399 +++++++++++------- emonitor/modules/translations/modules.pot | 388 ++++++++++------- 7 files changed, 574 insertions(+), 306 deletions(-) diff --git a/emonitor/modules/alarms/__init__.py b/emonitor/modules/alarms/__init__.py index 5392c4b..b58912a 100644 --- a/emonitor/modules/alarms/__init__.py +++ b/emonitor/modules/alarms/__init__.py @@ -73,6 +73,10 @@ def __init__(self, app): # static folders @app.route('/alarms/inc/') def alarms_static(filename): + if filename.startswith('sample_'): # deliver sample checker file + clsname = filename.split('_')[1] + return Response(AlarmType.getAlarmTypes(clsname).interpreterclass().getSampleLayout(), mimetype="image/jpeg") + return send_from_directory("{}/emonitor/modules/alarms/inc/".format(app.config.get('PROJECT_ROOT')), filename) @app.route('/alarms/export/') # filename = [id]-[style].pdf diff --git a/emonitor/modules/alarms/alarmutils.py b/emonitor/modules/alarms/alarmutils.py index c8c721c..9db987f 100644 --- a/emonitor/modules/alarms/alarmutils.py +++ b/emonitor/modules/alarms/alarmutils.py @@ -3,7 +3,8 @@ import logging import datetime, time import requests -import json +from StringIO import StringIO +from PIL import Image, ImageDraw, ImageFont from collections import OrderedDict from sqlalchemy import inspect from flask import current_app @@ -251,6 +252,28 @@ def buildAlarmFromText(self, alarmtype, rawtext): """ return dict() + def getSampleLayout(self): + """ + create sample layout file and return file + :return: sample as jpeg image + """ + img_sample = Image.new('RGB', (2480, 3508), (255, 255, 255)) # DIN-A4 72 dpi + font = ImageFont.truetype("times.ttf", 60) + + draw = ImageDraw.Draw(img_sample) + lines = [u'Sample not set'] + t = 10 + for line in lines: + size = font.getsize(line) + l = (2480 - size[0]) / 2 + t += size[1] + 20 + draw.text((l, t), line, (0, 0, 0), font=font) + + draw.line((40, t + 100, 2400, t + 100), fill=256, width=3) + output = StringIO() + img_sample.save(output, format="JPEG", dpi=(300, 300)) + return output.getvalue() + def getAlarmRoute(alarm): """ diff --git a/emonitor/modules/alarms/inc/faxchecker_fez.py b/emonitor/modules/alarms/inc/faxchecker_fez.py index 67deca2..1e07a1c 100644 --- a/emonitor/modules/alarms/inc/faxchecker_fez.py +++ b/emonitor/modules/alarms/inc/faxchecker_fez.py @@ -1,6 +1,7 @@ from collections import OrderedDict import re import difflib +from StringIO import StringIO from emonitor.modules.alarms.alarmutils import AlarmFaxChecker from emonitor.modules.streets.street import Street from emonitor.modules.streets.city import City @@ -8,6 +9,7 @@ from emonitor.modules.settings.department import Department from emonitor.modules.alarmkeys.alarmkey import Alarmkey from emonitor.modules.alarmobjects.alarmobject import AlarmObject +from PIL import Image, ImageDraw, ImageFont __all__ = ['FezAlarmFaxChecker'] @@ -17,7 +19,7 @@ class FezAlarmFaxChecker(AlarmFaxChecker): fax checker implementation for Feuerwehreinsatzzentrale Muenchen Land (FEZ) with special layout """ __name__ = "FEZ" - __version__ = '0.2' + __version__ = '0.3' fields = {} sections = OrderedDict() @@ -405,7 +407,6 @@ def buildAlarmFromText(self, alarmtype, rawtext): curr_field = "" - #for l in rawtext.decode('utf-8').split(u"\n"): for l in rawtext.split(u"\n"): field = difflib.get_close_matches(re.split(u':|=|i ', l)[0], sectionnames.keys(), 1) # test line ->:|= if len(field) == 0 and u" " in l: @@ -423,7 +424,6 @@ def buildAlarmFromText(self, alarmtype, rawtext): curr_field = field[0] elif curr_field != '': if sectionnames[curr_field] != u'': - #FezAlarmFaxChecker().fields[sectionnames[curr_field]] = (FezAlarmFaxChecker().fields[sectionnames[curr_field]][0] + u'\n' + value, FezAlarmFaxChecker().fields[sectionnames[curr_field]][1]) if value[0] == u' ': FezAlarmFaxChecker().fields[sectionnames[curr_field]] = (u"\n".join((FezAlarmFaxChecker().fields[sectionnames[curr_field]][0], value)), FezAlarmFaxChecker().fields[sectionnames[curr_field]][1]) else: @@ -454,3 +454,58 @@ def buildAlarmFromText(self, alarmtype, rawtext): except: values[k] = (FezAlarmFaxChecker().fields[k][0], FezAlarmFaxChecker().fields[k][1]) return values + + def getSampleLayout(self): + """ + create sample layout file and return file + :return: sample as jpeg image + """ + img_sample = Image.new('RGB', (2480, 3508), (255, 255, 255)) # DIN-A4 72 dpi + font = ImageFont.truetype("times.ttf", 60) + + draw = ImageDraw.Draw(img_sample) + lines = [u'Alarmschreiben', + u'Feuerwehreinsatzzentrale Landkreis M\xfcnchen Land', + u'Telefon: +49 (89) 1234-56789 Telefax: +49 (89) 4444-123456'] + t = 10 + for line in lines: + size = font.getsize(line) + l = (2480 - size[0]) / 2 + t += size[1] + 20 + draw.text((l, t), line, (0, 0, 0), font=font) + + draw.line((40, t + 100, 2400, t + 100), fill=256, width=3) + draw.text((40, t + 120), u'Einsatznr:' + u' ' * 20 + u'B 1.4.2 160101 000 ' + u' ' * 20 + u'Alarm: 01.01.2016 00:01', (0, 0, 0), font=font) + draw.line((40, t + 200, 2400, t + 200), fill=256, width=3) + + draw.text((40, t + 300), u'Mitteiler:' + u' ' * 30 + u'Person ABC', (0, 0, 0), font=font) + draw.text((40, t + 400), u'Einsatzort:', (0, 0, 0), font=font) + draw.text((40, t + 460), u'Stra\xdfe:' + u' ' * 34 + u'Musterstra\xdfe 1 3a', (0, 0, 0), font=font) + draw.text((40, t + 520), u'Abschnitt:', (0, 0, 0), font=font) + draw.text((40, t + 660), u'Kreuzung:', (0, 0, 0), font=font) + draw.text((40, t + 780), u'Ortsteil/Ort:' + u' ' * 26 + u'Musterstadt in 80000 Musterstadt, Kr M\xfcnchen', (0, 0, 0), font=font) + + draw.text((40, t + 900), u'Objekt:', (0, 0, 0), font=font) + draw.text((40, t + 1000), u'Einsatzplan:', (0, 0, 0), font=font) + + draw.line((40, t + 1100, 2400, t + 1100), fill=256, width=3) + draw.text((40, t + 1140), u'Meldebild:' + u' ' * 28 + u'Wasserschaden', (0, 0, 0), font=font) + draw.line((40, t + 1240, 2400, t + 1240), fill=256, width=3) + + draw.text((40, t + 1300), u'Hinweis:' + u' ' * 30 + u'Achtung nass!', (0, 0, 0), font=font) + draw.line((40, t + 1440, 2400, t + 1440), fill=256, width=3) + draw.line((40, t + 1500, 2400, t + 1500), fill=256, width=3) + + draw.text((40, t + 1520), u'Geforderte Einsatzmittel bzw. Ausr\xfcstung:', (0, 0, 0), font=font) + + draw.text((70, t + 1600), u'1.4.2 M-L FF Musterstadt', (0, 0, 0), font=font) + draw.text((70, t + 1680), u'1.4.2 M-L FF Musterstadt 40/1', (0, 0, 0), font=font) + draw.text((70, t + 1760), u'1.4.2 M-L FF Musterstadt 65/1', (0, 0, 0), font=font) + + draw.text((40, t + 1900), u'(Alarmschreiben Ende)', (0, 0, 0), font=font) + draw.line((40, t + 2000, 2400, t + 2000), fill=256, width=3) + + draw.text((40, t + 2060), u'Auch bei Erhalt des Alarmschreiben den EINSATZORT \xfcber Funk best\xe4tigen!!', (0, 0, 0), font=font) + output = StringIO() + img_sample.save(output, format="JPEG", dpi=(300, 300)) + return output.getvalue() diff --git a/emonitor/modules/alarms/templates/admin.alarms.type.html b/emonitor/modules/alarms/templates/admin.alarms.type.html index 15e1136..c0e22c3 100644 --- a/emonitor/modules/alarms/templates/admin.alarms.type.html +++ b/emonitor/modules/alarms/templates/admin.alarms.type.html @@ -42,12 +42,13 @@

{{ _('alarms.type.header.overview') }}

{% for alarmtype in alarmtypes %}
-
+
{{ alarmtype.name }}
{{ alarmtype.keywords.replace('\r\n', ', ') }}
+