forms.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, YesNoSwitch
  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. closed = forms.BooleanField(widget=YesNoSwitch,required=False)
  11. style = forms.CharField(max_length=255,required=False)
  12. template = forms.ChoiceField(choices=(
  13. ('rows', _('One forum per row')),
  14. ('fifty', _('Two forums per row')),
  15. ('thirty', _('Three forums per row')),
  16. ))
  17. layout = (
  18. (
  19. _("Basic Options"),
  20. (
  21. ('parent', {'label': _("Category Parent")}),
  22. ('name', {'label': _("Category Name")}),
  23. ('description', {'label': _("Category Description")}),
  24. ('closed', {'label': _("Closed Category")}),
  25. ),
  26. ),
  27. (
  28. _("Display Options"),
  29. (
  30. ('style', {'label': _("Category Style"), 'help_text': _('You can add custom CSS classess to this category, to change way it looks on board index.')}),
  31. ('template', {'label': _("Category Layout")}),
  32. ),
  33. ),
  34. )
  35. def __init__(self, *args, **kwargs):
  36. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(include_self=True),level_indicator=u'- - ')
  37. super(CategoryForm, self).__init__(*args, **kwargs)
  38. class ForumForm(Form):
  39. parent = False
  40. name = forms.CharField(max_length=255)
  41. description = forms.CharField(widget=forms.Textarea,required=False)
  42. closed = forms.BooleanField(widget=YesNoSwitch,required=False)
  43. style = forms.CharField(max_length=255,required=False)
  44. template = forms.ChoiceField(choices=(
  45. ('rows', _('One forum per row')),
  46. ('fifty', _('Two forums per row')),
  47. ('thirty', _('Three forums per row')),
  48. ))
  49. prune_start = forms.IntegerField(min_value=0,initial=0)
  50. prune_last = forms.IntegerField(min_value=0,initial=0)
  51. layout = (
  52. (
  53. _("Basic Options"),
  54. (
  55. ('parent', {'label': _("Forum Parent")}),
  56. ('name', {'label': _("Forum Name")}),
  57. ('description', {'label': _("Forum Description")}),
  58. ('closed', {'label': _("Closed Forum")}),
  59. ),
  60. ),
  61. (
  62. _("Prune Forum"),
  63. (
  64. ('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.')}),
  65. ('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.')}),
  66. ),
  67. ),
  68. (
  69. _("Display Options"),
  70. (
  71. ('style', {'label': _("Forum Style"), 'help_text': _('You can add custom CSS classess to this forum to change way it looks on forums lists.')}),
  72. ('template', {'label': _("Subforums List Layout")}),
  73. ),
  74. ),
  75. )
  76. def __init__(self, *args, **kwargs):
  77. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  78. super(ForumForm, self).__init__(*args, **kwargs)
  79. class RedirectForm(Form):
  80. parent = False
  81. name = forms.CharField(max_length=255)
  82. description = forms.CharField(widget=forms.Textarea,required=False)
  83. redirect = forms.URLField(max_length=255)
  84. style = forms.CharField(max_length=255,required=False)
  85. layout = (
  86. (
  87. _("Basic Options"),
  88. (
  89. ('parent', {'label': _("Redirect Parent")}),
  90. ('name', {'label': _("Redirect Name")}),
  91. ('redirect', {'label': _("Redirect URL")}),
  92. ('description', {'label': _("Redirect Description")}),
  93. ),
  94. ),
  95. (
  96. _("Display Options"),
  97. (
  98. ('style', {'label': _("Redirect Style"), 'help_text': _('You can add custom CSS classess to this redirect to change way it looks on forums lists.')}),
  99. ),
  100. ),
  101. )
  102. def __init__(self, *args, **kwargs):
  103. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  104. super(RedirectForm, self).__init__(*args, **kwargs)
  105. class DeleteForm(Form):
  106. parent = False
  107. layout = (
  108. (
  109. _("Delete Options"),
  110. (
  111. ('parent', {'label': _("Move deleted Forum contents to")}),
  112. ),
  113. ),
  114. )
  115. def __init__(self, *args, **kwargs):
  116. self.base_fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),required=False,empty_label=_("Remove with forum"),level_indicator=u'- - ')
  117. super(DeleteForm, self).__init__(*args, **kwargs)