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, name="Adresse - Straße: ", value=base_data['address_street']) self.forms['address_locality'] = form.add( npyscreen.TitleText, name="Adresse - Stadt: ", value=base_data['address_locality']) self.forms['address_code'] = form.add(npyscreen.TitleText, name="Adresse - PLZ: ", value=base_data['address_code']) self.forms['address_country'] = form.add( npyscreen.TitleText, 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()))) return base_data def has_changed(self): return self.base_data_dict != self.get_form_values_dict()