2020-03-14 15:03:37 +01:00
|
|
|
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(
|
2020-10-22 11:20:49 +02:00
|
|
|
npyscreen.TitleText, begin_entry_at=20, use_two_lines=False, name="Adresse - Straße: ", value=base_data['address_street'])
|
2020-03-14 15:03:37 +01:00
|
|
|
self.forms['address_locality'] = form.add(
|
2020-10-22 11:20:49 +02:00
|
|
|
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,
|
2020-03-14 15:03:37 +01:00
|
|
|
name="Adresse - PLZ: ", value=base_data['address_code'])
|
|
|
|
self.forms['address_country'] = form.add(
|
2020-10-22 11:20:49 +02:00
|
|
|
npyscreen.TitleText, begin_entry_at=20, use_two_lines=False, name="Adresse - Land: ", value=base_data['address_country'])
|
2020-03-14 15:03:37 +01:00
|
|
|
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())))
|
2020-03-14 15:12:41 +01:00
|
|
|
base_data['address_label'] = \
|
|
|
|
f"{base_data['fullname']}\n\
|
|
|
|
{base_data['address_street']}\n\
|
|
|
|
{base_data['address_code']} {base_data['address_locality']}"
|
2020-03-14 15:12:11 +01:00
|
|
|
base_data['address_region'] = ''
|
2020-03-14 15:03:37 +01:00
|
|
|
return base_data
|
|
|
|
|
|
|
|
def has_changed(self):
|
|
|
|
return self.base_data_dict != self.get_form_values_dict()
|