]> git.openstreetmap.org Git - osqa.git/blob - forum/models/comment.py
Removing the code that Hernani has removed in Revision 828 again. Somehow after the...
[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             return self.as_markdown('limitedsyntax')
21         else:
22             return self.body
23
24     @property
25     def headline(self):
26         return self.absolute_parent.headline
27
28     @property
29     def content_object(self):
30         return self.parent.leaf
31
32     def save(self, *args, **kwargs):
33         super(Comment,self).save(*args, **kwargs)
34
35         if not self.id:
36             self.parent.reset_comment_count_cache()
37
38     def mark_deleted(self, user):
39         if super(Comment, self).mark_deleted(user):
40             self.parent.reset_comment_count_cache()
41
42     def unmark_deleted(self):
43         if super(Comment, self).unmark_deleted():
44             self.parent.reset_comment_count_cache()
45
46     def is_reply_to(self, user):
47         inreply = re.search('@\w+', self.body)
48         if inreply is not None:
49             return user.username.startswith(inreply.group(0))
50
51         return False
52
53     def get_absolute_url(self):
54         return self.abs_parent.get_absolute_url() + "#%d" % self.id
55
56     def __unicode__(self):
57         return self.body
58