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',)
26 class AdminPrivateInfluenceCommentForm(ThreadedCommentForm):
27 def __init__(self, *args, **kwargs):
28 super(AdminPrivateInfluenceCommentForm, self).__init__(*args, **kwargs)
29 self.instance.is_public = False
31 def get_influence_comment_form(is_staff, reply_to):
32 """ Gets the form class that a user can use to reply to the given comment.
33 reply_to can be None, in which case the form class for a new comment is
35 allow_markup = allow_private = is_staff
37 allow_public = reply_to.is_public
40 return _get_influence_comment_form(allow_markup, allow_public, allow_private)
42 def _get_influence_comment_form(allow_markup, allow_public, allow_private):
43 """ Internal wrapper that selects the right form class depending on the
44 given options. Should not be called directly, call
45 get_influence_comment_form instead. """
46 if allow_markup and allow_public and allow_private:
47 return AdminInfluenceCommentForm
48 elif allow_markup and not allow_public and allow_private:
49 return AdminPrivateInfluenceCommentForm
50 elif not allow_markup and allow_public and not allow_private:
51 return InfluenceCommentForm
53 raise Exception("Unsupported configuration")
55 class InfluenceForm(ContextModelForm):
58 fields = ('character', 'contact', 'summary', 'description')
60 class CharacterForm(ContextModelForm):