forms.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. perms = False
  9. name = forms.CharField(max_length=255)
  10. description = forms.CharField(widget=forms.Textarea,required=False)
  11. closed = forms.BooleanField(widget=YesNoSwitch,required=False)
  12. style = forms.CharField(max_length=255,required=False)
  13. template = forms.ChoiceField(choices=(
  14. ('row', _('One forum per row')),
  15. ('half', _('Two forums per row')),
  16. ('quarter', _('Four forums per row')),
  17. ))
  18. layout = (
  19. (
  20. _("Basic Options"),
  21. (
  22. ('parent', {'label': _("Category Parent")}),
  23. ('perms', {'label': _("Copy Permissions from")}),
  24. ('name', {'label': _("Category Name")}),
  25. ('description', {'label': _("Category Description")}),
  26. ('closed', {'label': _("Closed Category")}),
  27. ),
  28. ),
  29. (
  30. _("Display Options"),
  31. (
  32. ('template', {'label': _("Category Layout"), 'help_text': _('Controls how this category is displayed on forums lists.')}),
  33. ('style', {'label': _("Category Style"), 'help_text': _('You can add custom CSS classess to this category, to change way it looks on board index.')}),
  34. ),
  35. ),
  36. )
  37. def finalize_form(self):
  38. self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(include_self=True),level_indicator=u'- - ')
  39. self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ',required=False,empty_label=_("Don't copy permissions"))
  40. class ForumForm(Form):
  41. parent = False
  42. perms = False
  43. name = forms.CharField(max_length=255)
  44. description = forms.CharField(widget=forms.Textarea,required=False)
  45. closed = forms.BooleanField(widget=YesNoSwitch,required=False)
  46. style = forms.CharField(max_length=255,required=False)
  47. prune_start = forms.IntegerField(min_value=0,initial=0)
  48. prune_last = forms.IntegerField(min_value=0,initial=0)
  49. template = forms.ChoiceField(choices=(
  50. ('row', _('One forum per row')),
  51. ('half', _('Two forums per row')),
  52. ('quarter', _('Four forums per row')),
  53. ))
  54. layout = (
  55. (
  56. _("Basic Options"),
  57. (
  58. ('parent', {'label': _("Forum Parent")}),
  59. ('perms', {'label': _("Copy Permissions from")}),
  60. ('name', {'label': _("Forum Name")}),
  61. ('description', {'label': _("Forum Description")}),
  62. ('closed', {'label': _("Closed Forum")}),
  63. ),
  64. ),
  65. (
  66. _("Prune Forum"),
  67. (
  68. ('prune_start', {'label': _("Delete threads with first post older than"), 'help_text': _('Enter number of days since thread start after which thread will be deleted or zero to don\'t delete threads.')}),
  69. ('prune_last', {'label': _("Delete threads with last post older than"), 'help_text': _('Enter number of days since since last reply in thread after which thread will be deleted or zero to don\'t delete threads.')}),
  70. ),
  71. ),
  72. (
  73. _("Display Options"),
  74. (
  75. ('template', {'label': _("Subforums Layout"), 'help_text': _('Controls how this forum displays subforums list.')}),
  76. ('style', {'label': _("Forum Style"), 'help_text': _('You can add custom CSS classess to this forum to change way it looks on forums lists.')}),
  77. ),
  78. ),
  79. )
  80. def finalize_form(self):
  81. self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  82. self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ',required=False,empty_label=_("Don't copy permissions"))
  83. class RedirectForm(Form):
  84. parent = False
  85. perms = False
  86. name = forms.CharField(max_length=255)
  87. description = forms.CharField(widget=forms.Textarea,required=False)
  88. redirect = forms.URLField(max_length=255)
  89. style = forms.CharField(max_length=255,required=False)
  90. layout = (
  91. (
  92. _("Basic Options"),
  93. (
  94. ('parent', {'label': _("Redirect Parent")}),
  95. ('perms', {'label': _("Copy Permissions from")}),
  96. ('name', {'label': _("Redirect Name")}),
  97. ('redirect', {'label': _("Redirect URL")}),
  98. ('description', {'label': _("Redirect Description")}),
  99. ),
  100. ),
  101. (
  102. _("Display Options"),
  103. (
  104. ('style', {'label': _("Redirect Style"), 'help_text': _('You can add custom CSS classess to this redirect to change way it looks on forums lists.')}),
  105. ),
  106. ),
  107. )
  108. def finalize_form(self):
  109. self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ')
  110. self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),level_indicator=u'- - ',required=False,empty_label=_("Don't copy permissions"))
  111. class DeleteForm(Form):
  112. parent = False
  113. layout = (
  114. (
  115. _("Delete Options"),
  116. (
  117. ('parent', {'label': _("Move deleted Forum contents to")}),
  118. ),
  119. ),
  120. )
  121. def finalize_form(self):
  122. self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(),required=False,empty_label=_("Remove with forum"),level_indicator=u'- - ')