forms.py 6.7 KB

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