From 4ae69d20afb815d2c15c3b5592cdaeee472d6aa8 Mon Sep 17 00:00:00 2001 From: David Kilias Date: Sun, 23 Aug 2020 18:47:35 +0200 Subject: [PATCH] add id handling & creation to data_form --- edit_data_form.py | 5 +++++ id.py | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 id.py diff --git a/edit_data_form.py b/edit_data_form.py index 0e43d3e..68ab61a 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -10,6 +10,7 @@ import pathlib from base_data_model import base_data_model from financial_data_model import financial_data_model from membership_data_model import membership_data_model +from id import new_id class FormApp(npyscreen.NPSAppManaged): @@ -38,6 +39,10 @@ class FormApp(npyscreen.NPSAppManaged): data_dict['finanzdaten'] = self.financial_data.get_form_values_dict() data_dict['mitgliederdaten'] = self.membership_data.get_form_values_dict() data_dict['timestamp'] = datetime.datetime.now().replace(microsecond=0).isoformat() + try: + data_dict['id'] = self.member['id'] + except KeyError: + data_dict['id'] = new_id() return data_dict def data_has_changed(self): diff --git a/id.py b/id.py new file mode 100644 index 0000000..1d4a122 --- /dev/null +++ b/id.py @@ -0,0 +1,7 @@ +import datetime +import hashlib + +def new_id(): + h = hashlib.md5() + h.update(datetime.datetime.now().isoformat().encode()) + return h.hexdigest()[-5:] \ No newline at end of file