|
@@ -10,13 +10,16 @@ from misago.apps.threadtype.mixins import ValidateThreadNameMixin
|
|
|
|
|
|
class SplitThreadForm(Form, ValidateThreadNameMixin):
|
|
|
def finalize_form(self):
|
|
|
- self.fields['thread_name'] = forms.CharField(label=_("New Thread Name"),
|
|
|
- max_length=settings.thread_name_max,
|
|
|
- validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
|
|
|
- _("Thread name is too long. Try shorter name.")
|
|
|
- )])
|
|
|
- self.fields['thread_forum'] = ForumChoiceField(label=_("New Thread Forum"),
|
|
|
- queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']))
|
|
|
+ self.fields['thread_name'] = forms.CharField(
|
|
|
+ label=_("New Thread Name"),
|
|
|
+ max_length=settings.thread_name_max,
|
|
|
+ validators=[validate_sluggable(
|
|
|
+ _("Thread name must contain at least one alpha-numeric character."),
|
|
|
+ _("Thread name is too long. Try shorter name.")
|
|
|
+ )])
|
|
|
+ self.fields['thread_forum'] = ForumChoiceField(
|
|
|
+ label=_("New Thread Forum"),
|
|
|
+ queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']))
|
|
|
|
|
|
def clean_thread_forum(self):
|
|
|
new_forum = self.cleaned_data['thread_forum']
|
|
@@ -31,11 +34,16 @@ def get_thread_from_url(request, thread_url):
|
|
|
from django.http import Http404
|
|
|
|
|
|
try:
|
|
|
- thread_url = thread_url[len(settings.BOARD_ADDRESS):]
|
|
|
+ if thread_url.startswith(settings.BOARD_ADDRESS):
|
|
|
+ thread_url = thread_url[len(settings.BOARD_ADDRESS):]
|
|
|
+
|
|
|
+ if '#' in thread_url:
|
|
|
+ thread_url = thread_url.split('#')[0]
|
|
|
|
|
|
match = resolve(thread_url)
|
|
|
if not match.url_name.startswith('thread'):
|
|
|
raise forms.ValidationError(_("This is not a correct thread URL."))
|
|
|
+
|
|
|
thread = Thread.objects.get(pk=match.kwargs['thread'])
|
|
|
request.acl.threads.allow_thread_view(request.user, thread)
|
|
|
return thread
|
|
@@ -45,7 +53,7 @@ def get_thread_from_url(request, thread_url):
|
|
|
raise forms.ValidationError(_("Thread could not be found."))
|
|
|
|
|
|
|
|
|
-class MovePostsForm(Form, ValidateThreadNameMixin):
|
|
|
+class MovePostsForm(Form):
|
|
|
error_source = 'thread_url'
|
|
|
|
|
|
def __init__(self, data=None, request=None, thread=None, *args, **kwargs):
|
|
@@ -53,8 +61,9 @@ class MovePostsForm(Form, ValidateThreadNameMixin):
|
|
|
super(MovePostsForm, self).__init__(data, request=request, *args, **kwargs)
|
|
|
|
|
|
def finalize_form(self):
|
|
|
- self.fields['thread_url'] = forms.CharField(label=_("New Thread Link"),
|
|
|
- help_text=_("To select new thread, simply copy and paste here its link."))
|
|
|
+ self.fields['thread_url'] = forms.CharField(
|
|
|
+ label=_("New Thread Link"),
|
|
|
+ help_text=_("To select new thread, simply copy and paste here its link."))
|
|
|
|
|
|
def clean_thread_url(self):
|
|
|
thread = get_thread_from_url(self.request, self.cleaned_data['thread_url'])
|