forms.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from django.utils.translation import ugettext_lazy as _
  2. from django import forms
  3. from mptt.forms import TreeNodeChoiceField
  4. from misago.forms import Form
  5. from misago.forums.models import Forum
  6. class CategoryForm(Form):
  7. parent = False
  8. name = forms.CharField(max_length=255)
  9. description = forms.CharField(widget=forms.Textarea,required=False)
  10. template = forms.ChoiceField(choices=(
  11. ('rows', _('One forum per row')),
  12. ('fifty', _('Two forums per row')),
  13. ('thirty', _('Three forums per row')),
  14. ))
  15. layout = (
  16. (
  17. _("Category Options"),
  18. (
  19. ('parent', {'label': _("Category Parent")}),
  20. ('name', {'label': _("Category Name")}),
  21. ('description', {'label': _("Category Description")}),
  22. ('template', {'label': _("Category Layout")}),
  23. ),
  24. ),
  25. )
  26. def __init__(self, *args, **kwargs):
  27. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(include_self=True),level_indicator=u'- - ')
  28. super(CategoryForm, self).__init__(*args, **kwargs)
  29. class ForumForm(Form):
  30. parent = False
  31. name = forms.CharField(max_length=255)
  32. description = forms.CharField(widget=forms.Textarea,required=False)
  33. template = forms.ChoiceField(choices=(
  34. ('rows', _('One forum per row')),
  35. ('fifty', _('Two forums per row')),
  36. ('thirty', _('Three forums per row')),
  37. ))
  38. prune_start = forms.IntegerField(min_value=0,initial=0)
  39. prune_last = forms.IntegerField(min_value=0,initial=0)
  40. layout = (
  41. (
  42. _("Forum Options"),
  43. (
  44. ('parent', {'label': _("Forum Parent")}),
  45. ('name', {'label': _("Forum Name")}),
  46. ('description', {'label': _("Forum Description")}),
  47. ('template', {'label': _("Subforums Layout")}),
  48. ),
  49. ),
  50. (
  51. _("Prune Forum"),
  52. (
  53. ('prune_start', {'label': _("Delete threads with first post older than"), 'help_text': _('Enter number of days since topic start after which topic will be deleted or zero to don\'t delete topics.')}),
  54. ('prune_last', {'label': _("Delete threads with last post older than"), 'help_text': _('Enter number of days since since last reply in topic after which topic will be deleted or zero to don\'t delete topics.')}),
  55. ),
  56. ),
  57. )
  58. def __init__(self, *args, **kwargs):
  59. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  60. super(ForumForm, self).__init__(*args, **kwargs)
  61. class RedirectForm(Form):
  62. parent = False
  63. name = forms.CharField(max_length=255)
  64. description = forms.CharField(widget=forms.Textarea,required=False)
  65. redirect = forms.URLField(max_length=255)
  66. layout = (
  67. (
  68. _("Redirect Options"),
  69. (
  70. ('parent', {'label': _("Redirect Parent")}),
  71. ('name', {'label': _("Redirect Name")}),
  72. ('redirect', {'label': _("Redirect URL")}),
  73. ('description', {'label': _("Redirect Description")}),
  74. ),
  75. ),
  76. )
  77. def __init__(self, *args, **kwargs):
  78. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  79. super(RedirectForm, self).__init__(*args, **kwargs)
  80. class DeleteForm(Form):
  81. parent = False
  82. layout = (
  83. (
  84. _("Delete Options"),
  85. (
  86. ('parent', {'label': _("Move deleted Forum contents to")}),
  87. ),
  88. ),
  89. )
  90. def __init__(self, *args, **kwargs):
  91. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),required=False,empty_label=_("Remove with forum"),level_indicator=u'- - ')
  92. super(DeleteForm, self).__init__(*args, **kwargs)