moderation.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from django.utils.translation import ugettext_lazy as _
  2. from misago.core import forms
  3. from misago.forums.forms import ForumChoiceField
  4. class MoveThreadsForm(forms.Form):
  5. new_forum = ForumChoiceField(label=_("Move threads to forum"),
  6. empty_label=None)
  7. def __init__(self, *args, **kwargs):
  8. self.forum = kwargs.pop('forum')
  9. acl = kwargs.pop('acl')
  10. super(MoveThreadsForm, self).__init__(*args, **kwargs)
  11. self.fields['new_forum'].set_acl(acl)
  12. def clean(self):
  13. data = super(MoveThreadsForm, self).clean()
  14. new_forum = data.get('new_forum')
  15. if new_forum:
  16. if new_forum.is_category:
  17. message = _("You can't move threads to category.")
  18. raise forms.ValidationError(message)
  19. if new_forum.is_redirect:
  20. message = _("You can't move threads to redirect.")
  21. raise forms.ValidationError(message)
  22. if new_forum.pk == self.forum.pk:
  23. message = _("New forum is same as current one.")
  24. raise forms.ValidationError(message)
  25. else:
  26. raise forms.ValidationError(_("You have to select forum."))
  27. return data