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 Get all tags on obj, optionally limited by key and/or category
""" """
if key or category: print "Key: %s, Category: %s" % (key, category)
key_cands = Q(db_key__iexact=key.lower().strip()) if key!=None else Q() tags = _GA(obj, "db_tags").all()
cat_cands = Q(db_category__iexact=category.lower.strip()) if key!=None else Q() if key:
return _GA(obj, "db_tags").filter(cat_cands & key_cands) tags = tags.filter(db_key__iexact=key.lower().strip())
else: if category:
return list(_GA(obj, "db_tags").all()) tags = tags.filter(db_category__iexact=category.lower().strip())
return list(tags)
def get_tag(self, key=None, category=None): def get_tag(self, key=None, category=None):
""" """

View file

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