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
b794e7e3
authored
Jun 21, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up the tests.
parent
3b9cffb0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
6 deletions
+32
-6
taggit/models.py
+8
-3
taggit/tests/models.py
+11
-0
taggit/tests/tests.py
+13
-3
No files found.
taggit/models.py
View file @
b794e7e3
...
@@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType
...
@@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.db
import
models
,
IntegrityError
,
transaction
from
django.db
import
models
,
IntegrityError
,
transaction
from
django.template.defaultfilters
import
slugify
from
django.template.defaultfilters
import
slugify
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext
class
Tag
(
models
.
Model
):
class
Tag
(
models
.
Model
):
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
max_length
=
100
)
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
max_length
=
100
)
...
@@ -52,7 +53,10 @@ class TaggedItemBase(models.Model):
...
@@ -52,7 +53,10 @@ class TaggedItemBase(models.Model):
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(app_label)
s_
%(class)
s_items"
)
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(app_label)
s_
%(class)
s_items"
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
_
(
"
%(object)
s tagged with
%(tag)
s"
)
%
{
'object'
:
self
.
content_object
,
'tag'
:
self
.
tag
}
return
ugettext
(
"
%(object)
s tagged with
%(tag)
s"
)
%
{
"object"
:
self
.
content_object
,
"tag"
:
self
.
tag
}
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
...
@@ -80,7 +84,8 @@ class TaggedItemBase(models.Model):
...
@@ -80,7 +84,8 @@ class TaggedItemBase(models.Model):
class
TaggedItem
(
TaggedItemBase
):
class
TaggedItem
(
TaggedItemBase
):
object_id
=
models
.
IntegerField
(
verbose_name
=
_
(
'Object id'
))
object_id
=
models
.
IntegerField
(
verbose_name
=
_
(
'Object id'
))
content_type
=
models
.
ForeignKey
(
ContentType
,
verbose_name
=
_
(
'Content type'
),
related_name
=
"tagged_items"
)
content_type
=
models
.
ForeignKey
(
ContentType
,
verbose_name
=
_
(
'Content type'
),
related_name
=
"tagged_items"
)
content_object
=
GenericForeignKey
()
content_object
=
GenericForeignKey
()
class
Meta
:
class
Meta
:
...
...
taggit/tests/models.py
View file @
b794e7e3
...
@@ -15,6 +15,10 @@ class Pet(models.Model):
...
@@ -15,6 +15,10 @@ class Pet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
()
tags
=
TaggableManager
()
def
__unicode__
(
self
):
return
self
.
name
class
HousePet
(
Pet
):
class
HousePet
(
Pet
):
trained
=
models
.
BooleanField
()
trained
=
models
.
BooleanField
()
...
@@ -36,6 +40,10 @@ class DirectPet(models.Model):
...
@@ -36,6 +40,10 @@ class DirectPet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
(
through
=
TaggedPet
)
tags
=
TaggableManager
(
through
=
TaggedPet
)
def
__unicode__
(
self
):
return
self
.
name
class
DirectHousePet
(
DirectPet
):
class
DirectHousePet
(
DirectPet
):
trained
=
models
.
BooleanField
()
trained
=
models
.
BooleanField
()
...
@@ -57,6 +65,9 @@ class CustomPKPet(models.Model):
...
@@ -57,6 +65,9 @@ class CustomPKPet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
primary_key
=
True
)
tags
=
TaggableManager
(
through
=
TaggedCustomPKPet
)
tags
=
TaggableManager
(
through
=
TaggedCustomPKPet
)
def
__unicode__
(
self
):
return
self
.
name
class
CustomPKHousePet
(
CustomPKPet
):
class
CustomPKHousePet
(
CustomPKPet
):
trained
=
models
.
BooleanField
()
trained
=
models
.
BooleanField
()
taggit/tests/tests.py
View file @
b794e7e3
...
@@ -182,6 +182,16 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -182,6 +182,16 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
[
i
.
tag
for
i
in
self
.
taggeditem_model
.
objects
.
filter
(
**
lookup_kwargs
)],
[
i
.
tag
for
i
in
self
.
taggeditem_model
.
objects
.
filter
(
**
lookup_kwargs
)],
[
'scary'
]
[
'scary'
]
)
)
def
test_taggeditem_unicode
(
self
):
ross
=
self
.
pet_model
.
objects
.
create
(
name
=
"ross"
)
# I keep Ross Perot for a pet, what's it to you?
ross
.
tags
.
add
(
"president"
)
self
.
assertEqual
(
unicode
(
self
.
taggeditem_model
.
objects
.
all
()[
0
]),
"ross tagged with president"
)
class
TaggableManagerDirectTestCase
(
TaggableManagerTestCase
):
class
TaggableManagerDirectTestCase
(
TaggableManagerTestCase
):
...
@@ -209,7 +219,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -209,7 +219,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self
.
assertEqual
(
self
.
form_class
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
self
.
assertEqual
(
self
.
form_class
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
f
=
self
.
form_class
({
'name'
:
'apple'
,
'tags'
:
'green, red, yummy'
})
f
=
self
.
form_class
({
'name'
:
'apple'
,
'tags'
:
'green, red, yummy'
})
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="green, red, yummy" id="id_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="green, red, yummy" id="id_tags" /><
br />A comma-separated list of tags.<
/td></tr>"""
)
f
.
save
()
f
.
save
()
apple
=
self
.
food_model
.
objects
.
get
(
name
=
'apple'
)
apple
=
self
.
food_model
.
objects
.
get
(
name
=
'apple'
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'green'
,
'red'
,
'yummy'
])
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'green'
,
'red'
,
'yummy'
])
...
@@ -225,11 +235,11 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -225,11 +235,11 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self
.
assert_tags_equal
(
raspberry
.
tags
.
all
(),
[])
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" /></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>"""
)
apple
.
tags
.
add
(
'has,comma'
)
apple
.
tags
.
add
(
'has,comma'
)
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,comma" delicious green red yummy" id="id_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,comma" delicious green red yummy" id="id_tags" /><
br />A comma-separated list of tags.<
/td></tr>"""
)
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
...
...
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