Show a message when a thread is re-added to the same message
authorMagnus Hagander <magnus@hagander.net>
Wed, 4 Feb 2015 20:08:32 +0000 (21:08 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 4 Feb 2015 20:08:32 +0000 (21:08 +0100)
pgcommitfest/commitfest/ajax.py
pgcommitfest/commitfest/static/commitfest/js/commitfest.js

index d1d8bcbd147c28d1a8cc530ad4802c2b9ddb0a83..f489d12b554f09bf9ac9a4b17b474d09e614ffcc 100644 (file)
@@ -86,10 +86,7 @@ def attachThread(request):
        patch = get_object_or_404(Patch, pk=int(request.POST['p']), commitfests=cf)
        msgid = request.POST['msg']
 
-       if doAttachThread(cf, patch, msgid, request.user):
-               return 'OK'
-       else:
-               raise Exception("Something happened that cannot happen")
+       return doAttachThread(cf, patch, msgid, request.user)
 
 def doAttachThread(cf, patch, msgid, user):
        # Note! Must be called in an open transaction!
@@ -101,8 +98,7 @@ def doAttachThread(cf, patch, msgid, user):
        if len(threads):
                thread = threads[0]
                if thread.patches.filter(id=patch.id).exists():
-                       # We have everything, so claim we're done.
-                       return True
+                       return 'This thread is already added to this email'
 
                # We did not exist, so we'd better add ourselves.
                # While at it, we update the thread entry with the latest data from the
@@ -135,7 +131,7 @@ def doAttachThread(cf, patch, msgid, user):
        patch.set_modified()
        patch.save()
 
-       return True
+       return 'OK'
 
 @transaction.commit_on_success
 def detachThread(request):
index ca49f6183c0c8fd61be2bba41222911cafc01d25..f1797ffd9fb554ea63ea0fff5663cd9f055d0299 100644 (file)
@@ -98,6 +98,9 @@ function doAttachThread(cfid, patchid, msgid, reloadonsuccess) {
       'p': patchid,
       'msg': msgid,
    }).success(function(data) {
+      if (data != 'OK') {
+         alert(data);
+      }
       if (reloadonsuccess)
          location.reload();
       return true;