From 7cbcefa4deb5f2d8f89aa577cb428987242ef657 Mon Sep 17 00:00:00 2001 From: David Kilias Date: Fri, 20 Mar 2020 13:15:20 +0100 Subject: [PATCH] ask for a destination if instantiated without a filename --- edit_data_form.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/edit_data_form.py b/edit_data_form.py index 276ccc1..05d7b84 100755 --- a/edit_data_form.py +++ b/edit_data_form.py @@ -15,7 +15,7 @@ from membership_data_model import membership_data_model class FormApp(npyscreen.NPSAppManaged): def __init__(self, filename): super().__init__() - + self.is_new_member = self.is_default_file(filename) self.dir_path = pathlib.Path(filename).absolute().parent self.member = json.load(open(filename, 'r')) @@ -47,9 +47,16 @@ class FormApp(npyscreen.NPSAppManaged): name = self.base_data.get_form_values_dict()['fullname'] date = datetime.datetime.now().replace(microsecond=0).isoformat() fn = '{}_{}.json'.format('_'.join(name.lower().split()), date.replace(':','')) + if self.is_new_member: + print('Enter destination directory for new Member data:') + self.dir_path = input() + file_path = pathlib.Path(self.dir_path, fn) return file_path + def is_default_file(self, filename): + return pathlib.Path(filename).name == 'example.json' + def main(*_args): if len(argv) > 1: