Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2311ed28
authored
Sep 26, 2009
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TaggableForm, and tests
parent
46a4e80a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
2 deletions
+40
-2
taggit/forms.py
+19
-0
taggit/tests/__init__.py
+1
-1
taggit/tests/forms.py
+8
-0
taggit/tests/tests.py
+11
-0
taggit/utils.py
+1
-1
No files found.
taggit/forms.py
0 → 100644
View file @
2311ed28
from
django
import
forms
from
taggit.utils
import
parse_tags
class
TaggableForm
(
forms
.
ModelForm
):
tags
=
forms
.
CharField
(
help_text
=
"A comma seperated list of tags."
)
def
save
(
self
,
commit
=
True
):
obj
=
super
(
TaggableForm
,
self
)
.
save
(
commit
=
False
)
def
save_tags
():
# TODO: Remove the assumption that the manager is named 'tags'
obj
.
tags
.
set
(
parse_tags
(
self
.
cleaned_data
[
'tags'
]))
if
commit
:
obj
.
save
()
save_tags
()
else
:
obj
.
save_tags
=
save_tags
return
obj
taggit/tests/__init__.py
View file @
2311ed28
from
taggit.tests.tests
import
(
AddTagTestCase
)
taggit/tests/forms.py
0 → 100644
View file @
2311ed28
from
taggit.forms
import
TaggableForm
from
taggit.tests.models
import
Food
class
FoodForm
(
TaggableForm
):
class
Meta
:
model
=
Food
taggit/tests/tests.py
View file @
2311ed28
from
django.test
import
TestCase
from
taggit.models
import
Tag
from
taggit.tests.forms
import
FoodForm
from
taggit.tests.models
import
Food
class
BaseTaggingTest
(
TestCase
):
...
...
@@ -32,3 +33,13 @@ class AddTagTestCase(BaseTaggingTest):
apple
.
tags
.
remove
(
'green'
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'red'
])
self
.
assert_tags_equal
(
Food
.
tags
.
all
(),
[
'green'
,
'red'
])
class
TaggableFormTestCase
(
BaseTaggingTest
):
def
test_form
(
self
):
self
.
assertEqual
(
FoodForm
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
f
=
FoodForm
({
'name'
:
'apple'
,
'tags'
:
'green, red, yummy'
})
f
.
save
()
apple
=
Food
.
objects
.
get
(
name
=
'apple'
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'green'
,
'red'
,
'yummy'
])
taggit/utils.py
View file @
2311ed28
from
functools
import
wraps
def
split
_tags
(
tags
):
def
parse
_tags
(
tags
):
return
[
o
.
strip
()
for
o
in
tags
.
split
(
','
)
if
o
.
strip
()]
def
require_instance_manager
(
func
):
...
...
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