Fixes to Tag Handler and Manager.

This commit is contained in:
Kelketek 2013-08-04 12:47:00 -05:00
parent 1da88deb93
commit e05bfcad85
2 changed files with 10 additions and 9 deletions

View file

@ -154,12 +154,13 @@ class TagManager(models.Manager):
"""
Get all tags on obj, optionally limited by key and/or category
"""
if key or category:
key_cands = Q(db_key__iexact=key.lower().strip()) if key!=None else Q()
cat_cands = Q(db_category__iexact=category.lower.strip()) if key!=None else Q()
return _GA(obj, "db_tags").filter(cat_cands & key_cands)
else:
return list(_GA(obj, "db_tags").all())
print "Key: %s, Category: %s" % (key, category)
tags = _GA(obj, "db_tags").all()
if key:
tags = tags.filter(db_key__iexact=key.lower().strip())
if category:
tags = tags.filter(db_category__iexact=category.lower().strip())
return list(tags)
def get_tag(self, key=None, category=None):
"""

View file

@ -97,7 +97,7 @@ class Attribute(SharedMemoryModel):
# Attribute Database Model setup
#
# These database fields are all set using their corresponding properties,
# named same as the field, but without the db_* prefix.
# named same as the field, but withtout the db_* prefix.
db_key = models.CharField('key', max_length=255, db_index=True)
# access through the value property
db_value = PickledObjectField('value', null=True)
@ -378,12 +378,12 @@ class TagHandler(object):
"Remove a tag from the handler"
for tag in make_iter(tag):
tag = tag.strip().lower() if tag!=None else None
category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None
category = "%s%s" % (self.prefix, category.strip().lower()) if category!=None else None
#TODO This does not delete the tag object itself. Maybe it should do that when no
# objects reference the tag anymore?
tagobj = self.obj.db_tags.filter(db_key=tag, db_category=category)
if tagobj:
self.obj.remove(tagobj[0])
self.obj.db_tags.remove(tagobj[0])
def clear(self):
"Remove all tags from the handler"
self.obj.db_tags.clear()