to_return = [(isinstance(tr, ToFetch) and fetched[str(tr)] or tr) for tr in to_return]
to_cache.update(dict([(self.model.infer_cache_key({on_cache_query_attr: attr}), r._as_dict()) for attr, r in fetched.items()]))
+
if len(to_cache):
cache.set_many(to_cache, 60 * 60)
def save(self, full_save=False, *args, **kwargs):
put_back = [k for k, v in self.__dict__.items() if isinstance(v, models.expressions.ExpressionNode)]
+ if hasattr(self, '_state'):
+ self._state.db = 'default'
+
if self.id and not full_save:
self.__class__.objects.filter(id=self.id).update(**self._get_update_kwargs())
else:
tag.save()
def delete(self, *args, **kwargs):
+ for tag in self.tags.all():
+ tag.add_to_usage_count(-1)
+ tag.save()
+
self.active_revision = None
self.save()
tags_changed = self._process_changes_in_tags()
super(Node, self).save(*args, **kwargs)
- if tags_changed: self.tags = list(Tag.objects.filter(name__in=self.tagname_list()))
+ if tags_changed:
+ self.tags = list(Tag.objects.filter(name__in=self.tagname_list()))
class Meta:
app_label = 'forum'
app_label = 'forum'
def __unicode__(self):
- return u'%s' % self.name
+ return self.name
def add_to_usage_count(self, value):
if self.used_count + value < 0:
self.used_count = models.F('used_count') + value
def cache_key(self):
- return self._generate_cache_key(self.name)
+ return self._generate_cache_key(Tag.safe_cache_name(self.name))
+
+ @classmethod
+ def safe_cache_name(cls, name):
+ return "".join([str(ord(c)) for c in name])
@classmethod
def infer_cache_key(cls, querydict):
if 'name' in querydict:
- return cls._generate_cache_key(querydict['name'])
+ return cls._generate_cache_key(cls.safe_cache_name(querydict['name']))
- return BaseModel.infer_cache_key(querydict)
+ return None
@classmethod
def value_to_list_on_cache_query(cls):
from html5lib import sanitizer, serializer, tokenizer, treebuilders, treewalkers, HTMLParser
from django.utils.html import strip_tags
from forum.utils.html2text import HTML2Text
-from django.template import mark_safe
+from django.utils.safestring import mark_safe
from forum import settings
class HTMLSanitizerMixin(sanitizer.HTMLSanitizerMixin):