Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and I do try to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

* `interactive set-task-attribs` (also run by `interactive manage-tasks`): a task marked `completed!` at one prompt was asked about again at the next one, and answering `completed!` there crashed on the already-completed task. Regression in v1.2.0.
* `list-categories` and timewarrior time tracking crashed on a task with more than one CATEGORIES line. https://github.com/pycalendar/plann/issues/71
* `{CATEGORIES}` in a `list --template` printed the internal `vCategory([...])` representation instead of a comma-separated list.

## v1.2.0 - 2026-09-16

Expand Down
2 changes: 1 addition & 1 deletion plann/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _sort_key_function(skey):
if '{' in skey:
template = Template(skey)
def fkey(obj):
return template.format(**obj.icalendar_component)
return template.format_component(obj.icalendar_component)
elif skey == 'get_duration()':
def fkey(obj):
return obj.get_duration()
Expand Down
2 changes: 1 addition & 1 deletion plann/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _mass_reprioritize(objs):
while obj.icalendar_component.get('PRIORITY', 0)>current_pri:
current_pri += 1
text += f"\n=== PRIORITY {current_pri}\n"
text += template.format(**obj.icalendar_component) + "\n"
text += template.format_component(obj.icalendar_component) + "\n"
edited = _editor(text)
current_pri = 0
for line in edited.split('\n'):
Expand Down
2 changes: 1 addition & 1 deletion plann/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def _list(objs, ics=False, template="{DTSTART:?{DUE:?(date missing)?}?%F %H:%M:%
if 'calendar_name' in template.template:
more_info['calendar_name'] = obj.parent.get_display_name()
more_info['calendar_url'] = obj.parent.url
output.append(" "*indent + template.format(**obj.icalendar_component, **more_info))
output.append(" "*indent + template.format_component(obj.icalendar_component, **more_info))
## Recursively add children in an indented way
output.extend(_list(below, template=template, top_down=top_down, bottom_up=bottom_up, indent=indent+2, echo=False, filter=filter, cache=cache))
if indent and top_down:
Expand Down
13 changes: 13 additions & 0 deletions plann/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def __init__(self, template):
def format(self, *pargs, **kwargs):
return super().format(self.template, *pargs, **kwargs)

def format_component(self, comp, **kwargs):
"""Format an icalendar component, with CATEGORIES as a comma-separated list"""
values = dict(comp)
if 'CATEGORIES' in comp:
values['CATEGORIES'] = ",".join(str(c) for c in comp.categories)
return self.format(**values, **kwargs)

def get_field(self, field_name, args, kwargs):
try:
return super().get_field(field_name, args, kwargs)
except Exception:
return (no_value, field_name)

def get_value(self, key, args, kwds):
try:
ret = string.Formatter.get_value(self, key, args, kwds)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_template.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import date

import icalendar

from plann.lib import tz
from plann.template import Template

Expand Down Expand Up @@ -55,6 +57,26 @@ def test_missing_replaced_with_even_more_advanced_default(self):
text = template.format()
assert text == "Date is maybe bar"

def test_categories_rendered_as_comma_separated_list(self):
todo = icalendar.Todo()
todo.add('categories', ['RL', 'claude'])
assert Template("{CATEGORIES}").format_component(todo) == "RL,claude"
assert Template("{CATEGORIES:>12}").format_component(todo) == " RL,claude"

## Several CATEGORIES lines in one component
todo.add('categories', ['keyboard'])
assert Template("{CATEGORIES}").format_component(todo) == "RL,claude,keyboard"

def test_missing_categories_gives_default(self):
todo = icalendar.Todo()
assert Template("{CATEGORIES:?none?}").format_component(todo) == "none"

def test_bad_field_lookup_gives_empty_string(self):
todo = icalendar.Todo()
todo.add('categories', ['RL'])
assert Template("[{CATEGORIES.cats}]").format_component(todo) == "[]"

def test_format_component_takes_extra_keys(self):
todo = icalendar.Todo()
todo.add('summary', 'foo')
assert Template("{SUMMARY} {calendar_name}").format_component(todo, calendar_name="bar") == "foo bar"
Loading