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"))
21 def __unicode__(self):
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 todo = models.TextField(blank=True, verbose_name = _("Todo"))
46 status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
47 longterm = models.BooleanField(default=False, verbose_name = _("Long term"))
49 result = models.TextField(blank=True,verbose_name = _("Result"))
51 def __unicode__(self):
54 def get_absolute_url(self):
55 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
57 def get_comments(self, private):
59 Gets the comments that have been made on this Influence. Each
60 comment gets its reply_form attribute set to a Form appropriate
61 for replying to the comment.
63 If private is True, private comments are included in this list.
65 def quote_reply(comment):
66 regex = "^([ >]*)(.*)$"
67 text = rewrap(normalize_newlines(comment.comment), 72, regex)
68 return "\n".join(["> " + l for l in text.split("\n")])
70 # Import here to prevent dependency loop, since forms depends on
72 from forms import get_influence_comment_form
75 comments = ThreadedComment.objects.get_tree(self)
77 comments = ThreadedComment.public.get_tree(self)
79 # Annotate each comment with a proper reply form
80 for comment in comments:
81 initial = { 'comment' : quote_reply(comment) }
82 prefix = "reply-to-%s" % (comment.pk)
83 FormClass = get_influence_comment_form(private, comment)
84 comment.reply_form = FormClass(initial=initial,
89 verbose_name = _("Influence")
90 verbose_name_plural = _("Influences")
92 # vim: set sts=4 sw=4 expandtab: