|
@@ -26,28 +26,17 @@ class SplitThreadForm(Form, ValidateThreadNameMixin):
|
|
|
return new_forum
|
|
|
|
|
|
|
|
|
-class MovePostsForm(Form, ValidateThreadNameMixin):
|
|
|
- error_source = 'thread_url'
|
|
|
-
|
|
|
- def __init__(self, data=None, request=None, thread=None, *args, **kwargs):
|
|
|
- self.thread = thread
|
|
|
- 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."))
|
|
|
-
|
|
|
- def clean_thread_url(self):
|
|
|
+def get_thread_from_url(request, thread_url):
|
|
|
from django.core.urlresolvers import resolve
|
|
|
from django.http import Http404
|
|
|
- thread_url = self.cleaned_data['thread_url']
|
|
|
+
|
|
|
try:
|
|
|
thread_url = thread_url[len(settings.BOARD_ADDRESS):]
|
|
|
match = resolve(thread_url)
|
|
|
- if match.url_name[0:len(self.type_prefix)] != self.type_prefix:
|
|
|
+ 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'])
|
|
|
- self.request.acl.threads.allow_thread_view(self.request.user, thread)
|
|
|
+ request.acl.threads.allow_thread_view(request.user, thread)
|
|
|
if thread.pk == self.thread.pk:
|
|
|
raise forms.ValidationError(_("New thread is same as current one."))
|
|
|
return thread
|
|
@@ -55,3 +44,19 @@ class MovePostsForm(Form, ValidateThreadNameMixin):
|
|
|
raise forms.ValidationError(_("This is not a correct thread URL."))
|
|
|
except (Thread.DoesNotExist, ACLError403, ACLError404):
|
|
|
raise forms.ValidationError(_("Thread could not be found."))
|
|
|
+
|
|
|
+
|
|
|
+class MovePostsForm(Form, ValidateThreadNameMixin):
|
|
|
+ error_source = 'thread_url'
|
|
|
+
|
|
|
+ def __init__(self, data=None, request=None, thread=None, *args, **kwargs):
|
|
|
+ self.thread = thread
|
|
|
+ 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."))
|
|
|
+
|
|
|
+ def clean_thread_url(self):
|
|
|
+ return get_thread_from_url(
|
|
|
+ self.request, self.cleaned_data['thread_url'])
|