Skip to content

Commit

Permalink
bugfixing categories more - clarifying that set-category will add a c…
Browse files Browse the repository at this point in the history
…ategory, while set-categories will replace all categories
  • Loading branch information
tobixen committed Oct 1, 2023
1 parent f02c924 commit 697c004
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plann/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def delete(ctx, multi_delete, **kwargs):

@select.command()
@click.option('--pdb/--no-pdb', default=None, help="Interactive edit through pdb (experts only)")
@click.option('--add-category', default=None, help="Delete multiple things without confirmation prompt", multiple=True)
@click.option('--add-category', default=None, help="Add a category (equivalent with --set-category, while --set-categories will overwrite existing categories))", multiple=True)
@click.option('--postpone', help="Add something to the DTSTART and DTEND/DUE")
@click.option('--interactive-ical/--no-interactive-ical', help="Edit the ical interactively")
@click.option('--interactive-relations/--no-interactive-relations', help="Edit the relationships")
Expand Down
2 changes: 1 addition & 1 deletion plann/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _edit(ctx, add_category=None, cancel=None, interactive_ical=False, interacti
## TODO: consolidate with command_edit
if 'recurrence_mode' in kwargs:
complete_recurrence_mode = kwargs.pop('recurrence_mode')
_process_set_args(ctx, kwargs)
_process_set_args(ctx, kwargs, keep_category=True)
if interactive_ical:
_interactive_ical_edit(ctx.obj['objs'])
if interactive_relations:
Expand Down
2 changes: 1 addition & 1 deletion plann/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def command_edit(obj, command, interactive=True):
elif command.startswith('set '):
command = command[4:].split('=')
assert len(command) == 2
parsed = _process_set_arg(*command)
parsed = _process_set_arg(*command, keep_category=True)
for x in parsed:
_set_something(obj, x, parsed[x])
elif command == 'edit':
Expand Down
11 changes: 8 additions & 3 deletions plann/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def _add_category(obj, category):
cats = comp.pop('categories').cats
else:
cats = []
cats.append(category)
if hasattr(category, 'split'):
category = category.split(',')
cats.extend(category)
comp.add('categories', cats)

def _summary(obj):
Expand Down Expand Up @@ -295,7 +297,7 @@ def _relationship_text(obj, reltype_wanted=None):
ret.append(reltype + "\n" + "\n".join(objs) + "\n")
return "\n".join(ret)

def _process_set_arg(arg, value):
def _process_set_arg(arg, value, keep_category=False):
ret = {}
if arg in attr_time and arg != 'duration':
ret[arg] = parse_dt(value, for_storage=True)
Expand All @@ -307,7 +309,10 @@ def _process_set_arg(arg, value):
ret[arg] = rrule
elif arg in ('category', 'categories'):
if hasattr(value, 'split'):
ret['categories'] = value.split(',')
value = value.split(',')
if not keep_category:
arg = 'categories'
ret[arg] = value
else:
ret[arg] = value
return ret
Expand Down
13 changes: 11 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ def dag(obj, reltype, observed=None):
todo4 = _add_todo(ctx, summary=['make plann even better'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo4')
todo5 = _add_todo(ctx, summary=['use plann on a daily basis to find more bugs and missing features'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo5')

## TODO: testing of set_category / set_categories should be moved to a separate test in test_lib / test_command / test_cli
assert(set([str(x) for x in todo1.icalendar_component['CATEGORIES'].cats]) == {'plann', 'keyboard'})
assert(set([str(x) for x in todo2.icalendar_component['CATEGORIES'].cats]) == {'plann', 'keyboard'})
assert(set([str(x) for x in todo3.icalendar_component['CATEGORIES'].cats]) == {'plann'})

uid3 = str(todo3.icalendar_component['uid'])
uid4 = str(todo4.icalendar_component['uid'])
uid5 = str(todo5.icalendar_component['uid'])
Expand Down Expand Up @@ -357,10 +362,14 @@ def prompt(*largs, **kwargs):
_interactive_edit(todo1)
todo1.load()
assert(todo1.icalendar_component['DUE'].dt > datetime_(year=2023, month=9, day=19, hour=15))
with patch('click.prompt', new=gen_prompt('set category=foo')):
with patch('click.prompt', new=gen_prompt('set categories=foo')):
_interactive_edit(todo1)
todo1.load()
assert(set([str(x) for x in todo1.icalendar_component['CATEGORIES'].cats]) == {'foo'})
with patch('click.prompt', new=gen_prompt('set category=bar')):
_interactive_edit(todo1)
todo1.load()
assert([str(x) for x in todo1.icalendar_component['CATEGORIES'].cats] == ['foo'])
assert(set([str(x) for x in todo1.icalendar_component['CATEGORIES'].cats]) == {'foo', 'bar'})
## TODO: part, split, family
## TODO: cancel,

Expand Down

0 comments on commit 697c004

Please sign in to comment.