Browse Source

#411 make it possible to interrupt posting presave

Rafał Pitoń 10 years ago
parent
commit
9c91df647f
2 changed files with 15 additions and 3 deletions
  1. 7 0
      misago/threads/forms/posting.py
  2. 8 3
      misago/threads/views/generic.py

+ 7 - 0
misago/threads/forms/posting.py

@@ -13,6 +13,13 @@ REPLY = 1
 EDIT = 2
 EDIT = 2
 
 
 
 
+class InterruptChanges(Exception):
+    def __init__(self, message):
+        if not message:
+            raise ValueError("You have to provide InterruptChanges message.")
+        self.message = message
+
+
 class EditorFormset(object):
 class EditorFormset(object):
     """
     """
     This is gigantozaurus that handles entire posting process
     This is gigantozaurus that handles entire posting process

+ 8 - 3
misago/threads/views/generic.py

@@ -1,6 +1,7 @@
 """
 """
 Module with basic views for use by inheriting actions
 Module with basic views for use by inheriting actions
 """
 """
+from django.contrib import messages
 from django.db.transaction import atomic
 from django.db.transaction import atomic
 from django.shortcuts import redirect, render
 from django.shortcuts import redirect, render
 from django.views.generic import View
 from django.views.generic import View
@@ -11,7 +12,8 @@ from misago.forums.lists import get_forums_list, get_forum_path
 from misago.forums.models import Forum
 from misago.forums.models import Forum
 from misago.forums.permissions import allow_see_forum, allow_browse_forum
 from misago.forums.permissions import allow_see_forum, allow_browse_forum
 
 
-from misago.threads.forms.posting import EditorFormset, START, REPLY, EDIT
+from misago.threads.forms.posting import (InterruptChanges, EditorFormset,
+                                          START, REPLY, EDIT)
 from misago.threads.models import Thread, Post
 from misago.threads.models import Thread, Post
 from misago.threads.permissions import allow_see_thread, allow_start_thread
 from misago.threads.permissions import allow_see_thread, allow_start_thread
 
 
@@ -197,8 +199,11 @@ class EditorView(ViewBase):
 
 
         if request.method == 'POST':
         if request.method == 'POST':
             if 'submit' in request.POST and formset.is_valid():
             if 'submit' in request.POST and formset.is_valid():
-                formset.save()
-                return redirect('misago:index')
+                try:
+                    formset.save()
+                    return redirect('misago:index')
+                except InterruptChanges as e:
+                    messages.error(request, e.message)
             else:
             else:
                 formset.update()
                 formset.update()