Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
2d1e9e4b
Commit
2d1e9e4b
authored
Oct 20, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce LimitFilter which truncates todolist at given number.
parent
0a6c7eda
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
17 deletions
+49
-17
lib/Config.py
lib/Config.py
+1
-0
lib/Filter.py
lib/Filter.py
+9
-3
lib/ListCommand.py
lib/ListCommand.py
+2
-0
test/FilterTest.py
test/FilterTest.py
+37
-14
No files found.
lib/Config.py
View file @
2d1e9e4b
...
...
@@ -21,6 +21,7 @@ This module contains some definitions to configure the application.
DEFAULT_ACTION
=
'ls'
COLORS
=
True
HIGHLIGHT_PROJECTS_CONTEXTS
=
True
LIST_LIMIT
=
25
FILENAME
=
'todo.txt'
ARCHIVE_FILENAME
=
'done.txt'
...
...
lib/Filter.py
View file @
2d1e9e4b
...
...
@@ -15,14 +15,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class
Filter
(
object
):
def
filter
(
self
,
p_todos
,
p_limit
=
None
):
def
filter
(
self
,
p_todos
):
"""
Filters a list of todos. Truncates the list after p_limit todo
items (or no maximum limit if omitted).
"""
result
=
[
t
for
t
in
p_todos
if
self
.
match
(
t
)]
return
result
[:
p_limit
]
return
[
t
for
t
in
p_todos
if
self
.
match
(
t
)]
def
match
(
self
,
p_todo
):
""" Default match value. """
...
...
@@ -111,3 +110,10 @@ class InstanceFilter(Filter):
return
True
except
ValueError
:
return
False
class
LimitFilter
(
Filter
):
def
__init__
(
self
,
p_limit
):
self
.
limit
=
max
(
0
,
p_limit
)
def
filter
(
self
,
p_todos
):
return
p_todos
[:
self
.
limit
]
lib/ListCommand.py
View file @
2d1e9e4b
...
...
@@ -57,6 +57,8 @@ class ListCommand(Command.Command):
if
len
(
args
)
>
0
:
filters
.
append
(
Filter
.
GrepFilter
(
args
[
0
]))
filters
.
append
(
Filter
.
LimitFilter
(
Config
.
LIST_LIMIT
))
self
.
out
(
self
.
todolist
.
view
(
sorter
,
filters
).
pretty_print
())
def
usage
(
self
):
...
...
test/FilterTest.py
View file @
2d1e9e4b
...
...
@@ -24,20 +24,6 @@ import Todo
import
TodoList
class
FilterTest
(
unittest
.
TestCase
):
def
test_filter1
(
self
):
todo
=
Todo
.
Todo
(
"(C) Relevant"
)
relevance
=
Filter
.
RelevanceFilter
()
result
=
relevance
.
filter
([
todo
],
0
)
self
.
assertEquals
(
result
,
[])
def
test_filter2
(
self
):
todo
=
Todo
.
Todo
(
"(C) Relevant"
)
relevance
=
Filter
.
RelevanceFilter
()
result
=
relevance
.
filter
([
todo
],
100
)
self
.
assertEquals
(
result
,
[
todo
])
def
test_filter3
(
self
):
todo
=
Todo
.
Todo
(
"(C) Relevant"
)
relevance
=
Filter
.
RelevanceFilter
()
...
...
@@ -126,3 +112,40 @@ class FilterTest(unittest.TestCase):
filtered_todos
=
instance_filter
.
filter
([])
self
.
assertEquals
([],
filtered_todos
)
def
test_filter12
(
self
):
""" Test limit filter. """
todos
=
load_file
(
'data/FilterTest1.txt'
)
limit_filter
=
Filter
.
LimitFilter
(
0
)
filtered_todos
=
limit_filter
.
filter
(
todos
)
self
.
assertEquals
([],
filtered_todos
)
def
test_filter13
(
self
):
""" Test limit filter. """
todos
=
load_file
(
'data/FilterTest1.txt'
)
limit_filter
=
Filter
.
LimitFilter
(
1
)
filtered_todos
=
limit_filter
.
filter
(
todos
)
self
.
assertEquals
(
len
(
filtered_todos
),
1
)
self
.
assertEquals
(
filtered_todos
[
0
].
source
(),
'(C) This is part of some +Project'
)
def
test_filter14
(
self
):
""" Test limit filter. """
todos
=
load_file
(
'data/FilterTest1.txt'
)
limit_filter
=
Filter
.
LimitFilter
(
-
1
)
filtered_todos
=
limit_filter
.
filter
(
todos
)
self
.
assertEquals
([],
filtered_todos
)
def
test_filter15
(
self
):
""" Test limit filter. """
todos
=
load_file
(
'data/FilterTest1.txt'
)
limit_filter
=
Filter
.
LimitFilter
(
100
)
filtered_todos
=
limit_filter
.
filter
(
todos
)
self
.
assertEquals
(
len
(
filtered_todos
),
4
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment