moderation.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from django.utils.translation import ugettext_lazy as _
  2. from misago.core import forms
  3. from misago.forums.forms import ForumChoiceField
  4. from misago.threads.validators import validate_title
  5. class MergeThreadsForm(forms.Form):
  6. merged_thread_title = forms.CharField(label=_("Merged thread title"),
  7. required=False)
  8. def clean(self):
  9. data = super(MergeThreadsForm, self).clean()
  10. merged_thread_title = data.get('merged_thread_title')
  11. if merged_thread_title:
  12. validate_title(merged_thread_title)
  13. else:
  14. message = _("You have to enter merged thread title.")
  15. raise forms.ValidationError(message)
  16. return data
  17. class MoveThreadsForm(forms.Form):
  18. new_forum = ForumChoiceField(label=_("Move threads to forum"),
  19. empty_label=None)
  20. def __init__(self, *args, **kwargs):
  21. self.forum = kwargs.pop('forum')
  22. acl = kwargs.pop('acl')
  23. super(MoveThreadsForm, self).__init__(*args, **kwargs)
  24. self.fields['new_forum'].set_acl(acl)
  25. def clean(self):
  26. data = super(MoveThreadsForm, self).clean()
  27. new_forum = data.get('new_forum')
  28. if new_forum:
  29. if new_forum.is_category:
  30. message = _("You can't move threads to category.")
  31. raise forms.ValidationError(message)
  32. if new_forum.is_redirect:
  33. message = _("You can't move threads to redirect.")
  34. raise forms.ValidationError(message)
  35. if new_forum.pk == self.forum.pk:
  36. message = _("New forum is same as current one.")
  37. raise forms.ValidationError(message)
  38. else:
  39. raise forms.ValidationError(_("You have to select forum."))
  40. return data
  41. class MoveThreadForm(MoveThreadsForm):
  42. new_forum = ForumChoiceField(label=_("Move thread to forum"),
  43. empty_label=None)