threads.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. from django import forms
  2. from django.utils.translation import gettext_lazy as _
  3. from .base import ChangeSettingsForm
  4. class ChangeThreadsSettingsForm(ChangeSettingsForm):
  5. settings = [
  6. "attachment_403_image",
  7. "attachment_404_image",
  8. "daily_post_limit",
  9. "hourly_post_limit",
  10. "post_attachments_limit",
  11. "post_length_max",
  12. "post_length_min",
  13. "readtracker_cutoff",
  14. "thread_title_length_max",
  15. "thread_title_length_min",
  16. "unused_attachments_lifetime",
  17. "threads_per_page",
  18. "posts_per_page",
  19. "posts_per_page_orphans",
  20. "events_per_page",
  21. ]
  22. daily_post_limit = forms.IntegerField(
  23. label=_("Daily post limit per user"),
  24. help_text=_(
  25. "Daily limit of posts that may be posted by single user. "
  26. "Fail-safe for situations when forum is flooded by spam bots. "
  27. "Change to 0 to remove the limit."
  28. ),
  29. min_value=0,
  30. )
  31. hourly_post_limit = forms.IntegerField(
  32. label=_("Hourly post limit per user"),
  33. help_text=_(
  34. "Hourly limit of posts that may be posted by single user. "
  35. "Fail-safe for situations when forum is flooded by spam bots. "
  36. "Change to 0 to remove the limit."
  37. ),
  38. min_value=0,
  39. )
  40. post_attachments_limit = forms.IntegerField(
  41. label=_("Maximum number of attachments per post"), min_value=1
  42. )
  43. post_length_max = forms.IntegerField(
  44. label=_("Maximum allowed post length"), min_value=0
  45. )
  46. post_length_min = forms.IntegerField(
  47. label=_("Minimum required post length"), min_value=1
  48. )
  49. thread_title_length_max = forms.IntegerField(
  50. label=_("Maximum allowed thread title length"), min_value=2, max_value=255
  51. )
  52. thread_title_length_min = forms.IntegerField(
  53. label=_("Minimum required thread title length"), min_value=2, max_value=255
  54. )
  55. unused_attachments_lifetime = forms.IntegerField(
  56. label=_("Unused attachments lifetime"),
  57. help_text=_(
  58. "Period of time (in hours) after which user-uploaded files that weren't "
  59. "attached to any post are deleted from disk."
  60. ),
  61. min_value=1,
  62. )
  63. readtracker_cutoff = forms.IntegerField(
  64. label=_("Read-tracker cutoff"),
  65. help_text=_(
  66. "Controls amount of data used by read-tracking system. All content older "
  67. "than number of days specified in this setting is considered old and read, "
  68. "even if the opposite is true for the user. Active forums can try lowering "
  69. "this value while less active ones may wish to increase it instead. "
  70. ),
  71. min_value=1,
  72. )
  73. threads_per_page = forms.IntegerField(
  74. label=_("Number of threads displayed on a single page"), min_value=10
  75. )
  76. posts_per_page = forms.IntegerField(
  77. label=_("Number of posts displayed on a single page"), min_value=5
  78. )
  79. posts_per_page_orphans = forms.IntegerField(
  80. label=_("Maximum orphans"),
  81. help_text=_(
  82. "If number of posts to be displayed on the last page is less or equal to "
  83. "number specified in this setting, those posts will instead be displayed "
  84. "on previous page, reducing the total number of pages in thread."
  85. ),
  86. min_value=0,
  87. )
  88. events_per_page = forms.IntegerField(
  89. label=_("Maximum number of events displayed on a single page"), min_value=5
  90. )
  91. attachment_403_image = forms.ImageField(
  92. label=_("Permission denied"),
  93. help_text=_(
  94. "Attachments proxy will display this image in place of default one "
  95. "when user tries to access attachment they have no permission to see."
  96. ),
  97. required=False,
  98. )
  99. attachment_403_image_delete = forms.BooleanField(
  100. label=_("Delete custom permission denied image"), required=False
  101. )
  102. attachment_404_image = forms.ImageField(
  103. label=_("Not found"),
  104. help_text=_(
  105. "Attachments proxy will display this image in place of default one "
  106. "when user tries to access attachment that doesn't exist."
  107. ),
  108. required=False,
  109. )
  110. attachment_404_image_delete = forms.BooleanField(
  111. label=_("Delete custom not found image"), required=False
  112. )
  113. def clean(self):
  114. cleaned_data = super().clean()
  115. if cleaned_data.get("posts_per_page_orphans") > cleaned_data.get(
  116. "posts_per_page"
  117. ):
  118. self.add_error(
  119. "posts_per_page_orphans",
  120. _("This value must be lower than number of posts per page."),
  121. )
  122. return cleaned_data