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')),
39 ('I', _('Influence')),
40 ('N', _('Notifcation')),
42 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
43 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
45 type = models.CharField(max_length=1, choices=TYPE_CHOICES, default='I', verbose_name = _("Type"))
46 character = models.ForeignKey(Character, verbose_name = _("Character"))
47 contact = models.CharField(max_length=255, verbose_name = _("Contact Name"))
48 summary = models.CharField(max_length=255, verbose_name = _("Summary"))
49 description = models.TextField(verbose_name = _("Description"))
50 todo = models.TextField(blank=True, verbose_name = _("Todo"))
51 status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
52 longterm = models.BooleanField(default=False, verbose_name = _("Long term"))
54 result = models.TextField(blank=True,verbose_name = _("Result"))
56 def __unicode__(self):
59 def get_absolute_url(self):
60 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
62 def get_comments(self, private):
64 Gets the comments that have been made on this Influence. Each
65 comment gets its reply_form attribute set to a Form appropriate
66 for replying to the comment.
68 If private is True, private comments are included in this list.
70 def quote_reply(comment):
71 regex = "^([ >]*)(.*)$"
72 text = rewrap(normalize_newlines(comment.comment), 72, regex)
73 return "\n".join(["> " + l for l in text.split("\n")])
75 # Import here to prevent dependency loop, since forms depends on
77 from forms import get_influence_comment_form
80 comments = ThreadedComment.objects.get_tree(self)
82 comments = ThreadedComment.public.get_tree(self)
84 # Annotate each comment with a proper reply form
85 for comment in comments:
86 initial = { 'comment' : quote_reply(comment) }
87 prefix = "reply-to-%s" % (comment.pk)
88 FormClass = get_influence_comment_form(private, comment)
89 comment.reply_form = FormClass(initial=initial,
94 verbose_name = _("Influence")
95 verbose_name_plural = _("Influences")
97 # vim: set sts=4 sw=4 expandtab: