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