Fix trivial spelling error in test comment
[mediagoblin.git] / mediagoblin / moderation / forms.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import wtforms
18 from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
19
20 ACTION_CHOICES = [
21 (u'takeaway', _(u'Take away privilege')),
22 (u'userban', _(u'Ban the user')),
23 (u'sendmessage', _(u'Send the user a message')),
24 (u'delete', _(u'Delete the content'))]
25
26 class MultiCheckboxField(wtforms.SelectMultipleField):
27 """
28 A multiple-select, except displays a list of checkboxes.
29
30 Iterating the field will produce subfields, allowing custom rendering of
31 the enclosed checkbox fields.
32
33 code from http://wtforms.simplecodes.com/docs/1.0.4/specific_problems.html
34 """
35 widget = wtforms.widgets.ListWidget(prefix_label=False)
36 option_widget = wtforms.widgets.CheckboxInput()
37
38
39 # ============ Forms for mediagoblin.moderation.user page ================== #
40
41 class PrivilegeAddRemoveForm(wtforms.Form):
42 """
43 This form is used by an admin to give/take away a privilege directly from
44 their user page.
45 """
46 privilege_name = wtforms.HiddenField('',[wtforms.validators.required()])
47
48 class BanForm(wtforms.Form):
49 """
50 This form is used by an admin to ban a user directly from their user page.
51 """
52 user_banned_until = wtforms.DateField(
53 _(u'User will be banned until:'),
54 format='%Y-%m-%d',
55 validators=[wtforms.validators.optional()])
56 why_user_was_banned = wtforms.TextAreaField(
57 _(u'Why are you banning this User?'),
58 validators=[wtforms.validators.optional()])
59
60 # =========== Forms for mediagoblin.moderation.report page ================= #
61
62 class ReportResolutionForm(wtforms.Form):
63 """
64 This form carries all the information necessary to take punitive actions
65 against a user who created content that has been reported.
66
67 :param action_to_resolve A list of Unicode objects representing
68 a choice from the ACTION_CHOICES const-
69 -ant. Every choice passed affects what
70 punitive actions will be taken against
71 the user.
72
73 :param targeted_user A HiddenField object that holds the id
74 of the user that was reported.
75
76 :param take_away_privileges A list of Unicode objects which repres-
77 -ent the privileges that are being tak-
78 -en away. This field is optional and
79 only relevant if u'takeaway' is in the
80 `action_to_resolve` list.
81
82 :param user_banned_until A DateField object that holds the date
83 that the user will be unbanned. This
84 field is optional and only relevant if
85 u'userban' is in the action_to_resolve
86 list. If the user is being banned and
87 this field is blank, the user is banned
88 indefinitely.
89
90 :param why_user_was_banned A TextArea object that holds the
91 reason that a user was banned, to disp-
92 -lay to them when they try to log in.
93 This field is optional and only relevant
94 if u'userban' is in the
95 `action_to_resolve` list.
96
97 :param message_to_user A TextArea object that holds a message
98 which will be emailed to the user. This
99 is only relevant if the u'sendmessage'
100 option is in the `action_to_resolve`
101 list.
102
103 :param resolution_content A TextArea object that is required for
104 every report filed. It represents the
105 reasons that the moderator/admin resol-
106 -ved the report in such a way.
107 """
108 action_to_resolve = MultiCheckboxField(
109 _(u'What action will you take to resolve the report?'),
110 validators=[wtforms.validators.optional()],
111 choices=ACTION_CHOICES)
112 targeted_user = wtforms.HiddenField('',
113 validators=[wtforms.validators.required()])
114 take_away_privileges = wtforms.SelectMultipleField(
115 _(u'What privileges will you take away?'),
116 validators=[wtforms.validators.optional()])
117 user_banned_until = wtforms.DateField(
118 _(u'User will be banned until:'),
119 format='%Y-%m-%d',
120 validators=[wtforms.validators.optional()])
121 why_user_was_banned = wtforms.TextAreaField(
122 _(u'Why user was banned:'),
123 validators=[wtforms.validators.optional()])
124 message_to_user = wtforms.TextAreaField(
125 _(u'Message to user:'),
126 validators=[wtforms.validators.optional()])
127 resolution_content = wtforms.TextAreaField(
128 _(u'Resolution content:'))
129
130 # ======== Forms for mediagoblin.moderation.report_panel page ============== #
131
132 class ReportPanelSortingForm(wtforms.Form):
133 """
134 This form is used for sorting and filtering through different reports in
135 the mediagoblin.moderation.reports_panel view.
136
137 """
138 active_p = wtforms.IntegerField(
139 validators=[wtforms.validators.optional()])
140 closed_p = wtforms.IntegerField(
141 validators=[wtforms.validators.optional()])
142 reported_user = wtforms.IntegerField(
143 validators=[wtforms.validators.optional()])
144 reporter = wtforms.IntegerField(
145 validators=[wtforms.validators.optional()])
146
147 class UserPanelSortingForm(wtforms.Form):
148 """
149 This form is used for sorting different reports.
150 """
151 p = wtforms.IntegerField(
152 validators=[wtforms.validators.optional()])