forms.py 7.4 KB

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