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 @@ ...@@ -5,3 +5,4 @@
(C) 13 + 29 = 42 (C) 13 + 29 = 42
x 2014-12-12 Completed but with date:2014-12-12 x 2014-12-12 Completed but with date:2014-12-12
hidden item h:1
...@@ -72,7 +72,7 @@ class ListCommandTest(CommandTest): ...@@ -72,7 +72,7 @@ class ListCommandTest(CommandTest):
command.execute() command.execute()
self.assertFalse(self.todolist.dirty) 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, "") self.assertEqual(self.errors, "")
def test_list06(self): def test_list06(self):
...@@ -147,7 +147,7 @@ class ListCommandTest(CommandTest): ...@@ -147,7 +147,7 @@ class ListCommandTest(CommandTest):
command.execute() command.execute()
self.assertFalse(self.todolist.dirty) 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, "") self.assertEqual(self.errors, "")
def test_list14(self): def test_list14(self):
...@@ -275,7 +275,7 @@ class ListCommandTest(CommandTest): ...@@ -275,7 +275,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-x", "-n", "foo"], self.todolist, self.out, self.error) command = ListCommand(["-x", "-n", "foo"], self.todolist, self.out, self.error)
command.execute() 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, "") self.assertEqual(self.errors, "")
def test_list36(self): def test_list36(self):
......
...@@ -20,7 +20,7 @@ import os ...@@ -20,7 +20,7 @@ import os
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand 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.PrettyPrinter import pretty_printer_factory
from topydo.lib.prettyprinters.Format import PrettyPrinterFormatFilter from topydo.lib.prettyprinters.Format import PrettyPrinterFormatFilter
from topydo.lib.TodoListBase import InvalidTodoException from topydo.lib.TodoListBase import InvalidTodoException
...@@ -93,8 +93,9 @@ class ListCommand(ExpressionCommand): ...@@ -93,8 +93,9 @@ class ListCommand(ExpressionCommand):
def _filters(self): def _filters(self):
""" """
Additional filters to select particular todo items given with the -i Additional filters to:
flag. - select particular todo items given with the -i flag,
- hide appropriately tagged items in the absense of the -x flag.
""" """
filters = super()._filters() filters = super()._filters()
...@@ -112,6 +113,9 @@ class ListCommand(ExpressionCommand): ...@@ -112,6 +113,9 @@ class ListCommand(ExpressionCommand):
todos = [get_todo(i) for i in self.ids] todos = [get_todo(i) for i in self.ids]
filters.append(InstanceFilter(todos)) filters.append(InstanceFilter(todos))
if not self.show_all:
filters.append(HiddenTagFilter(self.todolist))
return filters return filters
def _print(self): def _print(self):
...@@ -238,5 +242,6 @@ When an EXPRESSION is given, only the todos matching that EXPRESSION are shown. ...@@ -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. -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 -s : Sort the list according to a SORT EXPRESSION. Defaults to the expression
in the configuration. 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: ...@@ -77,6 +77,7 @@ class _Config:
'ls': { 'ls': {
'hide_tags': 'id,p,ical', 'hide_tags': 'id,p,ical',
'hidden_item_tags': 'h,hide',
'indent': '0', 'indent': '0',
'list_limit': '-1', 'list_limit': '-1',
'list_format': '|%I| %x %{(}p{)} %c %s %k %{due:}d %{t:}t', 'list_format': '|%I| %x %{(}p{)} %c %s %k %{due:}d %{t:}t',
...@@ -311,6 +312,13 @@ class _Config: ...@@ -311,6 +312,13 @@ class _Config:
return [] if hidden_tags == '' else [tag.strip() for tag in return [] if hidden_tags == '' else [tag.strip() for tag in
hidden_tags.split(',')] 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): def priority_color(self, p_priority):
""" """
Returns a dict with priorities as keys and color numbers as value. Returns a dict with priorities as keys and color numbers as value.
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
import re import re
from topydo.lib.Config import config
from topydo.lib.RelativeDate import relative_date_to_date from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Utils import date_string_to_date from topydo.lib.Utils import date_string_to_date
...@@ -91,8 +92,8 @@ class RelevanceFilter(Filter): ...@@ -91,8 +92,8 @@ class RelevanceFilter(Filter):
The item has not been completed AND The item has not been completed AND
The start date is blank, today or in the past, 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 '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 'C' with due date within 14 days.
""" """
def match(self, p_todo): def match(self, p_todo):
...@@ -154,6 +155,32 @@ class InstanceFilter(Filter): ...@@ -154,6 +155,32 @@ class InstanceFilter(Filter):
return False 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): class LimitFilter(Filter):
def __init__(self, p_limit): def __init__(self, p_limit):
super().__init__() 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