Merge pull request 'status-select-one' (#21) from status-select-one into master

This commit is contained in:
Stefan Haun 2020-03-26 14:03:03 +00:00
commit 602b155084

View file

@ -1,13 +1,26 @@
import npyscreen import npyscreen
class membership_data_model(): class membership_data_model():
status_values = {
'V': 'Vollzahler',
'E': 'Ermäßigt',
'F': 'Fördermitglied'
}
def __init__(self, membership_data_dict): def __init__(self, membership_data_dict):
self.membership_data_dict = membership_data_dict self.membership_data_dict = membership_data_dict
self.forms = {} self.forms = {}
def add_edit_fields(self, parent_form): def add_edit_fields(self, parent_form):
mem = self.membership_data_dict mem = self.membership_data_dict
self.forms['status'] = parent_form.add(npyscreen.TitleText, name="Status: ", value=mem['status']) status_value = 0
if 'status' in mem.keys() and mem['status'] in self.status_values.keys():
status_value = list(self.status_values.keys()).index(mem['status'])
self.forms['status'] = parent_form.add(npyscreen.TitleSelectOne, name="Status: ",
values=list(self.status_values.values()),
value=status_value,
max_height=3, scroll_exit=True)
self.forms['von'] = parent_form.add(npyscreen.TitleText, name="Von: ", value=mem['von']) self.forms['von'] = parent_form.add(npyscreen.TitleText, name="Von: ", value=mem['von'])
self.forms['bis'] = parent_form.add(npyscreen.TitleText, name="Bis: ", value=mem['bis']) self.forms['bis'] = parent_form.add(npyscreen.TitleText, name="Bis: ", value=mem['bis'])
self.forms['mitgliedsbeitrag'] = parent_form.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ", self.forms['mitgliedsbeitrag'] = parent_form.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ",
@ -21,6 +34,7 @@ class membership_data_model():
def get_form_values_dict(self): def get_form_values_dict(self):
membership_data_model = dict(zip(self.forms.keys(), map(lambda f: f.value, self.forms.values()))) membership_data_model = dict(zip(self.forms.keys(), map(lambda f: f.value, self.forms.values())))
membership_data_model['status'] = list(self.status_values.keys())[self.forms['status'].value[0]]
return membership_data_model return membership_data_model
def has_changed(self): def has_changed(self):