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):
20 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
21 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
22 name = models.CharField(max_length=255, verbose_name = _("Name"))
23 status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
24 player = models.ForeignKey(User, verbose_name = _("Player"))
25 contacts = models.ManyToManyField('self')
26 type = models.CharField(max_length=2, choices=TYPE_CHOICES, verbose_name=_("Type"))
28 def __unicode__(self):
31 def get_absolute_url(self):
32 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
35 verbose_name = _("Character")
36 verbose_name_plural = _("Characters")
38 class Influence(models.Model):
41 ('U', _('Under discussion')),
42 ('P', _('Processing')),
45 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
46 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
48 initiator = models.ForeignKey(Character, verbose_name = _("Initiator"), related_name='initiated_influences')
49 other_contacts = models.CharField(max_length=255, blank = True, verbose_name = _("Other Contacts"))
50 other_characters = models.ManyToManyField(Character, blank = True, verbose_name = _("Involved characters"), related_name='influences_involved_in')
51 summary = models.CharField(max_length=255, verbose_name = _("Summary"))
52 description = models.TextField(verbose_name = _("Description"))
53 todo = models.TextField(verbose_name = _("Todo"))
54 status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
55 longterm = models.BooleanField(default=False, verbose_name = _("Long term"))
57 result = models.TextField(blank=True,verbose_name = _("Result"))
59 def __unicode__(self):
62 def get_absolute_url(self):
63 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
65 def get_comments(self, private):
67 Gets the comments that have been made on this Influence. Each
68 comment gets its reply_form attribute set to a Form appropriate
69 for replying to the comment.
71 If private is True, private comments are included in this list.
73 def quote_reply(comment):
74 regex = "^([ >]*)(.*)$"
75 text = rewrap(normalize_newlines(comment.comment), 72, regex)
76 return "\n".join(["> " + l for l in text.split("\n")])
78 # Import here to prevent dependency loop, since forms depends on
80 from forms import get_influence_comment_form
83 comments = ThreadedComment.objects.get_tree(self)
85 comments = ThreadedComment.public.get_tree(self)
87 # Annotate each comment with a proper reply form
88 for comment in comments:
89 initial = { 'comment' : quote_reply(comment) }
90 prefix = "reply-to-%s" % (comment.pk)
91 FormClass = get_influence_comment_form(private, comment)
92 comment.reply_form = FormClass(initial=initial,
97 verbose_name = _("Influence")
98 verbose_name_plural = _("Influences")
100 # vim: set sts=4 sw=4 expandtab: