From: hernani Date: Thu, 7 Apr 2011 11:22:50 +0000 (+0000) Subject: Merge cacheimp -> master X-Git-Tag: live~372 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/7fa400fc50e17b3c017615b296934945531fa715 Merge cacheimp -> master git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@940 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/models/base.py b/forum/models/base.py index bf132c4..2609106 100644 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -150,6 +150,7 @@ class CachedQuerySet(models.query.QuerySet): 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) @@ -257,6 +258,9 @@ class BaseModel(models.Model): 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: diff --git a/forum/models/node.py b/forum/models/node.py index a71ae47..afb04cf 100644 --- a/forum/models/node.py +++ b/forum/models/node.py @@ -437,6 +437,10 @@ class Node(BaseModel, NodeContent): 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() @@ -463,7 +467,8 @@ class Node(BaseModel, NodeContent): 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' diff --git a/forum/models/tag.py b/forum/models/tag.py index c84a922..5b6bef3 100644 --- a/forum/models/tag.py +++ b/forum/models/tag.py @@ -26,7 +26,7 @@ class Tag(BaseModel): 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: @@ -35,14 +35,18 @@ class Tag(BaseModel): 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): diff --git a/forum/utils/html.py b/forum/utils/html.py index bf84e2f..28a6a4b 100644 --- a/forum/utils/html.py +++ b/forum/utils/html.py @@ -3,7 +3,7 @@ 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):