Skip to content

Commit

Permalink
add additional field handling for persons
Browse files Browse the repository at this point in the history
  • Loading branch information
seiferta committed May 4, 2016
1 parent 26bfde6 commit ccdd386
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 10 deletions.
19 changes: 18 additions & 1 deletion emonitor/modules/persons/content_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import werkzeug
import yaml
from datetime import datetime
from flask import render_template, request, current_app
from emonitor.extensions import db
Expand Down Expand Up @@ -49,6 +50,11 @@ def getAdminContent(self, **params):
pass
person.identifier = request.form.get('identifier')
person.remark = request.form.get('remark')
_additional = {}
for field in Settings.get('persons.settings').get('additional'):
if field.split('=')[0] in request.form.keys():
_additional[field.split('=')[0]] = request.form.get(field.split('=')[0])
person._options = yaml.safe_dump(_additional, encoding='utf-8')
db.session.commit()

elif request.form.get('action').startswith('deleteperson_'):
Expand All @@ -74,6 +80,14 @@ def getAdminContent(self, **params):
Settings.set('persons.settings', _settings)
db.session.commit()

elif request.form.get('action') == 'updateadditional':
_settings = Settings.get('persons.settings')
if 'additional' not in _settings.keys():
_settings['additional'] = []
_settings['additional'] = request.form.get('additional').replace('\r', '').split('\n')
Settings.set('persons.settings', _settings)
db.session.commit()

