1 from django.db import models
2 from django.core.urlresolvers import reverse
3 from django.contrib.auth.models import User
4 from django.utils.text import normalize_newlines
5 from django.utils.translation import ugettext_lazy as _
6 from threadedcomments.models import ThreadedComment
7 from xerxes.tools.text import rewrap
9 # Create your models here.
10 class Character(models.Model):
15 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
16 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
17 name = models.CharField(max_length=255, verbose_name = _("Name"))
18 status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
19 player = models.ForeignKey(User, verbose_name = _("Player"))
24 def get_absolute_url(self):
25 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
28 verbose_name = _("Character")
29 verbose_name_plural = _("Characters")
31 class Influence(models.Model):
34 ('U', _('Under discussion')),
35 ('P', _('Processing')),
38 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
39 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
41 character = models.ForeignKey(Character, verbose_name = _("Character"))
42 contact = models.CharField(max_length=255, verbose_name = _("Contact Name"))
43 summary = models.CharField(max_length=255, verbose_name = _("Summary"))
44 description = models.TextField(verbose_name = _("Description"))
45 status = models.TextField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
46 longterm = models.BooleanField(default=False, verbose_name = _("Long term"))
48 result = models.TextField(blank=True,verbose_name = _("Result"))
53 def get_absolute_url(self):
54 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
56 def get_comments(self, private):
58 Gets the comments that have been made on this Influence. Each
59 comment gets its reply_form attribute set to a Form appropriate
60 for replying to the comment.
62 If private is True, private comments are included in this list.
64 def quote_reply(comment):
65 regex = "^([ >]*)(.*)$"
66 text = rewrap(normalize_newlines(comment.comment), 72, regex)
67 return "\n".join(["> " + l for l in text.split("\n")])
69 # Import here to prevent dependency loop, since forms depends on
71 from forms import get_influence_comment_form
74 comments = ThreadedComment.objects.get_tree(self)
76 comments = ThreadedComment.public.get_tree(self)
78 # Annotate each comment with a proper reply form
79 for comment in comments:
80 initial = { 'comment' : quote_reply(comment) }
81 prefix = "reply-to-%s" % (comment.pk)
82 FormClass = get_influence_comment_form(private, comment)
83 comment.reply_form = FormClass(initial=initial,
88 verbose_name = _("Influence")
89 verbose_name_plural = _("Influences")
91 # vim: set sts=4 sw=4 expandtab: