Browse Source

Fixes in posting actions

Ralfp 12 years ago
parent
commit
810650bd5c

+ 13 - 7
misago/apps/threadtype/posting/base.py

@@ -45,13 +45,19 @@ class PostingBaseView(ViewBase):
 
     def notify_users(self):
         try:
-            if self.quote and self.quote.user_id:
-                del self.md.mentions[self.quote.user.username_slug]
-        except KeyError:
-            pass
-        if self.md.mentions:
-            self.post.notify_mentioned(self.request, self.type_prefix, self.md.mentions)
-            self.post.save(force_update=True)
+            post_content = self.md
+        except AttributeError:
+            post_content = False
+
+        if post_content:
+            try:
+                if self.quote and self.quote.user_id:
+                    del post_content.mentions[self.quote.user.username_slug]
+            except KeyError:
+                pass
+            if post_content.mentions:
+                self.post.notify_mentioned(self.request, self.type_prefix, post_content.mentions)
+                self.post.save(force_update=True)
 
     def watch_thread(self):
         if self.request.user.subscribe_start:

+ 5 - 0
misago/apps/threadtype/posting/editreply.py

@@ -26,6 +26,9 @@ class EditReplyBaseView(PostingBaseView):
         changed_thread = False
         changed_post = old_post != form.cleaned_data['post']
 
+        if self.thread.last_post_id == self.post.pk:
+            self.thread.last_post == self.post
+
         if 'close_thread' in form.cleaned_data and form.cleaned_data['close_thread']:
             self.thread.closed = not self.thread.closed
             changed_thread = True
@@ -33,6 +36,8 @@ class EditReplyBaseView(PostingBaseView):
                 self.thread.last_post.set_checkpoint(self.request, 'closed')
             else:
                 self.thread.last_post.set_checkpoint(self.request, 'opened')
+            if self.thread.last_post_id != self.post.pk or not changed_post:
+                self.thread.last_post.save(force_update=True)
 
         if ('thread_weight' in form.cleaned_data and
                 form.cleaned_data['thread_weight'] != self.thread.weight):

+ 5 - 0
misago/apps/threadtype/posting/editthread.py

@@ -29,6 +29,9 @@ class EditThreadBaseView(PostingBaseView):
         changed_thread = old_name != form.cleaned_data['thread_name']
         changed_post = old_post != form.cleaned_data['post']
 
+        if self.thread.last_post_id == self.post.pk:
+            self.thread.last_post == self.post
+
         if 'close_thread' in form.cleaned_data and form.cleaned_data['close_thread']:
             self.thread.closed = not self.thread.closed
             changed_thread = True
@@ -36,6 +39,8 @@ class EditThreadBaseView(PostingBaseView):
                 self.thread.last_post.set_checkpoint(self.request, 'closed')
             else:
                 self.thread.last_post.set_checkpoint(self.request, 'opened')
+            if self.thread.last_post_id != self.post.pk or not changed_post:
+                self.thread.last_post.save(force_update=True)
 
         if ('thread_weight' in form.cleaned_data and
                 form.cleaned_data['thread_weight'] != self.thread.weight):

+ 16 - 9
misago/apps/threadtype/posting/newreply.py

@@ -38,7 +38,7 @@ class NewReplyBaseView(PostingBaseView):
         moderation = (not self.request.acl.threads.acl[self.forum.pk]['can_approve']
                       and self.request.acl.threads.acl[self.forum.pk]['can_start_threads'] == 1)
 
-        self.thread.previous_last = self.thread.last
+        self.thread.previous_last = self.thread.last_post
         self.md, post_preparsed = post_markdown(self.request, form.cleaned_data['post'])
 
         # Count merge diff and see if we are merging
@@ -85,12 +85,6 @@ class NewReplyBaseView(PostingBaseView):
             if self.thread.last_poster_id != self.request.user.pk:
                 self.thread.score += self.request.settings['thread_ranking_reply_score']
 
-        # Set thread status
-        if 'close_thread' in form.cleaned_data:
-            self.thread.closed = not self.thread.closed
-        if 'thread_weight' in form.cleaned_data:
-            self.thread.weight = form.cleaned_data['thread_weight']
-
         # Save updated thread
         self.thread.save(force_update=True)
 
@@ -113,17 +107,30 @@ class NewReplyBaseView(PostingBaseView):
         self.request.user.last_post = now
         self.request.user.save(force_update=True)
 
+        # Set thread weight
+        if 'thread_weight' in form.cleaned_data:
+            self.thread.weight = form.cleaned_data['thread_weight']
+
         # Set "closed" checkpoint, either due to thread limit or posters wish
         if (self.request.settings.thread_length > 0
                 and not merged and not moderation and not self.thread.closed
                 and self.thread.replies >= self.request.settings.thread_length):
             self.thread.closed = True
             self.post.set_checkpoint(self.request, 'limit')
+            self.post.save(force_update=True)
+            self.thread.save(force_update=True)
         elif 'close_thread' in form.cleaned_data and form.cleaned_data['close_thread']:
+            self.thread.closed = not self.thread.closed
+            if merged:
+                checkpoint_post = self.post
+            else:
+                checkpoint_post = self.thread.previous_last
             if self.thread.closed:
-                self.thread.last_post.set_checkpoint(self.request, 'closed')
+                checkpoint_post.set_checkpoint(self.request, 'closed')
             else:
-                self.thread.last_post.set_checkpoint(self.request, 'opened')
+                checkpoint_post.set_checkpoint(self.request, 'opened')
+            checkpoint_post.save(force_update=True)
+            self.thread.save(force_update=True)
 
         # Notify user we quoted?
         if (self.quote and self.quote.user_id and not merged

+ 1 - 1
misago/models/threadmodel.py

@@ -152,7 +152,7 @@ class Thread(models.Model):
         from misago.acl.exceptions import ACLError403, ACLError404
         from misago.models import ThreadRead, WatchedThread
 
-        for watch in WatchedThread.objects.filter(thread=self).filter(email=True).filter(last_read__gte=self.previous_last):
+        for watch in WatchedThread.objects.filter(thread=self).filter(email=True).filter(last_read__gte=self.previous_last.date):
             user = watch.user
             if user.pk != request.user.pk:
                 try: