]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/node.py
Update last commit, change response to forbidden.
[osqa.git] / forum / models / node.py
index 13749cd9872a5af40019e7154b96f7df12a9bff5..00cbbd0d71cac3a719feed84da895788f06157e1 100644 (file)
@@ -77,6 +77,7 @@ class NodeMetaClass(models.Model.__metaclass__):
 \r
 \r
 node_create = django.dispatch.Signal(providing_args=['instance'])\r
+node_edit = django.dispatch.Signal(providing_args=['instance'])\r
 \r
 class Node(BaseModel, NodeContent, DeletableContent):\r
     __metaclass__ = NodeMetaClass\r
@@ -89,12 +90,12 @@ class Node(BaseModel, NodeContent, DeletableContent):
 \r
     tags                 = models.ManyToManyField('Tag', related_name='%(class)ss')\r
 \r
-    score                 = models.IntegerField(default=0)\r
-    vote_up_count         = models.IntegerField(default=0)\r
+    score                 = DenormalizedField(default=0)\r
+    vote_up_count         = DenormalizedField(default=0)\r
     vote_down_count       = models.IntegerField(default=0)\r
 \r
-    comment_count         = models.PositiveIntegerField(default=0)\r
-    offensive_flag_count  = models.SmallIntegerField(default=0)\r
+    comment_count         = DenormalizedField(default=0)\r
+    offensive_flag_count  = DenormalizedField(default=0)\r
 \r
     last_edited_at        = models.DateTimeField(null=True, blank=True)\r
     last_edited_by        = models.ForeignKey(User, null=True, blank=True, related_name='last_edited_%(class)ss')\r
@@ -136,14 +137,17 @@ class Node(BaseModel, NodeContent, DeletableContent):
         self.body = revision.body\r
 \r
         old_revision = self.active_revision\r
-\r
         self.active_revision = revision\r
-        self.save()\r
 \r
         if not old_revision:\r
+            signal = node_create\r
+        else:\r
             self.last_edited_at = datetime.datetime.now()\r
             self.last_edited_by = user\r
-            node_create.send(sender=self.__class__, instance=self)\r
+            signal = node_edit\r
+\r
+        self.save()\r
+        signal.send(sender=self.__class__, instance=self)\r
 \r
     def get_tag_list_if_changed(self):\r
         dirty = self.get_dirty_fields()\r
@@ -201,7 +205,7 @@ class Node(BaseModel, NodeContent, DeletableContent):
         app_label = 'forum'\r
 \r
 \r
-class NodeRevision(NodeContent):\r
+class NodeRevision(BaseModel, NodeContent):\r
     node       = models.ForeignKey(Node, related_name='revisions')\r
     summary    = models.CharField(max_length=300)\r
     revision   = models.PositiveIntegerField()\r