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
0ec48c52
authored
May 28, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated for 2.4 compatibility, thanks Charles.
parent
15645ff6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
21 deletions
+15
-21
docs/index.txt
+3
-0
taggit/managers.py
+8
-3
taggit/tests/tests.py
+3
-17
taggit/utils.py
+1
-1
No files found.
docs/index.txt
View file @
0ec48c52
...
@@ -4,6 +4,9 @@ Welcome to django-taggit's documentation!
...
@@ -4,6 +4,9 @@ Welcome to django-taggit's documentation!
``django-taggit`` is a reusable Django application designed to making adding
``django-taggit`` is a reusable Django application designed to making adding
tagging to your project easy and fun.
tagging to your project easy and fun.
``django-taggit`` works with Django 1.1 and 1.2 (see the issues documentation
for known issues with older versions of Django), and Python 2.4-2.X.
.. toctree::
.. toctree::
:maxdepth: 2
:maxdepth: 2
...
...
taggit/managers.py
View file @
0ec48c52
from
collections
import
defaultdict
import
django
import
django
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.contrib.contenttypes.generic
import
GenericForeignKey
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
...
@@ -13,6 +11,12 @@ from taggit.models import Tag, TaggedItem
...
@@ -13,6 +11,12 @@ from taggit.models import Tag, TaggedItem
from
taggit.utils
import
require_instance_manager
from
taggit.utils
import
require_instance_manager
try
:
all
except
NameError
:
# 2.4 compat
from
django.utils.itercompat
import
all
class
TaggableRel
(
ManyToManyRel
):
class
TaggableRel
(
ManyToManyRel
):
def
__init__
(
self
,
to
):
def
__init__
(
self
,
to
):
...
@@ -183,8 +187,9 @@ class _TaggableManager(models.Manager):
...
@@ -183,8 +187,9 @@ class _TaggableManager(models.Manager):
for
obj
in
objs
:
for
obj
in
objs
:
items
[(
getattr
(
obj
,
f
.
rel
.
field_name
),)]
=
obj
items
[(
getattr
(
obj
,
f
.
rel
.
field_name
),)]
=
obj
else
:
else
:
preload
=
defaultdict
(
set
)
preload
=
{}
for
result
in
qs
:
for
result
in
qs
:
preload
.
setdefault
(
result
[
'content_type'
],
set
())
preload
[
result
[
"content_type"
]]
.
add
(
result
[
"object_id"
])
preload
[
result
[
"content_type"
]]
.
add
(
result
[
"object_id"
])
for
ct
,
obj_ids
in
preload
.
iteritems
():
for
ct
,
obj_ids
in
preload
.
iteritems
():
...
...
taggit/tests/tests.py
View file @
0ec48c52
from
__future__
import
with_statement
from
contextlib
import
contextmanager
from
django.test
import
TestCase
from
django.test
import
TestCase
from
taggit.models
import
Tag
,
TaggedItem
from
taggit.models
import
Tag
,
TaggedItem
...
@@ -16,16 +13,6 @@ class BaseTaggingTest(TestCase):
...
@@ -16,16 +13,6 @@ class BaseTaggingTest(TestCase):
tags
.
sort
()
tags
.
sort
()
self
.
assertEqual
(
got
,
tags
)
self
.
assertEqual
(
got
,
tags
)
@contextmanager
def
assert_raises
(
self
,
exc_type
):
try
:
yield
except
Exception
,
e
:
self
.
assert_
(
type
(
e
)
is
exc_type
,
"
%
s didn't match expected "
"exception type
%
s"
%
(
e
,
exc_type
))
else
:
self
.
fail
(
"No exception raised, expected
%
s"
%
exc_type
)
class
TaggableManagerTestCase
(
BaseTaggingTest
):
class
TaggableManagerTestCase
(
BaseTaggingTest
):
food_model
=
Food
food_model
=
Food
...
@@ -66,10 +53,9 @@ class TaggableManagerTestCase(BaseTaggingTest):
...
@@ -66,10 +53,9 @@ class TaggableManagerTestCase(BaseTaggingTest):
apple
.
delete
()
apple
.
delete
()
self
.
assert_tags_equal
(
self
.
food_model
.
tags
.
all
(),
[
"green"
])
self
.
assert_tags_equal
(
self
.
food_model
.
tags
.
all
(),
[
"green"
])
f
=
self
.
food_model
()
food_instance
=
self
.
food_model
()
with
self
.
assert_raises
(
ValueError
):
self
.
assertRaises
(
ValueError
,
lambda
:
food_instance
.
tags
.
all
())
f
.
tags
.
all
()
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"
)
...
...
taggit/utils.py
View file @
0ec48c52
from
functools
import
wraps
from
django.utils.functional
import
wraps
def
parse_tags
(
tags
):
def
parse_tags
(
tags
):
if
tags
is
None
:
if
tags
is
None
:
...
...
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