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