-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add support for categories. To fix #10 #323
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in #10:
Regarding the commas issue, it looks like using t.set_inline('category', ['foo','bar']) sets them properly (and also escapes commas INSIDE categories properly).
This probably needs some changes in TodoWritter.set_field (overriding the behavior for CATEGORIES
).
I also think we might be able to use the multiple options feature here, so category names can actually contain commas (which would actually be escaped). This would slightly change usage to:
todo new --category foo --category bar Some description
I think this is slightly tidier than forcing people to comma-separate, what do you think about this?
Looking pretty good so far though, thanks!
TodoWriter.set_field calls add on the vtodo. This is icalendar.Component.add, with the relevant part there: It seems that the categories list is not recognized as such (matches the remove of Possible solutions:
|
I've just had a look into the proposed implementation and I vote for removing the We can take the easy route and store the categories comma-separated in a database text field. This would mostly mean:
Proper database design would suggest that there is a table with tuples (category, UID), where proper clean-up, aka remove all UID entries from this mapping when a UID is removed from the cache, is necessary. Unless we go with the less complex, but also less efficient approach:
|
ok, let's just lay out the tasks then. |
0ff3d90
to
95ff7e6
Compare
unfortunately the model ties the name of the command line options and the name of the field in the ics file. So the option will be called --categories. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good so far, thanks for the big effort (this is actually a lot less simple than I'd anticipated!).
I've mostly minor comments, and nothing critical. Thanks!
todoman/formatters.py
Outdated
if categories is None or categories == '': | ||
return None | ||
else: | ||
return categories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be return c for c in caterories.split(',')
, so that this returns a list of categories.
todoman/cli.py
Outdated
@@ -355,6 +370,9 @@ def new(ctx, summary, list, todo_properties, read_description, interactive): | |||
|
|||
for key, value in todo_properties.items(): | |||
if value: | |||
logger.debug("property: " + key + " value: " + ','.join(value) + " (" + str(type(value)) + ")" ) | |||
if key == "categories": | |||
value = [v for v in value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should actually be done in parse_category
(see my other comment below).
todoman/interactive.py
Outdated
@@ -159,6 +164,7 @@ def _save_inner(self): | |||
self.todo.summary = self.summary | |||
self.todo.description = self.description | |||
self.todo.location = self.location | |||
self.todo.categories = self.categories.split(',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we might also want to strip any whitespace in each category, so that Offline, Work
ends up as Office
and Work
, rather than Office
and Work
. (note the extra space in the last one).
Maybe:
self.todo.categories = [c.strip() for c in self.categories.split(',')]
self.vtodo.add(name, value) | ||
if name == 'categories': | ||
v = icalendar.prop.vInline(','.join(value)) | ||
self.vtodo.add(name, v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using set_inline
here actually sets the category
property escaping commas as expected.
That means you also don't have to split
when reading back from the cache.
Regarding this comment:
I believe it's possible to make the parameter name and flag name different, see here. I know this documentation change is relatively recent, but I believe click>=6 has the same behaviour (as seen in 9b111c5) |
…nstead of category
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looking pretty good. Let me know if you need any help with anything of have any doubts and I can take a closer look.
Thanks!
self.vtodo.add(name, value) | ||
if name == 'categories': | ||
# v = icalendar.prop.vInline(','.join(value)) | ||
v = self.vtodo.set_inline(name, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this needs to be if value is not None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_inline in the icalender library is defined here:
https://github.com/collective/icalendar/blob/master/src/icalendar/cal.py#L256
|
Shouldn't todoman specify the icalendar version in the requirements? |
The latest version specifies a minimum version, due to this API change being backwards incompatible. |
This adds categories to todoman.