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
8d1f2e16
Commit
8d1f2e16
authored
Jun 15, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function to add a tag to a todo.
parent
4b5e72b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
TodoBase.py
TodoBase.py
+9
-2
test/TodoBaseTest.py
test/TodoBaseTest.py
+7
-1
No files found.
TodoBase.py
View file @
8d1f2e16
...
@@ -55,13 +55,20 @@ class TodoBase(object):
...
@@ -55,13 +55,20 @@ class TodoBase(object):
if
p_value
==
""
or
t
==
p_value
]
if
p_value
==
""
or
t
==
p_value
]
return
len
(
result
)
>
0
return
len
(
result
)
>
0
def
set_tag
(
self
,
p_key
,
p_value
=
""
):
def
add_tag
(
self
,
p_key
,
p_value
):
""" Adds a tag to the todo. """
self
.
set_tag
(
p_key
,
p_value
,
True
)
def
set_tag
(
self
,
p_key
,
p_value
=
""
,
p_force_add
=
False
):
"""
"""
Sets a occurrence of the tag identified by p_key. Sets an arbitrary
Sets a occurrence of the tag identified by p_key. Sets an arbitrary
instance of the tag when the todo contains multiple tags with this key.
instance of the tag when the todo contains multiple tags with this key.
When p_key does not exist, the tag is added.
When p_key does not exist, the tag is added.
When p_value is not set, the tag will be removed.
When p_value is not set, the tag will be removed.
When p_force_add is true, a tag will always be added to the todo, in
case there is already a tag with the given key.
"""
"""
if
p_value
==
""
:
if
p_value
==
""
:
...
@@ -69,7 +76,7 @@ class TodoBase(object):
...
@@ -69,7 +76,7 @@ class TodoBase(object):
return
return
value
=
self
.
tag_value
(
p_key
)
value
=
self
.
tag_value
(
p_key
)
if
value
:
if
not
p_force_add
and
value
:
# remove old value from the tags
# remove old value from the tags
self
.
fields
[
'tags'
]
=
[
t
for
t
in
self
.
fields
[
'tags'
]
\
self
.
fields
[
'tags'
]
=
[
t
for
t
in
self
.
fields
[
'tags'
]
\
if
t
[
0
]
!=
p_key
and
t
[
1
]
!=
value
]
if
t
[
0
]
!=
p_key
and
t
[
1
]
!=
value
]
...
...
test/TodoBaseTest.py
View file @
8d1f2e16
...
@@ -17,7 +17,7 @@ class TodoBaseTester(unittest.TestCase):
...
@@ -17,7 +17,7 @@ class TodoBaseTester(unittest.TestCase):
self
.
assertTrue
(
todo
.
has_tag
(
'blah'
))
self
.
assertTrue
(
todo
.
has_tag
(
'blah'
))
self
.
assertTrue
(
todo
.
has_tag
(
'blah'
,
'zah:haz'
))
self
.
assertTrue
(
todo
.
has_tag
(
'blah'
,
'zah:haz'
))
def
test_add_tag
(
self
):
def
test_add_tag
1
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo"
)
todo
=
TodoBase
.
TodoBase
(
"(C) Foo"
)
todo
.
set_tag
(
'foo'
,
'bar'
)
todo
.
set_tag
(
'foo'
,
'bar'
)
...
@@ -27,6 +27,12 @@ class TodoBaseTester(unittest.TestCase):
...
@@ -27,6 +27,12 @@ class TodoBaseTester(unittest.TestCase):
self
.
assertFalse
(
todo
.
has_tag
(
'bar'
))
self
.
assertFalse
(
todo
.
has_tag
(
'bar'
))
self
.
assertTrue
(
re
.
search
(
r'\bfoo:bar\b'
,
todo
.
src
))
self
.
assertTrue
(
re
.
search
(
r'\bfoo:bar\b'
,
todo
.
src
))
def
test_add_tag2
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo id:1"
)
todo
.
add_tag
(
'id'
,
'2'
)
self
.
assertEquals
(
todo
.
source
(),
'(C) Foo id:1 id:2'
)
def
test_set_tag
(
self
):
def
test_set_tag
(
self
):
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar"
)
todo
=
TodoBase
.
TodoBase
(
"(C) Foo foo:bar"
)
todo
.
set_tag
(
'foo'
,
'baz'
)
todo
.
set_tag
(
'foo'
,
'baz'
)
...
...
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