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
18566407
authored
Sep 07, 2010
by
Carl Meyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trailing whitespace cleanup
parent
d9f3a23a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
51 deletions
+51
-51
taggit/forms.py
+1
-1
taggit/managers.py
+3
-3
taggit/models.py
+6
-6
taggit/tests/models.py
+9
-9
taggit/tests/tests.py
+32
-32
No files found.
taggit/forms.py
View file @
18566407
...
@@ -12,7 +12,7 @@ class TagWidget(forms.TextInput):
...
@@ -12,7 +12,7 @@ class TagWidget(forms.TextInput):
class
TagField
(
forms
.
CharField
):
class
TagField
(
forms
.
CharField
):
widget
=
TagWidget
widget
=
TagWidget
def
clean
(
self
,
value
):
def
clean
(
self
,
value
):
try
:
try
:
return
parse_tags
(
value
)
return
parse_tags
(
value
)
...
...
taggit/managers.py
View file @
18566407
...
@@ -115,13 +115,13 @@ class TaggableManager(RelatedField):
...
@@ -115,13 +115,13 @@ class TaggableManager(RelatedField):
class
_TaggableManager
(
models
.
Manager
):
class
_TaggableManager
(
models
.
Manager
):
def
__init__
(
self
,
through
):
def
__init__
(
self
,
through
):
self
.
through
=
through
self
.
through
=
through
def
get_query_set
(
self
):
def
get_query_set
(
self
):
return
self
.
through
.
tags_for
(
self
.
model
,
self
.
instance
)
return
self
.
through
.
tags_for
(
self
.
model
,
self
.
instance
)
def
_lookup_kwargs
(
self
):
def
_lookup_kwargs
(
self
):
return
self
.
through
.
lookup_kwargs
(
self
.
instance
)
return
self
.
through
.
lookup_kwargs
(
self
.
instance
)
@require_instance_manager
@require_instance_manager
def
add
(
self
,
*
tags
):
def
add
(
self
,
*
tags
):
for
tag
in
tags
:
for
tag
in
tags
:
...
@@ -157,7 +157,7 @@ class _TaggableManager(models.Manager):
...
@@ -157,7 +157,7 @@ class _TaggableManager(models.Manager):
qs
=
qs
.
exclude
(
**
lookup_kwargs
)
qs
=
qs
.
exclude
(
**
lookup_kwargs
)
qs
=
qs
.
filter
(
tag__in
=
self
.
all
())
qs
=
qs
.
filter
(
tag__in
=
self
.
all
())
qs
=
qs
.
order_by
(
'-n'
)
qs
=
qs
.
order_by
(
'-n'
)
# TODO: This all feels like a bit of a hack.
# TODO: This all feels like a bit of a hack.
items
=
{}
items
=
{}
if
len
(
lookup_keys
)
==
1
:
if
len
(
lookup_keys
)
==
1
:
...
...
taggit/models.py
View file @
18566407
...
@@ -9,13 +9,13 @@ from django.utils.translation import ugettext_lazy as _, ugettext
...
@@ -9,13 +9,13 @@ from django.utils.translation import ugettext_lazy as _, ugettext
class
TagBase
(
models
.
Model
):
class
TagBase
(
models
.
Model
):
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
max_length
=
100
)
name
=
models
.
CharField
(
verbose_name
=
_
(
'Name'
),
max_length
=
100
)
slug
=
models
.
SlugField
(
verbose_name
=
_
(
'Slug'
),
unique
=
True
,
max_length
=
100
)
slug
=
models
.
SlugField
(
verbose_name
=
_
(
'Slug'
),
unique
=
True
,
max_length
=
100
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
pk
and
not
self
.
slug
:
if
not
self
.
pk
and
not
self
.
slug
:
self
.
slug
=
slug
=
slugify
(
self
.
name
)
self
.
slug
=
slug
=
slugify
(
self
.
name
)
...
@@ -57,7 +57,7 @@ class ItemBase(models.Model):
...
@@ -57,7 +57,7 @@ class ItemBase(models.Model):
"object"
:
self
.
content_object
,
"object"
:
self
.
content_object
,
"tag"
:
self
.
tag
"tag"
:
self
.
tag
}
}
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
...
@@ -81,7 +81,7 @@ class TaggedItemBase(ItemBase):
...
@@ -81,7 +81,7 @@ class TaggedItemBase(ItemBase):
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(class)
s_items"
)
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(class)
s_items"
)
else
:
else
:
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(app_label)
s_
%(class)
s_items"
)
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
"
%(app_label)
s_
%(class)
s_items"
)
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
...
@@ -114,7 +114,7 @@ class GenericTaggedItemBase(ItemBase):
...
@@ -114,7 +114,7 @@ class GenericTaggedItemBase(ItemBase):
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
@classmethod
@classmethod
def
lookup_kwargs
(
cls
,
instance
):
def
lookup_kwargs
(
cls
,
instance
):
return
{
return
{
...
...
taggit/tests/models.py
View file @
18566407
...
@@ -6,17 +6,17 @@ from taggit.models import TaggedItemBase, GenericTaggedItemBase, TagBase
...
@@ -6,17 +6,17 @@ from taggit.models import TaggedItemBase, GenericTaggedItemBase, TagBase
class
Food
(
models
.
Model
):
class
Food
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
()
tags
=
TaggableManager
()
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
class
Pet
(
models
.
Model
):
class
Pet
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
()
tags
=
TaggableManager
()
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -41,7 +41,7 @@ class DirectPet(models.Model):
...
@@ -41,7 +41,7 @@ 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
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -61,7 +61,7 @@ class CustomPKFood(models.Model):
...
@@ -61,7 +61,7 @@ class CustomPKFood(models.Model):
name
=
models
.
CharField
(
max_length
=
50
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
primary_key
=
True
)
tags
=
TaggableManager
(
through
=
TaggedCustomPKFood
)
tags
=
TaggableManager
(
through
=
TaggedCustomPKFood
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -69,7 +69,7 @@ class CustomPKPet(models.Model):
...
@@ -69,7 +69,7 @@ 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
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -88,7 +88,7 @@ class OfficialFood(models.Model):
...
@@ -88,7 +88,7 @@ class OfficialFood(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
(
through
=
OfficialThroughModel
)
tags
=
TaggableManager
(
through
=
OfficialThroughModel
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -96,7 +96,7 @@ class OfficialPet(models.Model):
...
@@ -96,7 +96,7 @@ class OfficialPet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
tags
=
TaggableManager
(
through
=
OfficialThroughModel
)
tags
=
TaggableManager
(
through
=
OfficialThroughModel
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
...
...
taggit/tests/tests.py
View file @
18566407
...
@@ -7,7 +7,7 @@ from taggit.tests.forms import (FoodForm, DirectFoodForm, CustomPKFoodForm,
...
@@ -7,7 +7,7 @@ from taggit.tests.forms import (FoodForm, DirectFoodForm, CustomPKFoodForm,
OfficialFoodForm
)
OfficialFoodForm
)
from
taggit.tests.models
import
(
Food
,
Pet
,
HousePet
,
DirectFood
,
DirectPet
,
from
taggit.tests.models
import
(
Food
,
Pet
,
HousePet
,
DirectFood
,
DirectPet
,
DirectHousePet
,
TaggedPet
,
CustomPKFood
,
CustomPKPet
,
CustomPKHousePet
,
DirectHousePet
,
TaggedPet
,
CustomPKFood
,
CustomPKPet
,
CustomPKHousePet
,
TaggedCustomPKPet
,
OfficialFood
,
OfficialPet
,
OfficialHousePet
,
TaggedCustomPKPet
,
OfficialFood
,
OfficialPet
,
OfficialHousePet
,
OfficialThroughModel
,
OfficialTag
)
OfficialThroughModel
,
OfficialTag
)
from
taggit.utils
import
parse_tags
,
edit_string_for_tags
from
taggit.utils
import
parse_tags
,
edit_string_for_tags
...
@@ -34,11 +34,11 @@ class TagModelTestCase(BaseTaggingTransactionTestCase):
...
@@ -34,11 +34,11 @@ class TagModelTestCase(BaseTaggingTransactionTestCase):
def
test_unique_slug
(
self
):
def
test_unique_slug
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"Red"
,
"red"
)
apple
.
tags
.
add
(
"Red"
,
"red"
)
def
test_update
(
self
):
def
test_update
(
self
):
special
=
self
.
tag_model
.
objects
.
create
(
name
=
"special"
)
special
=
self
.
tag_model
.
objects
.
create
(
name
=
"special"
)
special
.
save
()
special
.
save
()
def
test_add
(
self
):
def
test_add
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
yummy
=
self
.
tag_model
.
objects
.
create
(
name
=
"yummy"
)
yummy
=
self
.
tag_model
.
objects
.
create
(
name
=
"yummy"
)
...
@@ -62,7 +62,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -62,7 +62,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
housepet_model
=
HousePet
housepet_model
=
HousePet
taggeditem_model
=
TaggedItem
taggeditem_model
=
TaggedItem
tag_model
=
Tag
tag_model
=
Tag
def
test_add_tag
(
self
):
def
test_add_tag
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
self
.
assertEqual
(
list
(
apple
.
tags
.
all
()),
[])
self
.
assertEqual
(
list
(
apple
.
tags
.
all
()),
[])
...
@@ -93,14 +93,14 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -93,14 +93,14 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
tag
=
self
.
tag_model
.
objects
.
create
(
name
=
"delicious"
)
tag
=
self
.
tag_model
.
objects
.
create
(
name
=
"delicious"
)
apple
.
tags
.
add
(
tag
)
apple
.
tags
.
add
(
tag
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
"red"
,
"delicious"
])
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
"red"
,
"delicious"
])
apple
.
delete
()
apple
.
delete
()
self
.
assert_tags_equal
(
self
.
food_model
.
tags
.
all
(),
[
"green"
])
self
.
assert_tags_equal
(
self
.
food_model
.
tags
.
all
(),
[
"green"
])
def
test_require_pk
(
self
):
def
test_require_pk
(
self
):
food_instance
=
self
.
food_model
()
food_instance
=
self
.
food_model
()
self
.
assertRaises
(
ValueError
,
lambda
:
food_instance
.
tags
.
all
())
self
.
assertRaises
(
ValueError
,
lambda
:
food_instance
.
tags
.
all
())
def
test_delete_obj
(
self
):
def
test_delete_obj
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"red"
)
apple
.
tags
.
add
(
"red"
)
...
@@ -109,24 +109,24 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -109,24 +109,24 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
strawberry
.
tags
.
add
(
"red"
)
strawberry
.
tags
.
add
(
"red"
)
apple
.
delete
()
apple
.
delete
()
self
.
assert_tags_equal
(
strawberry
.
tags
.
all
(),
[
"red"
])
self
.
assert_tags_equal
(
strawberry
.
tags
.
all
(),
[
"red"
])
def
test_delete_bulk
(
self
):
def
test_delete_bulk
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
kitty
=
self
.
pet_model
.
objects
.
create
(
pk
=
apple
.
pk
,
name
=
"kitty"
)
kitty
=
self
.
pet_model
.
objects
.
create
(
pk
=
apple
.
pk
,
name
=
"kitty"
)
apple
.
tags
.
add
(
"red"
,
"delicious"
,
"fruit"
)
apple
.
tags
.
add
(
"red"
,
"delicious"
,
"fruit"
)
kitty
.
tags
.
add
(
"feline"
)
kitty
.
tags
.
add
(
"feline"
)
self
.
food_model
.
objects
.
all
()
.
delete
()
self
.
food_model
.
objects
.
all
()
.
delete
()
self
.
assert_tags_equal
(
kitty
.
tags
.
all
(),
[
"feline"
])
self
.
assert_tags_equal
(
kitty
.
tags
.
all
(),
[
"feline"
])
def
test_lookup_by_tag
(
self
):
def
test_lookup_by_tag
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"red"
,
"green"
)
apple
.
tags
.
add
(
"red"
,
"green"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"pear"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"pear"
)
pear
.
tags
.
add
(
"green"
)
pear
.
tags
.
add
(
"green"
)
self
.
assertEqual
(
self
.
assertEqual
(
list
(
self
.
food_model
.
objects
.
filter
(
tags__name__in
=
[
"red"
])),
list
(
self
.
food_model
.
objects
.
filter
(
tags__name__in
=
[
"red"
])),
[
apple
]
[
apple
]
...
@@ -150,21 +150,21 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -150,21 +150,21 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
cat
=
self
.
housepet_model
.
objects
.
create
(
name
=
"cat"
,
trained
=
True
)
cat
=
self
.
housepet_model
.
objects
.
create
(
name
=
"cat"
,
trained
=
True
)
cat
.
tags
.
add
(
"fuzzy"
)
cat
.
tags
.
add
(
"fuzzy"
)
self
.
assertEqual
(
self
.
assertEqual
(
map
(
lambda
o
:
o
.
pk
,
self
.
pet_model
.
objects
.
filter
(
tags__name__in
=
[
"fuzzy"
])),
map
(
lambda
o
:
o
.
pk
,
self
.
pet_model
.
objects
.
filter
(
tags__name__in
=
[
"fuzzy"
])),
[
kitty
.
pk
,
cat
.
pk
]
[
kitty
.
pk
,
cat
.
pk
]
)
)
def
test_exclude
(
self
):
def
test_exclude
(
self
):
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"red"
,
"green"
,
"delicious"
)
apple
.
tags
.
add
(
"red"
,
"green"
,
"delicious"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"pear"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"pear"
)
pear
.
tags
.
add
(
"green"
,
"delicious"
)
pear
.
tags
.
add
(
"green"
,
"delicious"
)
guava
=
self
.
food_model
.
objects
.
create
(
name
=
"guava"
)
guava
=
self
.
food_model
.
objects
.
create
(
name
=
"guava"
)
self
.
assertEqual
(
self
.
assertEqual
(
map
(
lambda
o
:
o
.
pk
,
self
.
food_model
.
objects
.
exclude
(
tags__name__in
=
[
"red"
])),
map
(
lambda
o
:
o
.
pk
,
self
.
food_model
.
objects
.
exclude
(
tags__name__in
=
[
"red"
])),
[
pear
.
pk
,
guava
.
pk
],
[
pear
.
pk
,
guava
.
pk
],
...
@@ -202,12 +202,12 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
...
@@ -202,12 +202,12 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
self
.
tag_model
.
objects
.
filter
(
**
lookup_kwargs
),
self
.
tag_model
.
objects
.
filter
(
**
lookup_kwargs
),
[
'scary'
]
[
'scary'
]
)
)
def
test_taggeditem_unicode
(
self
):
def
test_taggeditem_unicode
(
self
):
ross
=
self
.
pet_model
.
objects
.
create
(
name
=
"ross"
)
ross
=
self
.
pet_model
.
objects
.
create
(
name
=
"ross"
)
# I keep Ross Perot for a pet, what's it to you?
# I keep Ross Perot for a pet, what's it to you?
ross
.
tags
.
add
(
"president"
)
ross
.
tags
.
add
(
"president"
)
self
.
assertEqual
(
self
.
assertEqual
(
unicode
(
self
.
taggeditem_model
.
objects
.
all
()[
0
]),
unicode
(
self
.
taggeditem_model
.
objects
.
all
()[
0
]),
"ross tagged with president"
"ross tagged with president"
...
@@ -237,16 +237,16 @@ class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
...
@@ -237,16 +237,16 @@ class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
housepet_model
=
OfficialHousePet
housepet_model
=
OfficialHousePet
taggeditem_model
=
OfficialThroughModel
taggeditem_model
=
OfficialThroughModel
tag_model
=
OfficialTag
tag_model
=
OfficialTag
def
test_extra_fields
(
self
):
def
test_extra_fields
(
self
):
self
.
tag_model
.
objects
.
create
(
name
=
"red"
)
self
.
tag_model
.
objects
.
create
(
name
=
"red"
)
self
.
tag_model
.
objects
.
create
(
name
=
"delicious"
,
official
=
True
)
self
.
tag_model
.
objects
.
create
(
name
=
"delicious"
,
official
=
True
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
=
self
.
food_model
.
objects
.
create
(
name
=
"apple"
)
apple
.
tags
.
add
(
"delicious"
,
"red"
)
apple
.
tags
.
add
(
"delicious"
,
"red"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"Pear"
)
pear
=
self
.
food_model
.
objects
.
create
(
name
=
"Pear"
)
pear
.
tags
.
add
(
"delicious"
)
pear
.
tags
.
add
(
"delicious"
)
self
.
assertEqual
(
self
.
assertEqual
(
map
(
lambda
o
:
o
.
pk
,
self
.
food_model
.
objects
.
filter
(
tags__official
=
False
)),
map
(
lambda
o
:
o
.
pk
,
self
.
food_model
.
objects
.
filter
(
tags__official
=
False
)),
[
apple
.
pk
],
[
apple
.
pk
],
...
@@ -256,7 +256,7 @@ class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
...
@@ -256,7 +256,7 @@ class TaggableManagerOfficialTestCase(TaggableManagerTestCase):
class
TaggableFormTestCase
(
BaseTaggingTestCase
):
class
TaggableFormTestCase
(
BaseTaggingTestCase
):
form_class
=
FoodForm
form_class
=
FoodForm
food_model
=
Food
food_model
=
Food
def
test_form
(
self
):
def
test_form
(
self
):
self
.
assertEqual
(
self
.
form_class
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
self
.
assertEqual
(
self
.
form_class
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
...
@@ -271,11 +271,11 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -271,11 +271,11 @@ class TaggableFormTestCase(BaseTaggingTestCase):
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'
,
'delicious'
])
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'green'
,
'red'
,
'yummy'
,
'delicious'
])
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
()
raspberry
=
f
.
save
()
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" /><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>"""
)
...
@@ -287,7 +287,7 @@ class TaggableFormTestCase(BaseTaggingTestCase):
...
@@ -287,7 +287,7 @@ 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>"""
)
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
class
TaggableFormDirectTestCase
(
TaggableFormTestCase
):
form_class
=
DirectFoodForm
form_class
=
DirectFoodForm
food_model
=
DirectFood
food_model
=
DirectFood
...
@@ -315,18 +315,18 @@ class TagStringParseTestCase(UnitTestCase):
...
@@ -315,18 +315,18 @@ class TagStringParseTestCase(UnitTestCase):
self
.
assertEqual
(
parse_tags
(
'one two'
),
[
u'one'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one two'
),
[
u'one'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one two three'
),
[
u'one'
,
u'three'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one two three'
),
[
u'one'
,
u'three'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one one two two'
),
[
u'one'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one one two two'
),
[
u'one'
,
u'two'
])
def
test_with_comma_delimited_multiple_words
(
self
):
def
test_with_comma_delimited_multiple_words
(
self
):
"""
"""
Test with comma-delimited multiple words.
Test with comma-delimited multiple words.
An unquoted comma in the input will trigger this.
An unquoted comma in the input will trigger this.
"""
"""
self
.
assertEqual
(
parse_tags
(
',one'
),
[
u'one'
])
self
.
assertEqual
(
parse_tags
(
',one'
),
[
u'one'
])
self
.
assertEqual
(
parse_tags
(
',one two'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
',one two'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
',one two three'
),
[
u'one two three'
])
self
.
assertEqual
(
parse_tags
(
',one two three'
),
[
u'one two three'
])
self
.
assertEqual
(
parse_tags
(
'a-one, a-two and a-three'
),
self
.
assertEqual
(
parse_tags
(
'a-one, a-two and a-three'
),
[
u'a-one'
,
u'a-two and a-three'
])
[
u'a-one'
,
u'a-two and a-three'
])
def
test_with_double_quoted_multiple_words
(
self
):
def
test_with_double_quoted_multiple_words
(
self
):
"""
"""
Test with double-quoted multiple words.
Test with double-quoted multiple words.
...
@@ -338,19 +338,19 @@ class TagStringParseTestCase(UnitTestCase):
...
@@ -338,19 +338,19 @@ class TagStringParseTestCase(UnitTestCase):
self
.
assertEqual
(
parse_tags
(
'"one two"'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
'"one two"'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
'a-one "a-two and a-three"'
),
self
.
assertEqual
(
parse_tags
(
'a-one "a-two and a-three"'
),
[
u'a-one'
,
u'a-two and a-three'
])
[
u'a-one'
,
u'a-two and a-three'
])
def
test_with_no_loose_commas
(
self
):
def
test_with_no_loose_commas
(
self
):
"""
"""
Test with no loose commas -- split on spaces.
Test with no loose commas -- split on spaces.
"""
"""
self
.
assertEqual
(
parse_tags
(
'one two "thr,ee"'
),
[
u'one'
,
u'thr,ee'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'one two "thr,ee"'
),
[
u'one'
,
u'thr,ee'
,
u'two'
])
def
test_with_loose_commas
(
self
):
def
test_with_loose_commas
(
self
):
"""
"""
Loose commas - split on commas
Loose commas - split on commas
"""
"""
self
.
assertEqual
(
parse_tags
(
'"one", two three'
),
[
u'one'
,
u'two three'
])
self
.
assertEqual
(
parse_tags
(
'"one", two three'
),
[
u'one'
,
u'two three'
])
def
test_tags_with_double_quotes_can_contain_commas
(
self
):
def
test_tags_with_double_quotes_can_contain_commas
(
self
):
"""
"""
Double quotes can contain commas
Double quotes can contain commas
...
@@ -359,7 +359,7 @@ class TagStringParseTestCase(UnitTestCase):
...
@@ -359,7 +359,7 @@ class TagStringParseTestCase(UnitTestCase):
[
u'a-one'
,
u'a-two, and a-three'
])
[
u'a-one'
,
u'a-two, and a-three'
])
self
.
assertEqual
(
parse_tags
(
'"two", one, one, two, "one"'
),
self
.
assertEqual
(
parse_tags
(
'"two", one, one, two, "one"'
),
[
u'one'
,
u'two'
])
[
u'one'
,
u'two'
])
def
test_with_naughty_input
(
self
):
def
test_with_naughty_input
(
self
):
"""
"""
Test with naughty input.
Test with naughty input.
...
...
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