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, wrap
5 from django.utils.translation import ugettext_lazy as _
6 from threadedcomments.models import ThreadedComment
8 # Create your models here.
9 class Character(models.Model):
14 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
15 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
16 name = models.CharField(max_length=255, verbose_name = _("Name"))
17 status = models.CharField(max_length=2, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
18 player = models.ForeignKey(User, verbose_name = _("Player"))
23 def get_absolute_url(self):
24 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
27 verbose_name = _("Character")
28 verbose_name_plural = _("Characters")
30 class Influence(models.Model):
33 ('U', _('Under discussion')),
34 ('P', _('Processing')),
37 created = models.DateField(auto_now_add=1, verbose_name = _("Creation time"))
38 modified = models.DateField(auto_now=1, verbose_name = _("Modification time"))
40 character = models.ForeignKey(Character, verbose_name = _("Character"))
41 contact = models.CharField(max_length=255, verbose_name = _("Contact Name"))
42 summary = models.CharField(max_length=255, verbose_name = _("Summary"))
43 description = models.TextField(verbose_name = _("Description"))
44 status = models.TextField(max_length=1, choices=STATUS_CHOICES, default='N', verbose_name = _("Status"))
45 longterm = models.BooleanField(default=False, verbose_name = _("Long term"))
47 result = models.TextField(blank=True,verbose_name = _("Result"))
52 def get_absolute_url(self):
53 return reverse('influences_influence_detail', kwargs={'object_id' : self.pk})
55 def get_comments(self, private):
57 Gets the comments that have been made on this Influence. Each
58 comment gets its reply_form attribute set to a Form appropriate
59 for replying to the comment.
61 If private is True, private comments are included in this list.
63 def quote_reply(comment):
64 text = wrap(normalize_newlines(comment.comment), 72)
65 return "\n".join(["> " + l for l in text.split("\n")])
67 # Import here to prevent dependency loop, since forms depends on
69 from forms import get_influence_comment_form
72 comments = ThreadedComment.objects.get_tree(self)
74 comments = ThreadedComment.public.get_tree(self)
76 # Annotate each comment with a proper reply form
77 for comment in comments:
78 initial = { 'comment' : quote_reply(comment) }
79 prefix = "reply-to-%s" % (comment.pk)
80 FormClass = get_influence_comment_form(private, comment)
81 comment.reply_form = FormClass(initial=initial,
86 verbose_name = _("Influence")
87 verbose_name_plural = _("Influences")
89 # vim: set sts=4 sw=4 expandtab: