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
d133ea62
authored
Oct 02, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Various cleanup
parent
ab7160e2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
24 deletions
+17
-24
taggit/forms.py
+1
-0
taggit/managers.py
+2
-1
taggit/tests/tests.py
+14
-23
No files found.
taggit/forms.py
View file @
d133ea62
...
@@ -14,6 +14,7 @@ class TagField(forms.CharField):
...
@@ -14,6 +14,7 @@ class TagField(forms.CharField):
widget
=
TagWidget
widget
=
TagWidget
def
clean
(
self
,
value
):
def
clean
(
self
,
value
):
value
=
super
(
TagField
,
self
)
.
clean
(
value
)
try
:
try
:
return
parse_tags
(
value
)
return
parse_tags
(
value
)
except
ValueError
:
except
ValueError
:
...
...
taggit/managers.py
View file @
d133ea62
...
@@ -36,7 +36,8 @@ class TaggableRel(ManyToManyRel):
...
@@ -36,7 +36,8 @@ class TaggableRel(ManyToManyRel):
class
TaggableManager
(
RelatedField
):
class
TaggableManager
(
RelatedField
):
def
__init__
(
self
,
verbose_name
=
_
(
"Tags"
),
help_text
=
None
,
through
=
None
,
blank
=
False
):
def
__init__
(
self
,
verbose_name
=
_
(
"Tags"
),
help_text
=
None
,
through
=
None
,
blank
=
False
):
self
.
use_gfk
=
through
is
None
or
issubclass
(
through
,
GenericTaggedItemBase
)
self
.
use_gfk
=
through
is
None
or
issubclass
(
through
,
GenericTaggedItemBase
)
self
.
through
=
through
or
TaggedItem
self
.
through
=
through
or
TaggedItem
self
.
rel
=
TaggableRel
(
to
=
self
.
through
.
_meta
.
get_field
(
"tag"
)
.
rel
.
to
)
self
.
rel
=
TaggableRel
(
to
=
self
.
through
.
_meta
.
get_field
(
"tag"
)
.
rel
.
to
)
...
...
taggit/tests/tests.py
View file @
d133ea62
from
unittest
import
TestCase
as
UnitTestCase
from
unittest
import
TestCase
as
UnitTestCase
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ValidationError
from
django.db
import
connection
from
django.db
import
connection
from
django.test
import
TestCase
,
TransactionTestCase
from
django.test
import
TestCase
,
TransactionTestCase
...
@@ -320,8 +321,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -320,8 +321,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self
.
assertEqual
(
self
.
food_model
.
objects
.
count
(),
1
)
self
.
assertEqual
(
self
.
food_model
.
objects
.
count
(),
1
)
f
=
self
.
form_class
({
"name"
:
"raspberry"
})
f
=
self
.
form_class
({
"name"
:
"raspberry"
})
raspberry
=
f
.
save
()
self
.
assertFalse
(
f
.
is_valid
())
self
.
assert_tags_equal
(
raspberry
.
tags
.
all
(),
[])
f
=
self
.
form_class
(
instance
=
apple
)
f
=
self
.
form_class
(
instance
=
apple
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
...
@@ -334,6 +334,18 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -334,6 +334,18 @@ class TaggableFormTestCase(BaseTaggingTestCase):
f
=
self
.
form_class
(
instance
=
apple
)
f
=
self
.
form_class
(
instance
=
apple
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has space", "has,comma", delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has space", "has,comma", delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
def
test_formfield
(
self
):
tm
=
TaggableManager
(
verbose_name
=
'categories'
,
help_text
=
'Add some categories'
,
blank
=
True
)
ff
=
tm
.
formfield
()
self
.
assertEqual
(
ff
.
label
,
'categories'
)
self
.
assertEqual
(
ff
.
help_text
,
u'Add some categories'
)
self
.
assertEqual
(
ff
.
required
,
False
)
self
.
assertEqual
(
ff
.
clean
(
""
),
[])
tm
=
TaggableManager
()
ff
=
tm
.
formfield
()
self
.
assertRaises
(
ValidationError
,
ff
.
clean
,
""
)
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
form_class
=
DirectFoodForm
form_class
=
DirectFoodForm
...
@@ -431,24 +443,3 @@ class TagStringParseTestCase(UnitTestCase):
...
@@ -431,24 +443,3 @@ class TagStringParseTestCase(UnitTestCase):
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
spaces
,
comma
]),
u'"com,ma", "spa ces", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
spaces
,
comma
]),
u'"com,ma", "spa ces", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
comma
]),
u'"com,ma", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
comma
]),
u'"com,ma", plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
comma
,
spaces
]),
u'"com,ma", "spa ces"'
)
self
.
assertEqual
(
edit_string_for_tags
([
comma
,
spaces
]),
u'"com,ma", "spa ces"'
)
class
TagAdminFormTestCase
(
BaseTaggingTestCase
):
def
test_managers
(
self
):
tm
=
TaggableManager
(
verbose_name
=
'categories'
,
help_text
=
'Add some categories'
,
blank
=
True
)
self
.
assertEqual
(
tm
.
verbose_name
,
'categories'
)
self
.
assertEqual
(
tm
.
help_text
,
u'Add some categories'
)
self
.
assertEqual
(
tm
.
blank
,
True
)
def
test_formfield
(
self
):
tm
=
TaggableManager
(
verbose_name
=
'categories'
,
help_text
=
'Add some categories'
,
blank
=
True
)
ff
=
tm
.
formfield
()
self
.
assertEqual
(
ff
.
label
,
'categories'
)
self
.
assertEqual
(
ff
.
help_text
,
u'Add some categories'
)
self
.
assertEqual
(
ff
.
required
,
False
)
def
test_formfield_modified
(
self
):
tm
=
TaggableManager
(
verbose_name
=
'categories'
,
help_text
=
'Add some categories'
,
blank
=
True
)
ff
=
tm
.
formfield
(
required
=
True
,
help_text
=
'new help'
)
self
.
assertEqual
(
ff
.
label
,
'categories'
)
self
.
assertEqual
(
ff
.
help_text
,
'new help'
)
self
.
assertEqual
(
ff
.
required
,
True
)
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