if int(module[1]) == 0:
params.update({'settings': Settings.get('persons.settings')})
return render_template("admin.persons.settings.html", **params)
Expand Down Expand Up @@ -129,7 +143,10 @@ def getAdminData(self):
for key in vals['persons']: # item list
if key['state'] in states: # import only with correct state
if key['state'] == '-1': # add key
key['birthdate'] = datetime.strptime(key['birthdate'], '%d.%m.%Y')
try:
key['birthdate'] = datetime.strptime(key['birthdate'], '%d.%m.%Y')
except:
print ">>>>", key['birthdate']
key['active'] = key['active'] == 'Aktiv'
p = Person(key['firstname'], key['lastname'], key['salutation'], key['grade'], key['position'], key['identifier'], key['active'], key['birthdate'], key['remark'], int(request.args.get('department')))
db.session.add(p)
Expand Down
4 changes: 4 additions & 0 deletions emonitor/modules/persons/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def birthday(self):
"""
return int((datetime(1904, *self.birthdate.timetuple()[1:-2])).strftime('%j'))

@property
def options(self):
return yaml.load(self._options)

@staticmethod
def getPersons(id=0, identifier=0, dept=0, onlyactive=False):
if id != 0:
Expand Down
15 changes: 15 additions & 0 deletions emonitor/modules/persons/templates/admin.persons.settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ <h2>{{ _('persons.header.settings') }}</h2>
</form>
</fieldset>

<fieldset>
<legend>{{ _('persons.additional.label') }}</legend>
<small>{{ _('persons.additional.info') }}</small>
<form method="post" name="additional" action="" style="padding-bottom:30px;">
<p>
<label>{{ _('persons.additional.field') }}:<br/>
<textarea name="additional" style="width:99%;height:150px;">{{ settings.additional | join('\n') }}</textarea>
</label>
</p>
<p>
<button type="submit" name="action" value="updateadditional" class="save"><i class="fa fa-check"></i> {{ _('persons.save') }}</button>
</p>
</form>
</fieldset>

{% endblock %}

{% block script_end %}
Expand Down
10 changes: 10 additions & 0 deletions emonitor/modules/persons/templates/admin.persons_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ <h2>{{ _('persons.header.edit') }}</h2>
<textarea name="remark" style="width:99%;height:50px;">{{ person.remark }}</textarea>
</label>
</p>
<p>
<fieldset>
<legend>{{ _('persons.additional.fields') }}</legend>
{% for f in settings.additional %}
<label>{{ f.split('=')[1] }}:<br/>
<input type="text" name="{{ f.split('=')[0] }}" value="{{ person.options[f.split('=')[0]] }}" style="width:100%;">
</label><br/>
{% endfor %}
</fieldset>
</p>
<p>
<label>
<input type="checkbox" name="active"{%- if person.active %} checked="checked"{%- endif %}/>
Expand Down
Binary file modified emonitor/modules/translations/de/LC_MESSAGES/modules.mo
Binary file not shown.
31 changes: 26 additions & 5 deletions emonitor/modules/translations/de/LC_MESSAGES/modules.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-04-23 23:30+0200\n"
"PO-Revision-Date: 2016-04-23 23:32+0200\n"
"POT-Creation-Date: 2016-05-04 20:12+0200\n"
"PO-Revision-Date: 2016-05-04 20:15+0200\n"
"Last-Translator: Arne Seifert <[email protected]>\n"
"Language-Team: de <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
Expand Down Expand Up @@ -3401,7 +3401,7 @@ msgid "persons.remark"
msgstr "Bemerkung"

#: emonitor/modules/persons/templates/admin.persons.html:44
#: emonitor/modules/persons/templates/admin.persons_edit.html:71
#: emonitor/modules/persons/templates/admin.persons_edit.html:81
msgid "persons.active"
msgstr "Aktiv"

Expand Down Expand Up @@ -3460,7 +3460,8 @@ msgstr "Dienstgrad"

#: emonitor/modules/persons/templates/admin.persons.settings.html:48
#: emonitor/modules/persons/templates/admin.persons.settings.html:64
#: emonitor/modules/persons/templates/admin.persons_edit.html:75
#: emonitor/modules/persons/templates/admin.persons.settings.html:79
#: emonitor/modules/persons/templates/admin.persons_edit.html:85
msgid "persons.save"
msgstr "Speichern"

Expand All @@ -3474,6 +3475,22 @@ msgstr ""
"Jedes Mitglied hat in der aktiven Mannschaft eine Dienststellung. Diese wird "
"für die erweiterte Personalerfassung bei Einsätzen herangezogen."

#: emonitor/modules/persons/templates/admin.persons.settings.html:70
msgid "persons.additional.label"
msgstr "Zusätzliche Felder"

#: emonitor/modules/persons/templates/admin.persons.settings.html:71
msgid "persons.additional.info"
msgstr ""
"Für Mitglieder können zusätzliche Felder definiert werden, die individuell "
"gefüllt werden können.<br/>Die Definition erfolgt zeilenweise in der Form:<br/"
">'<em>Parametername</em>=<em>Parameter Label</em>'"

#: emonitor/modules/persons/templates/admin.persons.settings.html:74
#, fuzzy
msgid "persons.additional.field"
msgstr "Mitglied hinzufügen"

#: emonitor/modules/persons/templates/admin.persons.upload.html:22
msgid "persons.upload.headtitle"
msgstr "Mitgliedersdatei hochladen"
Expand Down Expand Up @@ -3632,7 +3649,11 @@ msgstr "Identifikator"
msgid "persons.birthdate"
msgstr "Geburtsdatum"

#: emonitor/modules/persons/templates/admin.persons_edit.html:76
#: emonitor/modules/persons/templates/admin.persons_edit.html:70
msgid "persons.additional.fields"
msgstr "Zusatzfelder"

#: emonitor/modules/persons/templates/admin.persons_edit.html:86
msgid "persons.cancel"
msgstr "Abbrechen"

Expand Down
25 changes: 21 additions & 4 deletions emonitor/modules/translations/modules.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-04-23 23:30+0200\n"
"POT-Creation-Date: 2016-05-04 20:12+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -3209,7 +3209,7 @@ msgid "persons.remark"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons.html:44
#: emonitor/modules/persons/templates/admin.persons_edit.html:71
#: emonitor/modules/persons/templates/admin.persons_edit.html:81
msgid "persons.active"
msgstr ""

Expand Down Expand Up @@ -3263,7 +3263,8 @@ msgstr ""

#: emonitor/modules/persons/templates/admin.persons.settings.html:48
#: emonitor/modules/persons/templates/admin.persons.settings.html:64
#: emonitor/modules/persons/templates/admin.persons_edit.html:75
#: emonitor/modules/persons/templates/admin.persons.settings.html:79
#: emonitor/modules/persons/templates/admin.persons_edit.html:85
msgid "persons.save"
msgstr ""

Expand All @@ -3275,6 +3276,18 @@ msgstr ""
msgid "persons.position.info"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons.settings.html:70
msgid "persons.additional.label"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons.settings.html:71
msgid "persons.additional.info"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons.settings.html:74
msgid "persons.additional.field"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons.upload.html:22
msgid "persons.upload.headtitle"
msgstr ""
Expand Down Expand Up @@ -3429,7 +3442,11 @@ msgstr ""
msgid "persons.birthdate"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons_edit.html:76
#: emonitor/modules/persons/templates/admin.persons_edit.html:70
msgid "persons.additional.fields"
msgstr ""

#: emonitor/modules/persons/templates/admin.persons_edit.html:86
msgid "persons.cancel"
msgstr ""

Expand Down

0 comments on commit ccdd386

Please sign in to comment.