add id handling & creation to data_form #27

Manually merged
tux merged 1 commit from add-id into master 2020-08-23 21:47:07 +02:00
2 changed files with 12 additions and 0 deletions
Showing only changes of commit 4ae69d20af - Show all commits

View file

@ -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):

7
id.py Normal file
View file

@ -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:]