From 96b06d33e0b595a29b10c7e73e8fd5581b2561e9 Mon Sep 17 00:00:00 2001 From: David Kilias Date: Sat, 14 Mar 2020 10:43:03 +0100 Subject: [PATCH 1/3] compose address label before saving data --- edit_data_form.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/edit_data_form.py b/edit_data_form.py index 686cfd9..76d3657 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -72,10 +72,11 @@ def main(*_args): app = FormApp(member_struct) app.run() new_data = {} - new_data['stammdaten'] = dict(zip(app.sd2.keys(), map(lambda f: f.value, app.sd2.values()))) - new_data['finanzdaten'] = dict(zip(app.fin2.keys(), map(lambda f: f.value, app.fin2.values()))) - new_data['mitgliederdaten'] = dict(zip(app.mem2.keys(), map(lambda f: f.value, app.mem2.values()))) - outfile_name = '{}_{}.json'.format(date.today().isoformat(), '_'.join(new_data['stammdaten']['fullname'].split())) + new_data['stammdaten']['address_label'] = \ + f"{new_data['stammdaten']['fullname']}\n \ + {new_data['stammdaten']['address_street']}\n \ + {new_data['stammdaten']['address_code']} {new_data['stammdaten']["address_locality"]}" + with open(outfile_name, 'w') as outfile: json.dump(new_data, outfile, sort_keys=True, indent=4) From cf6157a5485368a807aae4885f1033497c2a20f2 Mon Sep 17 00:00:00 2001 From: David Kilias Date: Sat, 14 Mar 2020 10:43:38 +0100 Subject: [PATCH 2/3] cleanup variable names --- edit_data_form.py | 95 +++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/edit_data_form.py b/edit_data_form.py index 76d3657..5c847c3 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -14,52 +14,64 @@ class FormApp(npyscreen.NPSAppManaged): def main(self): f = npyscreen.Form(name='Edit Member data') - + sd = self.member['stammdaten'] - self.sd2 = {} - self.sd2['fullname'] = f.add(npyscreen.TitleText, name="Name: ", value=sd['fullname']) - self.sd2['nickname'] = f.add(npyscreen.TitleText, name="Nickname: ", - value=sd['nickname']) - self.sd2['address_street'] = f.add( + base_data_widgets = {} + base_data_widgets['fullname'] = f.add( + npyscreen.TitleText, name="Name: ", value=sd['fullname']) + base_data_widgets['nickname'] = f.add(npyscreen.TitleText, name="Nickname: ", + value=sd['nickname']) + base_data_widgets['address_street'] = f.add( npyscreen.TitleText, name="Adresse - Straße: ", value=sd['address_street']) - self.sd2['address_locality'] = f.add( + base_data_widgets['address_locality'] = f.add( npyscreen.TitleText, name="Adresse - Stadt: ", value=sd['address_locality']) - self.sd2['address_code'] = f.add(npyscreen.TitleText, - name="Adresse - PLZ: ", value=sd['address_code']) - self.sd2['address_country'] = f.add( + base_data_widgets['address_code'] = f.add(npyscreen.TitleText, + name="Adresse - PLZ: ", value=sd['address_code']) + base_data_widgets['address_country'] = f.add( npyscreen.TitleText, name="Adresse - Land: ", value=sd['address_country']) - self.sd2['birth_date'] = f.add(npyscreen.TitleText, - name="Geburtstag: ", value=sd['birth_date']) - self.sd2['birth_location'] = f.add( + base_data_widgets['birth_date'] = f.add(npyscreen.TitleText, + name="Geburtstag: ", value=sd['birth_date']) + base_data_widgets['birth_location'] = f.add( npyscreen.TitleText, name="Geburtsort: ", value=sd['birth_location']) - self.sd2['email'] = f.add(npyscreen.TitleText, - name="email: ", value=sd['email']) - self.sd2['pgp-key'] = f.add(npyscreen.TitleText, name="URI PGP Key: ", value=sd['pgp-key']) - self.sd2['ssh-key'] = f.add(npyscreen.TitleText, name="URI SSH Key: ", value=sd['ssh-key']) + base_data_widgets['email'] = f.add(npyscreen.TitleText, + name="email: ", value=sd['email']) + base_data_widgets['pgp-key'] = f.add(npyscreen.TitleText, + name="URI PGP Key: ", value=sd['pgp-key']) + base_data_widgets['ssh-key'] = f.add(npyscreen.TitleText, + name="URI SSH Key: ", value=sd['ssh-key']) + self.base_data_widgets = base_data_widgets fin = self.member['finanzdaten'] - self.fin2 = {} - self.fin2['iban'] = f.add(npyscreen.TitleText, name="IBAN: ", value=fin['iban']) - self.fin2['bic'] = f.add(npyscreen.TitleText, name="BIC: ", value=fin['bic']) - self.fin2['holder'] = f.add(npyscreen.TitleText, name="Kontoinhaber: ", value=fin['holder']) - self.fin2['issuance'] = f.add(npyscreen.TitleText, name="Tag der Erteilung Lastschriftmandat: ", - value=fin['issuance']) - self.fin2['reference'] = f.add(npyscreen.TitleText, name="Mandatsreferenznummer: ", - value=fin['reference']) - self.fin2['scan-sepa-mandate'] = f.add(npyscreen.TitleText, name="URI Scan SEPA-Mandat: ", - value=fin['scan-sepa-mandate']) + finance_widgets = {} + finance_widgets['iban'] = f.add( + npyscreen.TitleText, name="IBAN: ", value=fin['iban']) + finance_widgets['bic'] = f.add( + npyscreen.TitleText, name="BIC: ", value=fin['bic']) + finance_widgets['holder'] = f.add( + npyscreen.TitleText, name="Kontoinhaber: ", value=fin['holder']) + finance_widgets['issuance'] = f.add(npyscreen.TitleText, name="Tag der Erteilung Lastschriftmandat: ", + value=fin['issuance']) + finance_widgets['reference'] = f.add(npyscreen.TitleText, name="Mandatsreferenznummer: ", + value=fin['reference']) + finance_widgets['scan-sepa-mandate'] = f.add(npyscreen.TitleText, name="URI Scan SEPA-Mandat: ", + value=fin['scan-sepa-mandate']) + sefl.finance_widgets = finance_widgets mem = self.member['mitgliederdaten'] - self.mem2 = {} - self.mem2['status'] = f.add(npyscreen.TitleText, name="Status: ", value=mem['status']) - self.mem2['von'] = f.add(npyscreen.TitleText, name="Von: ", value=mem['von']) - self.mem2['bis'] = f.add(npyscreen.TitleText, name="Bis: ", value=mem['bis']) - self.mem2['mitgliedsbeitrag'] = f.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ", - value=mem['mitgliedsbeitrag']) - self.mem2['schliessberechtigung'] = f.add(npyscreen.TitleText, name="Schliessberechtigung: ", - value=mem['schliessberechtigung']) - self.mem2['scan-antrag'] = f.add(npyscreen.TitleText, name="URI Scan Antrag: ", - value=mem['scan-antrag']) + member_widgets = {} + member_widgets['status'] = f.add( + npyscreen.TitleText, name="Status: ", value=mem['status']) + member_widgets['von'] = f.add( + npyscreen.TitleText, name="Von: ", value=mem['von']) + member_widgets['bis'] = f.add( + npyscreen.TitleText, name="Bis: ", value=mem['bis']) + member_widgets['mitgliedsbeitrag'] = f.add(npyscreen.TitleText, name="Mitgliedsbeitrag: ", + value=mem['mitgliedsbeitrag']) + member_widgets['schliessberechtigung'] = f.add(npyscreen.TitleText, name="Schliessberechtigung: ", + value=mem['schliessberechtigung']) + member_widgets['scan-antrag'] = f.add(npyscreen.TitleText, name="URI Scan Antrag: ", + value=mem['scan-antrag']) + self.member_widgets = member_widgets f.edit() @@ -71,12 +83,21 @@ def main(*_args): member_struct = json.load(open('example.json', 'r')) app = FormApp(member_struct) app.run() + new_data = {} + new_data['stammdaten'] = dict( + zip(app.sd2.keys(), map(lambda f: f.value, app.base_data_widgets.values()))) + new_data['finanzdaten'] = dict( + zip(app.fin2.keys(), map(lambda f: f.value, app.finance_widgets.values()))) + new_data['mitgliederdaten'] = dict( + zip(app.mem2.keys(), map(lambda f: f.value, app.member_widgets.values()))) new_data['stammdaten']['address_label'] = \ f"{new_data['stammdaten']['fullname']}\n \ {new_data['stammdaten']['address_street']}\n \ {new_data['stammdaten']['address_code']} {new_data['stammdaten']["address_locality"]}" + outfile_name = '{}_{}.json'.format(date.today().isoformat( + ), '_'.join(new_data['stammdaten']['fullname'].split())) with open(outfile_name, 'w') as outfile: json.dump(new_data, outfile, sort_keys=True, indent=4) From bce23cb45c02c562bccb20d23ace5922cce84697 Mon Sep 17 00:00:00 2001 From: David Kilias Date: Sat, 14 Mar 2020 10:48:47 +0100 Subject: [PATCH 3/3] fix formatting issues with multiline string --- edit_data_form.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/edit_data_form.py b/edit_data_form.py index 5c847c3..d2aefe2 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -55,7 +55,7 @@ class FormApp(npyscreen.NPSAppManaged): value=fin['reference']) finance_widgets['scan-sepa-mandate'] = f.add(npyscreen.TitleText, name="URI Scan SEPA-Mandat: ", value=fin['scan-sepa-mandate']) - sefl.finance_widgets = finance_widgets + self.finance_widgets = finance_widgets mem = self.member['mitgliederdaten'] member_widgets = {} @@ -86,15 +86,15 @@ def main(*_args): new_data = {} new_data['stammdaten'] = dict( - zip(app.sd2.keys(), map(lambda f: f.value, app.base_data_widgets.values()))) + zip(app.base_data_widgets.keys(), map(lambda f: f.value, app.base_data_widgets.values()))) new_data['finanzdaten'] = dict( - zip(app.fin2.keys(), map(lambda f: f.value, app.finance_widgets.values()))) + zip(app.finance_widgets.keys(), map(lambda f: f.value, app.finance_widgets.values()))) new_data['mitgliederdaten'] = dict( - zip(app.mem2.keys(), map(lambda f: f.value, app.member_widgets.values()))) + zip(app.member_widgets.keys(), map(lambda f: f.value, app.member_widgets.values()))) new_data['stammdaten']['address_label'] = \ - f"{new_data['stammdaten']['fullname']}\n \ - {new_data['stammdaten']['address_street']}\n \ - {new_data['stammdaten']['address_code']} {new_data['stammdaten']["address_locality"]}" + f"{new_data['stammdaten']['fullname']}\n\ +{new_data['stammdaten']['address_street']}\n\ +{new_data['stammdaten']['address_code']} {new_data['stammdaten']['address_locality']}" outfile_name = '{}_{}.json'.format(date.today().isoformat( ), '_'.join(new_data['stammdaten']['fullname'].split()))