Skip to content

Make filter method take a string, eg for use with tags.contains:foo #117

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tasklib has a similar API to that of Django's ORM::
>>> tasks = tw.tasks.pending()
>>> tasks
['Tidy the house', 'Learn German']
>>> tasks.filter(tags__contain='chores')
>>> tasks.filter(tags__contains='chores')
['Tidy the house']
>>> type(tasks[0])
<class 'tasklib.task.Task'>
Expand Down
8 changes: 7 additions & 1 deletion tasklib/serializing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ def deserialize_annotations(self, data):
return [TaskAnnotation(self, d) for d in data] if data else []

def serialize_tags(self, tags):
return ','.join(tags) if tags else ''
if isinstance(tags, list):
tags = set(tags)
if isinstance(tags, set):
return ','.join(tags) if tags else ''
if isinstance(tags, str):
return tags
raise ValueError("serialize_tags only supports list, set or string")

def deserialize_tags(self, tags):
if isinstance(tags, str):
Expand Down