author = models.ForeignKey(User, related_name='%(class)ss')\r
body = models.TextField()\r
\r
+ @property\r
+ def user(self):\r
+ return self.author\r
+\r
@property\r
def html(self):\r
return mark_safe(sanitize_html(markdown.markdown(self.body)))\r
def headline(self):\r
return self.title\r
\r
- @property\r
- def summary(self):\r
- return strip_tags(self.html)[:300]\r
-\r
def tagname_list(self):\r
if self.tagnames:\r
return [name for name in self.tagnames.split(u' ')]\r
name = node_cls.__name__.lower()\r
\r
def children(self):\r
- return node_cls.objects.filter(parent=self)\r
+ if node_cls._meta.proxy:\r
+ return node_cls.objects.filter(node_type=name, parent=self)\r
+ else:\r
+ return node_cls.objects.filter(parent=self)\r
\r
def parent(self):\r
p = self.__dict__.get('_%s_cache' % name, None)\r
\r
- if p is None:\r
- try:\r
- p = self.parent.leaf\r
- self.__dict__['_%s_cache' % name] = p\r
- except Exception, e:\r
- pass\r
+ if p is None and (self.parent is not None) and self.parent.node_type == name:\r
+ p = self.parent.leaf\r
+ self.__dict__['_%s_cache' % name] = p\r
\r
return p\r
\r
Node.add_to_class(name, property(parent))\r
\r
\r
+node_create = django.dispatch.Signal(providing_args=['instance'])\r
+\r
class Node(BaseModel, NodeContent, DeletableContent):\r
__metaclass__ = NodeMetaClass\r
\r
vote_up_count = models.IntegerField(default=0)\r
vote_down_count = models.IntegerField(default=0)\r
\r
- comment_count = models.PositiveIntegerField(default=0)\r
+ comment_count = models.PositiveIntegerField(default=0)\r
offensive_flag_count = models.SmallIntegerField(default=0)\r
\r
last_edited_at = models.DateTimeField(null=True, blank=True)\r
def leaf(self):\r
return NodeMetaClass.types[self.node_type].objects.get(id=self.id)\r
\r
+ @property\r
+ def summary(self):\r
+ return strip_tags(self.html)[:300]\r
+\r
def create_revision(self, user, **kwargs):\r
revision = NodeRevision(author=user, **kwargs)\r
\r
self.title = revision.title\r
self.tagnames = revision.tagnames\r
self.body = revision.body\r
- \r
- self.last_edited_at = datetime.datetime.now()\r
- self.last_edited_by = user\r
+\r
+ old_revision = self.active_revision\r
\r
self.active_revision = revision\r
self.save()\r
\r
+ if not old_revision:\r
+ self.last_edited_at = datetime.datetime.now()\r
+ self.last_edited_by = user\r
+ node_create.send(sender=self.__class__, instance=self)\r
+\r
def get_tag_list_if_changed(self):\r
dirty = self.get_dirty_fields()\r
\r