]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/comment.py
removing tabs/spaces inconsistency in the Comment model, making the Comment.comment...
[osqa.git] / forum / models / comment.py
index 15049b2d211d733841b3160d19600d4042a84e6e..afa674f403381c658980d3420f2f2f53673e1180 100644 (file)
@@ -1,57 +1,61 @@
-from base import *\r
-import re\r
-\r
-class Comment(Node):\r
-    class Meta(Node.Meta):\r
-        ordering = ('-added_at',)\r
-        proxy = True\r
-\r
-    def _update_parent_comment_count(self, diff):\r
-        parent = self.parent\r
-        parent.comment_count = parent.comment_count + diff\r
-        parent.save()\r
-\r
-    @property\r
-    def comment(self):\r
-        return self.body\r
-\r
-    @property\r
-    def headline(self):\r
-        return self.absolute_parent.headline\r
-\r
-    @property\r
-    def content_object(self):\r
-        return self.parent.leaf\r
-\r
-    def save(self, *args, **kwargs):\r
-        super(Comment,self).save(*args, **kwargs)\r
-\r
-        if self._is_new:\r
-            self._update_parent_comment_count(1)\r
-\r
-        try:\r
-            ping_google()\r
-        except Exception:\r
-            logging.debug('problem pinging google did you register you sitemap with google?')\r
-\r
-    def mark_deleted(self, user):\r
-        if super(Comment, self).mark_deleted(user):\r
-            self._update_parent_comment_count(-1)\r
-\r
-    def unmark_deleted(self):\r
-        if super(Comment, self).unmark_deleted():\r
-            self._update_parent_comment_count(1)\r
-\r
-    def is_reply_to(self, user):\r
-        inreply = re.search('@\w+', self.body)\r
-        if inreply is not None:\r
-            return user.username.startswith(inreply.group(0))\r
-\r
-        return False\r
-\r
-    def get_absolute_url(self):\r
-        return self.absolute_parent.get_absolute_url() + "#%d" % self.id\r
-\r
-    def __unicode__(self):\r
-        return self.body\r
-\r
+from base import *
+from django.utils.translation import ugettext as _
+import re
+
+class Comment(Node):
+    friendly_name = _("comment")
+
+    class Meta(Node.Meta):
+        ordering = ('-added_at',)
+        proxy = True
+
+    def _update_parent_comment_count(self, diff):
+        parent = self.parent
+        parent.comment_count = parent.comment_count + diff
+        parent.save()
+
+    @property
+    def comment(self):
+        return self._comment()
+
+    def _comment(self):
+        if settings.FORM_ALLOW_MARKDOWN_IN_COMMENTS:
+            return self.as_markdown('limitedsyntax')
+        else:
+            return self.body
+
+    @property
+    def headline(self):
+        return self.absolute_parent.headline
+
+    @property
+    def content_object(self):
+        return self.parent.leaf
+
+    def save(self, *args, **kwargs):
+        super(Comment,self).save(*args, **kwargs)
+
+        if not self.id:
+            self.parent.reset_comment_count_cache()
+
+    def mark_deleted(self, user):
+        if super(Comment, self).mark_deleted(user):
+            self.parent.reset_comment_count_cache()
+
+    def unmark_deleted(self):
+        if super(Comment, self).unmark_deleted():
+            self.parent.reset_comment_count_cache()
+
+    def is_reply_to(self, user):
+        inreply = re.search('@\w+', self.body)
+        if inreply is not None:
+            return user.username.startswith(inreply.group(0))
+
+        return False
+
+    def get_absolute_url(self):
+        return self.abs_parent.get_absolute_url() + "#%d" % self.id
+
+    def __unicode__(self):
+        return self.body
+