]> git.openstreetmap.org Git - osqa.git/commitdiff
Merge cacheimp -> master
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 7 Apr 2011 11:22:50 +0000 (11:22 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 7 Apr 2011 11:22:50 +0000 (11:22 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@940 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/base.py
forum/models/node.py
forum/models/tag.py
forum/utils/html.py

index bf132c4e1bca3177cfe666ade6f95742c0bfe5a0..260910635c2291afaa5a16a83d14048670034d34 100644 (file)
@@ -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:
index a71ae4725898fbfc7dc6cddaa854590b9f248d39..afb04cf50ce91fccfbb2e0e157fb01849d890d82 100644 (file)
@@ -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'
index c84a922d192a3ae330a815b60a4c7b7cc13f530a..5b6bef381474debedceab58b05575c29223b1563 100644 (file)
@@ -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):
index bf84e2f641c49c519fe6163f615468f42231c778..28a6a4b9647fe990dca340d502102c44a542e7ff 100644 (file)
@@ -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):