Rafał Pitoń 10 лет назад
Родитель
Сommit
22f091c304

+ 15 - 8
misago/threads/forms/reply.py → misago/threads/forms/posting.py

@@ -118,16 +118,23 @@ class ThreadPrefixFormBase(forms.Form):
     legend = _("Prefix")
     legend = _("Prefix")
     template = "misago/posting/threadprefixform.html"
     template = "misago/posting/threadprefixform.html"
 
 
-    prefix = forms.TypedChoiceField(label=_("Thread weight"), initial=0,
-                                    choices=(
-                                        (0, _("Standard")),
-                                        (1, _("Pinned")),
-                                        (2, _("Announcement")),
-                                    ))
-
 
 
 def ThreadPrefixForm(*args, **kwargs):
 def ThreadPrefixForm(*args, **kwargs):
-    return ThreadPrefixFormBase(*args, **kwargs)
+    prefixes = kwargs.pop('prefixes')
+
+    choices = [(0, _("No prefix"))]
+    choices.extend([(prefix.pk, prefix.name ) for prefix in prefixes])
+
+    field = forms.TypedChoiceField(
+        label=_("Thread prefix"),
+        coerce=int,
+        choices=choices)
+
+    FormType = type("ThreadPrefixFormFinal",
+                    (ThreadPrefixFormBase,),
+                    {'prefix': field})
+
+    return FormType(*args, **kwargs)
 
 
 
 
 class ThreadWeightForm(forms.Form):
 class ThreadWeightForm(forms.Form):

+ 1 - 1
misago/threads/posting/reply.py

@@ -1,7 +1,7 @@
 from misago.markup import Editor
 from misago.markup import Editor
 
 
 from misago.threads.checksums import update_post_checksum
 from misago.threads.checksums import update_post_checksum
-from misago.threads.forms.reply import ReplyForm, ThreadForm
+from misago.threads.forms.posting import ReplyForm, ThreadForm
 from misago.threads.posting import PostingMiddleware, START, REPLY, EDIT
 from misago.threads.posting import PostingMiddleware, START, REPLY, EDIT
 
 
 
 

+ 1 - 1
misago/threads/posting/threadclose.py

@@ -1,4 +1,4 @@
-from misago.threads.forms.reply import ThreadCloseForm
+from misago.threads.forms.posting import ThreadCloseForm
 from misago.threads.posting import PostingMiddleware
 from misago.threads.posting import PostingMiddleware
 
 
 
 

+ 13 - 6
misago/threads/posting/threadprefix.py

@@ -1,10 +1,10 @@
-from misago.threads.forms.reply import ThreadPrefixForm
+from misago.threads.forms.posting import ThreadPrefixForm
 from misago.threads.posting import PostingMiddleware
 from misago.threads.posting import PostingMiddleware
 
 
 
 
 class ThreadPrefixFormMiddleware(PostingMiddleware):
 class ThreadPrefixFormMiddleware(PostingMiddleware):
     def use_this_middleware(self):
     def use_this_middleware(self):
-        if self.forum.acl['can_change_threads_weight'] and self.forum.prefixes:
+        if self.forum.acl['can_change_threads_prefix'] and self.forum.prefixes:
             self.thread_prefix_id = self.thread.prefix_id
             self.thread_prefix_id = self.thread.prefix_id
             return True
             return True
         else:
         else:
@@ -12,12 +12,19 @@ class ThreadPrefixFormMiddleware(PostingMiddleware):
 
 
     def make_form(self):
     def make_form(self):
         if self.request.method == 'POST':
         if self.request.method == 'POST':
-            return ThreadPrefixForm(self.request.POST, prefix=self.prefix)
+            return ThreadPrefixForm(self.request.POST, prefix=self.prefix,
+                                    prefixes=self.forum.prefixes)
         else:
         else:
             initial = {'prefix_id': self.thread_prefix_id}
             initial = {'prefix_id': self.thread_prefix_id}
-            return ThreadPrefixForm(prefix=self.prefix, initial=initial)
+            return ThreadPrefixForm(prefix=self.prefix,
+                                    prefixes=self.forum.prefixes,
+                                    initial=initial)
 
 
     def pre_save(self, form):
     def pre_save(self, form):
         if self.thread_prefix_id != form.cleaned_data.get('prefix'):
         if self.thread_prefix_id != form.cleaned_data.get('prefix'):
-            self.thread.prefix_id = form.cleaned_data.get('prefix')
-            self.thread.update_fields.append('prefix')
+            if form.cleaned_data.get('prefix'):
+                self.thread.prefix_id = form.cleaned_data.get('prefix')
+                self.thread.update_fields.append('prefix')
+            else:
+                self.thread.prefix = None
+                self.thread.update_fields.append('prefix')

+ 1 - 1
misago/threads/posting/threadweight.py

@@ -1,4 +1,4 @@
-from misago.threads.forms.reply import ThreadWeightForm
+from misago.threads.forms.posting import ThreadWeightForm
 from misago.threads.posting import PostingMiddleware
 from misago.threads.posting import PostingMiddleware