forms.py 5.0 KB

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