]> git.openstreetmap.org Git - osqa.git/blob - forum/models/comment.py
ensure the action POST data is retrieved as a string, in some cases dict can be retur...
[osqa.git] / forum / models / comment.py
1 from base import *
2 from django.utils.translation import ugettext as _
3 import re
4
5 class Comment(Node):
6     friendly_name = _("comment")
7
8     class Meta(Node.Meta):
9         ordering = ('-added_at',)
10         proxy = True
11
12     def _update_parent_comment_count(self, diff):
13         parent = self.parent
14         parent.comment_count = parent.comment_count + diff
15         parent.save()
16
17     @property
18     def comment(self):
19         if settings.FORM_ALLOW_MARKDOWN_IN_COMMENTS:
20             # Avoid doing double replacement of backslashes
21             return self._as_markdown_raw(self.body,'limitedsyntax')
22         else:
23             return self.body
24
25     @property
26     def headline(self):
27         return self.absolute_parent.headline
28
29     @property
30     def content_object(self):
31         return self.parent.leaf
32
33     def save(self, *args, **kwargs):
34         super(Comment,self).save(*args, **kwargs)
35
36         if not self.id:
37             self.parent.reset_comment_count_cache()
38
39     def mark_deleted(self, user):
40         if super(Comment, self).mark_deleted(user):
41             self.parent.reset_comment_count_cache()
42
43     def unmark_deleted(self):
44         if super(Comment, self).unmark_deleted():
45             self.parent.reset_comment_count_cache()
46
47     def is_reply_to(self, user):
48         inreply = re.search('@\w+', self.body)
49         if inreply is not None:
50             return user.username.startswith(inreply.group(0))
51
52         return False
53
54     def get_absolute_url(self):
55         return self.abs_parent.get_absolute_url() + "#%d" % self.id
56
57     def __unicode__(self):
58         return self.body
59