Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Adding "exact match" to search options #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions todotxtio.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def __repr__(self):
return self.__str__()


def search(todos, text=None, completed=None, completion_date=None, priority=None, creation_date=None, projects=None, contexts=None, tags=None):
def search(todos, text=None, completed=None, completion_date=None, priority=None, creation_date=None, projects=None, contexts=None, tags=None, exact=None):
"""Return a list of todos that matches the provided filters.

It takes the exact same parameters as the :class:`todotxtio.Todo` object constructor, and return a list of :class:`todotxtio.Todo` objects as well.
Expand All @@ -294,7 +294,7 @@ def search(todos, text=None, completed=None, completion_date=None, priority=None
results = []

for todo in todos:
text_match = completed_match = completion_date_match = priority_match = creation_date_match = projects_match = contexts_match = tags_match =True
text_match = completed_match = completion_date_match = priority_match = creation_date_match = projects_match = contexts_match = tags_match = exact_match = True

if text is not None:
text_match = text in todo.text
Expand All @@ -320,7 +320,10 @@ def search(todos, text=None, completed=None, completion_date=None, priority=None
if tags is not None:
tags_match = any(todo.tags[k] == v for k, v in tags.items() if k in todo.tags)

if text_match and completed_match and completion_date_match and priority_match and creation_date_match and projects_match and contexts_match and tags_match:
if exact is not None:
exact_match = todo.text == exact

if text_match and completed_match and completion_date_match and priority_match and creation_date_match and projects_match and contexts_match and tags_match and exact_match:
results.append(todo)

return results