Browse Source

fix move posts form, bump ver to 0.5.6

Rafał Pitoń 9 years ago
parent
commit
70d4b4e9c0

+ 1 - 0
.gitignore

@@ -148,6 +148,7 @@ var
 sdist
 develop-eggs
 .installed.cfg
+venv
 
 # Installer logs
 pip-log.txt

+ 1 - 1
misago/__init__.py

@@ -1 +1 @@
-__version__ = "0.5.5"
+__version__ = "0.5.6"

+ 20 - 15
misago/apps/threadtype/thread/moderation/forms.py

@@ -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'])

+ 0 - 1
misago/tests/__init__.py

@@ -1 +0,0 @@
-from misago.tests.user_manager_create_user import UserManagerCreateUserTestCase

+ 0 - 0
misago/tests/user_manager_create_user.py → misago/tests/test_user_manager_create_user.py