\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
\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
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
\r
if self.parent_id and not self.abs_parent_id:\r
self.abs_parent = self.parent.absolute_parent\r
+\r
+ self.__dict__['score'] = self.__dict__['vote_up_count'] - self.__dict__['vote_down_count']\r
\r
tags = self.get_tag_list_if_changed()\r
super(Node, self).save(*args, **kwargs)\r
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