fix: populate edit defaults with the existing data
This commit is contained in:
parent
e8c37e6bcb
commit
22a8630a83
2 changed files with 23 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
"ID","STATUS","TITLE","DETAILS","TAGS","DEADLINE","TOUCHED"
|
"ID","STATUS","TITLE","DETAILS","TAGS","DEADLINE","TOUCHED"
|
||||||
0,"TODO","Use click-option-group","To help sort options in categories in help.","","","2023-07-28T12:04:02.615501"
|
0,"TODO","Use click-option-group","To help sort options in categories in help.","UX","","2023-07-28T23:07:24.677746"
|
||||||
1,"TODO","Use click-aliases","To allow for aliases (TBC: user-defined in config file?)","UX","","2023-07-28T17:10:35.635275"
|
1,"TODO","Use click-aliases","To allow for aliases (TBC: user-defined in config file?)","UX","","2023-07-28T17:10:35.635275"
|
||||||
2,"TODO","edit existing","When calling edit, populate defaults with existing data.","","","2023-07-28T12:07:08.177802"
|
2,"DONE","edit existing","When calling edit, populate defaults with existing data.","","","2023-07-28T23:08:18.324797"
|
||||||
3,"TODO","sanity checks","Check data consistency in load_data and save_data.","","","2023-07-28T12:08:10.272349"
|
3,"TODO","sanity checks","Check data consistency in load_data and save_data.","","","2023-07-28T12:08:10.272349"
|
||||||
|
|
|
||||||
|
27
klyban.py
27
klyban.py
|
|
@ -101,6 +101,7 @@ def check_id(context, param, value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Global group holding global options.
|
# Global group holding global options.
|
||||||
@click.group(invoke_without_command=True)
|
@click.group(invoke_without_command=True)
|
||||||
# Core options.
|
# Core options.
|
||||||
|
|
@ -304,14 +305,28 @@ def add(context, title, status, details, tags, deadline):
|
||||||
context.invoke(show)
|
context.invoke(show)
|
||||||
|
|
||||||
|
|
||||||
|
def default_from_existing(key):
|
||||||
|
class OptionDefaultFromContext(click.Option):
|
||||||
|
def get_default(self, context):
|
||||||
|
tid = context.params['tid']
|
||||||
|
df = load_data(context)
|
||||||
|
assert(tid in df.index)
|
||||||
|
row = df.loc[tid]
|
||||||
|
value = row[context.obj[key]]
|
||||||
|
if str(value) != "nan": # FIXME WTF?
|
||||||
|
self.default = value
|
||||||
|
else:
|
||||||
|
self.default = ""
|
||||||
|
return super(OptionDefaultFromContext, self).get_default(context)
|
||||||
|
return OptionDefaultFromContext
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument('TID', required=True, type=int, is_eager=True, callback=check_id)
|
@click.argument('TID', required=True, type=int, is_eager=True, callback=check_id)
|
||||||
@click.option('-t', '--title' , type=str, prompt=True)
|
@click.option('-t', '--title' , type=str, prompt=True, cls = default_from_existing('title_key'))
|
||||||
@click.option('-s', '--status' , type=str, prompt=True)
|
@click.option('-s', '--status' , type=str, prompt=True, cls = default_from_existing('status_key'))
|
||||||
@click.option('-d', '--details' , type=str, prompt=True, default="")
|
@click.option('-d', '--details' , type=str, prompt=True, cls = default_from_existing('details_key'))
|
||||||
@click.option('-t', '--tags' , type=str, prompt=True, default="")
|
@click.option('-t', '--tags' , type=str, prompt=True, cls = default_from_existing('tags_key'))
|
||||||
@click.option('-a', '--deadline', type=str, prompt=True, default="")
|
@click.option('-a', '--deadline', type=str, prompt=True, cls = default_from_existing('deadline_key'))
|
||||||
# FIXME populate the defaults with the existing data.
|
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def edit(context, tid, title, status, details, tags, deadline):
|
def edit(context, tid, title, status, details, tags, deadline):
|
||||||
"""Add a new task."""
|
"""Add a new task."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue