stammdaten-formular/base_data_model.py

40 lines
No EOL
2.3 KiB
Python

import npyscreen
class base_data_model():
def __init__(self, base_data_dict):
self.base_data_dict = base_data_dict
self.forms = {}
def add_edit_fields(self, form):
base_data = self.base_data_dict
self.forms['fullname'] = form.add(npyscreen.TitleText, name="Name: ", value=base_data['fullname'])
self.forms['nickname'] = form.add(npyscreen.TitleText, name="Nickname: ",
value=base_data['nickname'])
self.forms['address_street'] = form.add(
npyscreen.TitleText, begin_entry_at=20, use_two_lines=False, name="Adresse - Straße: ", value=base_data['address_street'])
self.forms['address_locality'] = form.add(
npyscreen.TitleText, begin_entry_at=20, use_two_lines=False, name="Adresse - Stadt: ", value=base_data['address_locality'])
self.forms['address_code'] = form.add(npyscreen.TitleText, begin_entry_at=20, use_two_lines=False,
name="Adresse - PLZ: ", value=base_data['address_code'])
self.forms['address_country'] = form.add(
npyscreen.TitleText, begin_entry_at=20, use_two_lines=False, name="Adresse - Land: ", value=base_data['address_country'])
self.forms['birth_date'] = form.add(npyscreen.TitleText,
name="Geburtstag: ", value=base_data['birth_date'])
self.forms['birth_location'] = form.add(
npyscreen.TitleText, name="Geburtsort: ", value=base_data['birth_location'])
self.forms['email'] = form.add(npyscreen.TitleText,
name="email: ", value=base_data['email'])
self.forms['pgp-key'] = form.add(npyscreen.TitleText, name="URI PGP Key: ", value=base_data['pgp-key'])
self.forms['ssh-key'] = form.add(npyscreen.TitleText, name="URI SSH Key: ", value=base_data['ssh-key'])
def get_form_values_dict(self):
base_data = dict(zip(self.forms.keys(), map(lambda f: f.value, self.forms.values())))
base_data['address_label'] = \
f"{base_data['fullname']}\n\
{base_data['address_street']}\n\
{base_data['address_code']} {base_data['address_locality']}"
base_data['address_region'] = ''
return base_data
def has_changed(self):
return self.base_data_dict != self.get_form_values_dict()