|
@@ -1,11 +1,11 @@
|
|
from django import forms
|
|
from django import forms
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.utils.translation import ugettext_lazy as _
|
|
-from misago.apps.threadtype.mixins import ValidateThreadNameMixin
|
|
|
|
|
|
+from misago.apps.threadtype.mixins import ValidateThreadNameMixin, ValidatePostLengthMixin
|
|
from misago.forms import Form
|
|
from misago.forms import Form
|
|
from misago.validators import validate_sluggable
|
|
from misago.validators import validate_sluggable
|
|
|
|
|
|
-class PostingForm(Form):
|
|
|
|
|
|
+class PostingForm(Form, ValidatePostLengthMixin):
|
|
post = forms.CharField(widget=forms.Textarea)
|
|
post = forms.CharField(widget=forms.Textarea)
|
|
|
|
|
|
def __init__(self, data=None, file=None, request=None, forum=None, thread=None, *args, **kwargs):
|
|
def __init__(self, data=None, file=None, request=None, forum=None, thread=None, *args, **kwargs):
|
|
@@ -13,7 +13,16 @@ class PostingForm(Form):
|
|
self.thread = thread
|
|
self.thread = thread
|
|
super(PostingForm, self).__init__(data, file, request=request, *args, **kwargs)
|
|
super(PostingForm, self).__init__(data, file, request=request, *args, **kwargs)
|
|
|
|
|
|
- def set_extra_fields(self):
|
|
|
|
|
|
+ def finalize_form(self):
|
|
|
|
+ self.layout = [
|
|
|
|
+ [
|
|
|
|
+ None,
|
|
|
|
+ [
|
|
|
|
+ ('post', {'label': _("Post Content")}),
|
|
|
|
+ ]
|
|
|
|
+ ]
|
|
|
|
+ ]
|
|
|
|
+
|
|
# Can we change threads states?
|
|
# Can we change threads states?
|
|
if (self.request.acl.threads.can_pin_threads(self.forum) >= self.thread.weight and
|
|
if (self.request.acl.threads.can_pin_threads(self.forum) >= self.thread.weight and
|
|
self.request.acl.threads.can_pin_threads(self.forum)):
|
|
self.request.acl.threads.can_pin_threads(self.forum)):
|
|
@@ -24,35 +33,37 @@ class PostingForm(Form):
|
|
thread_weight.append((0, _("Standard")))
|
|
thread_weight.append((0, _("Standard")))
|
|
if thread_weight:
|
|
if thread_weight:
|
|
self.layout[0][1].append(('thread_weight', {'label': _("Thread Importance")}))
|
|
self.layout[0][1].append(('thread_weight', {'label': _("Thread Importance")}))
|
|
- self.fields['thread_weight'] = forms.TypedChoiceField(widget=forms.RadioSelect, choices=thread_weight, coerce=int, initial=0)
|
|
|
|
|
|
+ self.fields['thread_weight'] = forms.TypedChoiceField(widget=forms.RadioSelect,
|
|
|
|
+ choices=thread_weight,
|
|
|
|
+ required=False,
|
|
|
|
+ coerce=int,
|
|
|
|
+ initial=(self.thread.weight if self.thread else 0))
|
|
|
|
|
|
# Can we lock threads?
|
|
# Can we lock threads?
|
|
if self.request.acl.threads.can_close(self.forum):
|
|
if self.request.acl.threads.can_close(self.forum):
|
|
self.fields['close_thread'] = forms.BooleanField(required=False)
|
|
self.fields['close_thread'] = forms.BooleanField(required=False)
|
|
if self.thread and self.thread.closed:
|
|
if self.thread and self.thread.closed:
|
|
- self.layout[0][1].append(('close_thread', {'label': 'NOEZ', 'inline': _("Open Thread")}))
|
|
|
|
|
|
+ self.layout[0][1].append(('close_thread', {'inline': _("Open Thread")}))
|
|
else:
|
|
else:
|
|
- self.layout[0][1].append(('close_thread', {'label': 'BALLS', 'inline': _("Close Thread")}))
|
|
|
|
|
|
+ self.layout[0][1].append(('close_thread', {'inline': _("Close Thread")}))
|
|
|
|
+
|
|
|
|
+ def clean_thread_weight(self):
|
|
|
|
+ data = self.cleaned_data['thread_weight']
|
|
|
|
+ if not data:
|
|
|
|
+ if self.thread:
|
|
|
|
+ return self.thread.weight
|
|
|
|
+ return 0
|
|
|
|
+ return data
|
|
|
|
|
|
|
|
|
|
class NewThreadForm(PostingForm, ValidateThreadNameMixin):
|
|
class NewThreadForm(PostingForm, ValidateThreadNameMixin):
|
|
def finalize_form(self):
|
|
def finalize_form(self):
|
|
- self.layout = [
|
|
|
|
- [
|
|
|
|
- None,
|
|
|
|
- [
|
|
|
|
- ('thread_name', {'label': _("Thread Name")}),
|
|
|
|
- ('post', {'label': _("Post Content")}),
|
|
|
|
- ]
|
|
|
|
- ]
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
|
|
+ super(NewThreadForm, self).finalize_form()
|
|
|
|
+ self.layout[0][1].append(('thread_name', {'label': _("Thread Name")}))
|
|
self.fields['thread_name'] = forms.CharField(max_length=self.request.settings['thread_name_max'],
|
|
self.fields['thread_name'] = forms.CharField(max_length=self.request.settings['thread_name_max'],
|
|
validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
|
|
validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
|
|
_("Thread name is too long. Try shorter name."))])
|
|
_("Thread name is too long. Try shorter name."))])
|
|
|
|
|
|
- self.set_extra_fields()
|
|
|
|
-
|
|
|
|
|
|
|
|
class EditThreadForm(NewThreadForm, ValidateThreadNameMixin):
|
|
class EditThreadForm(NewThreadForm, ValidateThreadNameMixin):
|
|
def finalize_form(self):
|
|
def finalize_form(self):
|
|
@@ -60,3 +71,13 @@ class EditThreadForm(NewThreadForm, ValidateThreadNameMixin):
|
|
self.fields['edit_reason'] = forms.CharField(max_length=255, required=False, help_text=_("Optional reason for editing this thread."))
|
|
self.fields['edit_reason'] = forms.CharField(max_length=255, required=False, help_text=_("Optional reason for editing this thread."))
|
|
self.layout[0][1].append(('edit_reason', {'label': _("Edit Reason")}))
|
|
self.layout[0][1].append(('edit_reason', {'label': _("Edit Reason")}))
|
|
|
|
|
|
|
|
+
|
|
|
|
+class NewReplyForm(PostingForm):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class EditReplyForm(PostingForm):
|
|
|
|
+ def finalize_form(self):
|
|
|
|
+ super(EditThreadForm, self).finalize_form()
|
|
|
|
+ self.fields['edit_reason'] = forms.CharField(max_length=255, required=False, help_text=_("Optional reason for editing this reply."))
|
|
|
|
+ self.layout[0][1].append(('edit_reason', {'label': _("Edit Reason")}))
|