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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
ea52a9f1
authored
Jun 12, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A start, looks like future progress may be impossible.
parent
7568a6ae
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
44 deletions
+22
-44
runtests.py
+1
-1
taggit/managers.py
+3
-28
taggit/tests/models.py
+3
-0
taggit/tests/tests.py
+15
-15
No files found.
runtests.py
View file @
ea52a9f1
...
...
@@ -23,7 +23,7 @@ def runtests(*test_args):
test_args
=
[
'tests'
]
parent
=
dirname
(
abspath
(
__file__
))
sys
.
path
.
insert
(
0
,
parent
)
failures
=
run_tests
(
test_args
,
verbosity
=
1
,
interactive
=
True
)
failures
=
run_tests
(
test_args
,
verbosity
=
1
,
interactive
=
True
,
failfast
=
True
)
sys
.
exit
(
failures
)
...
...
taggit/managers.py
View file @
ea52a9f1
...
...
@@ -41,7 +41,7 @@ class TaggableManager(object):
def
__init__
(
self
,
verbose_name
=
_
(
"Tags"
),
through
=
None
):
self
.
use_gfk
=
through
is
None
self
.
through
=
through
or
TaggedItem
self
.
rel
=
TaggableRel
(
to
=
self
.
through
)
self
.
rel
=
TaggableRel
(
to
=
self
.
through
.
_meta
.
get_field
(
"tag"
)
.
rel
.
to
)
self
.
verbose_name
=
verbose_name
self
.
editable
=
True
self
.
unique
=
False
...
...
@@ -71,30 +71,7 @@ class TaggableManager(object):
getattr
(
instance
,
self
.
name
)
.
set
(
*
value
)
def
get_prep_lookup
(
self
,
lookup_type
,
value
):
if
lookup_type
!=
"in"
:
raise
ValueError
(
"You can't do lookups other than
\"
in
\"
on Tags"
)
if
all
(
isinstance
(
v
,
Tag
)
for
v
in
value
):
qs
=
self
.
through
.
objects
.
filter
(
tag__in
=
value
)
elif
all
(
isinstance
(
v
,
basestring
)
for
v
in
value
):
qs
=
self
.
through
.
objects
.
filter
(
tag__name__in
=
value
)
elif
all
(
isinstance
(
v
,
(
int
,
long
))
for
v
in
value
):
# This one is really ackward, just don't do it. The ORM does it
# for deletes, but no one else gets to.
return
value
else
:
# Fucking flip-floppers.
raise
ValueError
(
"You can't combine Tag objects and strings. '
%
s' was provided."
%
value
)
if
hasattr
(
models
.
Field
,
"get_prep_lookup"
):
return
models
.
Field
()
.
get_prep_lookup
(
lookup_type
,
qs
)
return
models
.
Field
()
.
get_db_prep_lookup
(
lookup_type
,
qs
)
if
django
.
VERSION
<
(
1
,
2
):
get_db_prep_lookup
=
get_prep_lookup
else
:
def
get_db_prep_lookup
(
self
,
lookup_type
,
value
,
connection
,
prepared
=
False
):
if
not
prepared
:
return
self
.
get_prep_lookup
(
lookup_type
,
value
)
return
models
.
Field
()
.
get_db_prep_lookup
(
lookup_type
,
value
,
connection
=
connection
,
prepared
=
True
)
return
models
.
Field
()
.
get_prep_lookup
(
lookup_type
,
value
)
def
formfield
(
self
,
form_class
=
TagField
,
**
kwargs
):
defaults
=
{
...
...
@@ -113,9 +90,7 @@ class TaggableManager(object):
return
self
.
model
.
_meta
.
object_name
.
lower
()
def
m2m_reverse_name
(
self
):
if
self
.
use_gfk
:
return
"id"
return
self
.
through
.
_meta
.
pk
.
column
return
self
.
through
.
_meta
.
get_field_by_name
(
"tag"
)[
0
]
.
column
def
m2m_column_name
(
self
):
if
self
.
use_gfk
:
...
...
taggit/tests/models.py
View file @
ea52a9f1
...
...
@@ -50,6 +50,9 @@ class CustomPKFood(models.Model):
tags
=
TaggableManager
(
through
=
TaggedCustomPKFood
)
def
__unicode__
(
self
):
return
self
.
name
class
TaggedCustomPKPet
(
TaggedItemBase
):
content_object
=
models
.
ForeignKey
(
'CustomPKPet'
)
...
...
taggit/tests/tests.py
View file @
ea52a9f1
...
...
@@ -110,11 +110,11 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
pear
.
tags
.
add
(
"green"
)
self
.
assertEqual
(
list
(
self
.
food_model
.
objects
.
filter
(
tags__in
=
[
"red"
])),
list
(
self
.
food_model
.
objects
.
filter
(
tags__
name__
in
=
[
"red"
])),
[
apple
]
)
self
.
assertEqual
(
list
(
self
.
food_model
.
objects
.
filter
(
tags__in
=
[
"green"
])),
list
(
self
.
food_model
.
objects
.
filter
(
tags__
name__
in
=
[
"green"
])),
[
apple
,
pear
]
)
...
...
@@ -123,18 +123,18 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
dog
=
self
.
pet_model
.
objects
.
create
(
name
=
"dog"
)
dog
.
tags
.
add
(
"woof"
,
"red"
)
self
.
assertEqual
(
list
(
self
.
food_model
.
objects
.
filter
(
tags__in
=
[
"red"
])
.
distinct
()),
list
(
self
.
food_model
.
objects
.
filter
(
tags__
name__
in
=
[
"red"
])
.
distinct
()),
[
apple
]
)
tag
=
Tag
.
objects
.
get
(
name
=
"woof"
)
self
.
assertEqual
(
list
(
self
.
pet_model
.
objects
.
filter
(
tags__in
=
[
tag
])),
[
dog
])
self
.
assertEqual
(
list
(
self
.
pet_model
.
objects
.
filter
(
tags__
name__
in
=
[
tag
])),
[
dog
])
cat
=
self
.
housepet_model
.
objects
.
create
(
name
=
"cat"
,
trained
=
True
)
cat
.
tags
.
add
(
"fuzzy"
)
self
.
assertEqual
(
map
(
lambda
o
:
o
.
pk
,
self
.
pet_model
.
objects
.
filter
(
tags__in
=
[
"fuzzy"
])),
map
(
lambda
o
:
o
.
pk
,
self
.
pet_model
.
objects
.
filter
(
tags__
name__
in
=
[
"fuzzy"
])),
[
kitty
.
pk
,
cat
.
pk
]
)
...
...
@@ -158,16 +158,16 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
apple
.
tags
.
add
(
"juicy"
,
"juicy"
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'juicy'
])
def
test_query_traverse
(
self
):
spot
=
self
.
pet_model
.
objects
.
create
(
name
=
'Spot'
)
spike
=
self
.
pet_model
.
objects
.
create
(
name
=
'Spike'
)
spot
.
tags
.
add
(
'scary'
)
spike
.
tags
.
add
(
'fluffy'
)
lookup_kwargs
=
{
'
%
s__name'
%
(
self
.
pet_model
.
_meta
.
object_name
.
lower
()):
'Spot'
}
self
.
assert_tags_equal
(
[
i
.
tag
for
i
in
self
.
taggeditem_model
.
objects
.
filter
(
**
lookup_kwargs
)],
[
'scary'
]
)
#
def test_query_traverse(self):
#
spot = self.pet_model.objects.create(name='Spot')
#
spike = self.pet_model.objects.create(name='Spike')
#
spot.tags.add('scary')
#
spike.tags.add('fluffy')
#
lookup_kwargs = {'%s__name' % (self.pet_model._meta.object_name.lower()): 'Spot'}
#
self.assert_tags_equal(
#
[i.tag for i in self.taggeditem_model.objects.filter(**lookup_kwargs)],
#
['scary']
#
)
class
TaggableManagerDirectTestCase
(
TaggableManagerTestCase
):
...
...
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