X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/32c46c35fc9dbf3305dc774b144ff5af5176c9de..7fb43328b198f5b5dc7f829b2facf9e25704e8e6:/forum/models/comment.py?ds=sidebyside diff --git a/forum/models/comment.py b/forum/models/comment.py index a2e7425..45c5962 100644 --- a/forum/models/comment.py +++ b/forum/models/comment.py @@ -1,57 +1,58 @@ -from base import * -import re - -class Comment(Node): - 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.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 self._is_new: - self._update_parent_comment_count(1) - - try: - ping_google() - except Exception: - logging.debug('problem pinging google did you register your sitemap with google?') - - def mark_deleted(self, user): - if super(Comment, self).mark_deleted(user): - self._update_parent_comment_count(-1) - - def unmark_deleted(self): - if super(Comment, self).unmark_deleted(): - self._update_parent_comment_count(1) - - 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.absolute_parent.get_absolute_url() + "#%d" % self.id - - def __unicode__(self): - return self.body - +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): + 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 +