Commit 7c0b829e authored by MinchinWeb's avatar MinchinWeb

Add HiddenTagFilter

Use the `h:1` tag to hide items from being listed
parent 86eb39da
......@@ -5,3 +5,4 @@
(C) 13 + 29 = 42
x 2014-12-12 Completed but with date:2014-12-12
hidden item h:1
......@@ -72,7 +72,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list06(self):
......@@ -147,7 +147,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list14(self):
......@@ -275,7 +275,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-x", "-n", "foo"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list36(self):
......
......@@ -20,7 +20,7 @@ import os
from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.Filter import InstanceFilter
from topydo.lib.Filter import HiddenTagFilter, InstanceFilter
from topydo.lib.PrettyPrinter import pretty_printer_factory
from topydo.lib.prettyprinters.Format import PrettyPrinterFormatFilter
from topydo.lib.TodoListBase import InvalidTodoException
......@@ -93,8 +93,9 @@ class ListCommand(ExpressionCommand):
def _filters(self):
"""
Additional filters to select particular todo items given with the -i
flag.
Additional filters to:
- select particular todo items given with the -i flag,
- hide appropriately tagged items in the absense of the -x flag.
"""
filters = super()._filters()
......@@ -112,6 +113,9 @@ class ListCommand(ExpressionCommand):
todos = [get_todo(i) for i in self.ids]
filters.append(InstanceFilter(todos))
if not self.show_all:
filters.append(HiddenTagFilter(self.todolist))
return filters
def _print(self):
......@@ -238,5 +242,6 @@ When an EXPRESSION is given, only the todos matching that EXPRESSION are shown.
-N : Limit number of items displayed such that they fit on the terminal.
-s : Sort the list according to a SORT EXPRESSION. Defaults to the expression
in the configuration.
-x : Show all todos (i.e. do not filter on dependencies or relevance).\
-x : Show all todos (i.e. do not filter on dependencies, relevance, or hidden
status).\
"""
......@@ -77,6 +77,7 @@ class _Config:
'ls': {
'hide_tags': 'id,p,ical',
'hidden_item_tags': 'h,hide',
'indent': '0',
'list_limit': '-1',
'list_format': '|%I| %x %{(}p{)} %c %s %k %{due:}d %{t:}t',
......@@ -311,6 +312,13 @@ class _Config:
return [] if hidden_tags == '' else [tag.strip() for tag in
hidden_tags.split(',')]
def hidden_item_tags(self):
""" Returns a list of tags which hide an item from the 'ls' output. """
hidden_item_tags = self.cp.get('ls', 'hidden_item_tags')
# pylint: disable=no-member
return [] if hidden_item_tags == '' else [tag.strip() for tag in
hidden_item_tags.split(',')]
def priority_color(self, p_priority):
"""
Returns a dict with priorities as keys and color numbers as value.
......
......@@ -16,6 +16,7 @@
import re
from topydo.lib.Config import config
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Utils import date_string_to_date
......@@ -91,8 +92,8 @@ class RelevanceFilter(Filter):
The item has not been completed AND
The start date is blank, today or in the past, AND
The priority is 'A' or the priority is B with due date within 30 days or
the priority is C with due date within 14 days.
The priority is 'A', or the priority is 'B' with due date within 30 days, or
the priority is 'C' with due date within 14 days.
"""
def match(self, p_todo):
......@@ -154,6 +155,32 @@ class InstanceFilter(Filter):
return False
class HiddenTagFilter(Filter):
def __init__(self, p_todos):
"""
Constructor.
A filter which selects a number of Todo instances from a TodoList
instance.
This is handy for constructing a view given a plain list of Todo items.
"""
super().__init__()
self.todos = p_todos
def match(self, p_todo):
"""
Returns Ture when p_todo doesn't have a tag to mark it as hidden.
"""
for my_tag in config().hidden_item_tags():
my_values = p_todo.tag_values(my_tag)
for my_value in my_values:
if not my_value in (0, '0', False, 'False'):
return False
return True
class LimitFilter(Filter):
def __init__(self, p_limit):
super().__init__()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment