At this point, I am very close to done with this code! I made one big change at
[mediagoblin: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 = [(_(u'takeaway'),_(u'Take away privilege')),
21     (_(u'userban'),_(u'Ban the user')),
22     (_(u'sendmessage'),(u'Send the user a message')),
23     (_(u'delete'),_(u'Delete the content'))]
24
25 class MultiCheckboxField(wtforms.SelectMultipleField):
26     """
27     A multiple-select, except displays a list of checkboxes.
28
29     Iterating the field will produce subfields, allowing custom rendering of
30     the enclosed checkbox fields.
31
32     code from http://wtforms.simplecodes.com/docs/1.0.4/specific_problems.html
33     """
34     widget = wtforms.widgets.ListWidget(prefix_label=False)
35     option_widget = wtforms.widgets.CheckboxInput()
36
37
38 # ============ Forms for mediagoblin.moderation.user page ==================  #
39
40 class PrivilegeAddRemoveForm(wtforms.Form):
41     """
42     This form is used by an admin to give/take away a privilege directly from
43         their user page.
44     """
45     privilege_name = wtforms.HiddenField('',[wtforms.validators.required()])
46
47 class BanForm(wtforms.Form):
48     """
49     This form is used by an admin to ban a user directly from their user page.
50     """
51     user_banned_until = wtforms.DateField(
52         _(u'User will be banned until:'),
53         format='%Y-%m-%d',
54         validators=[wtforms.validators.optional()])
55     why_user_was_banned = wtforms.TextAreaField(
56         _(u'Why are you banning this User?'),
57         validators=[wtforms.validators.optional()])
58
59 # =========== Forms for mediagoblin.moderation.report page =================  #
60
61 class ReportResolutionForm(wtforms.Form):
62     """
63     This form carries all the information necessary to take punitive actions
64         against a user who created content that has been reported.
65
66         :param  action_to_resolve       A list of Unicode objects representing
67                                         a choice from the ACTION_CHOICES const-
68                                         -ant. Every choice passed affects what
69                                         punitive actions will be taken against
70                                         the user.
71
72         :param targeted_user            A HiddenField object that holds the id
73                                         of the user that was reported.
74
75         :param take_away_privileges     A list of Unicode objects which repres-
76                                         -ent the privileges that are being tak-
77                                         -en away. This field is optional and
78                                         only relevant if u'takeaway' is in the
79                                         `action_to_resolve` list.
80
81         :param user_banned_until        A DateField object that holds the date
82                                         that the user will be unbanned. This
83                                         field is optional and only relevant if
84                                         u'userban' is in the action_to_resolve
85                                         list. If the user is being banned and
86                                         this field is blank, the user is banned
87                                         indefinitely.
88
89          :param why_user_was_banned     A TextArea object that holds the
90                                         reason that a user was banned, to disp-
91                                         -lay to them when they try to log in.
92                                         This field is optional and only relevant
93                                         if u'userban' is in the
94                                         `action_to_resolve` list.
95
96         :param message_to_user          A TextArea object that holds a message
97                                         which will be emailed to the user. This
98                                         is only relevant if the u'sendmessage'
99                                         option is in the `action_to_resolve`
100                                         list.
101
102         :param resolution_content       A TextArea object that is required for
103                                         every report filed. It represents the
104                                         reasons that the moderator/admin resol-
105                                         -ved the report in such a way.
106     """
107     action_to_resolve = MultiCheckboxField(
108         _(u'What action will you take to resolve the report?'),
109         validators=[wtforms.validators.optional()],
110         choices=ACTION_CHOICES)
111     targeted_user   = wtforms.HiddenField('',
112         validators=[wtforms.validators.required()])
113     take_away_privileges = wtforms.SelectMultipleField(
114         _(u'What privileges will you take away?'),
115         validators=[wtforms.validators.optional()])
116     user_banned_until = wtforms.DateField(
117         _(u'User will be banned until:'),
118         format='%Y-%m-%d',
119         validators=[wtforms.validators.optional()])
120     why_user_was_banned = wtforms.TextAreaField(
121         validators=[wtforms.validators.optional()])
122     message_to_user = wtforms.TextAreaField(
123         validators=[wtforms.validators.optional()])
124     resolution_content = wtforms.TextAreaField()
125
126 # ======== Forms for mediagoblin.moderation.report_panel page ==============  #
127
128 class ReportPanelSortingForm(wtforms.Form):
129     """
130     This form is used for sorting and filtering through different reports in
131     the mediagoblin.moderation.reports_panel view.
132
133     """
134     active_p = wtforms.IntegerField(
135         validators=[wtforms.validators.optional()])
136     closed_p = wtforms.IntegerField(
137         validators=[wtforms.validators.optional()])
138     reported_user = wtforms.IntegerField(
139         validators=[wtforms.validators.optional()])
140     reporter = wtforms.IntegerField(
141         validators=[wtforms.validators.optional()])
142
143 class UserPanelSortingForm(wtforms.Form):
144     """
145     This form is used for sorting different reports.
146     """
147     p = wtforms.IntegerField(
148         validators=[wtforms.validators.optional()])