1 from threadedcomments.forms import ThreadedCommentForm
2 from xerxes.tools.forms import ContextModelForm
3 from models import Influence, Character
6 # A few comment form classes, to handle the various cases (staff/no staff,
7 # reply to public/private post)
9 # It is probably possible to reduce this mess a bit using metaclasses, but I
10 # didn't get this to work yet.
12 class InfluenceCommentForm(ThreadedCommentForm):
13 def __init__(self, *args, **kwargs):
14 super(InfluenceCommentForm, self).__init__(*args, **kwargs)
16 class Meta(ThreadedCommentForm.Meta):
17 exclude = ('markup', )
19 class AdminInfluenceCommentForm(ThreadedCommentForm):
20 def __init__(self, *args, **kwargs):
21 super(AdminInfluenceCommentForm, self).__init__(*args, **kwargs)
23 class Meta(ThreadedCommentForm.Meta):
24 fields = ThreadedCommentForm.Meta.fields + ('is_public',)
25 exclude = ('markup', )
27 class AdminPrivateInfluenceCommentForm(ThreadedCommentForm):
28 def __init__(self, *args, **kwargs):
29 super(AdminPrivateInfluenceCommentForm, self).__init__(*args, **kwargs)
30 self.instance.is_public = False
32 class Meta(ThreadedCommentForm.Meta):
33 exclude = ('markup', )
35 def get_influence_comment_form(is_staff, reply_to):
36 """ Gets the form class that a user can use to reply to the given comment.
37 reply_to can be None, in which case the form class for a new comment is
40 allow_private = is_staff
42 allow_public = reply_to.is_public
45 return _get_influence_comment_form(allow_markup, allow_public, allow_private)
47 def _get_influence_comment_form(allow_markup, allow_public, allow_private):
48 """ Internal wrapper that selects the right form class depending on the
49 given options. Should not be called directly, call
50 get_influence_comment_form instead. """
51 if not allow_markup and allow_public and allow_private:
52 return AdminInfluenceCommentForm
53 elif not allow_markup and not allow_public and allow_private:
54 return AdminPrivateInfluenceCommentForm
55 elif not allow_markup and allow_public and not allow_private:
56 return InfluenceCommentForm
58 raise Exception("Unsupported configuration")
60 class InfluenceForm(ContextModelForm):
63 fields = ('character', 'contact', 'summary', 'description')
65 class CharacterForm(ContextModelForm):