Fix #5514 - Add to Collection causes server error
authorayleph <ayleph@thisshitistemp.com>
Thu, 29 Jun 2017 04:49:29 +0000 (21:49 -0700)
committerAndrew Browning <ayleph@thisshitistemp.com>
Tue, 15 Aug 2017 06:39:00 +0000 (02:39 -0400)
Re-arrange code to check whether a collection has been selected prior
to checking whether an item already exists in the selected collection.
This fixes a regression introduced in 0f3bf8d.

mediagoblin/user_pages/views.py

index ab235695ef6cbc379548e899909836bcad10d304..b4737ea8fb5e15e4bf948239a6e8aad4f05e5807 100644 (file)
@@ -297,12 +297,6 @@ def media_collect(request, media):
             collection = None
 
     # Make sure the user actually selected a collection
-    item = CollectionItem.query.filter_by(collection=collection.id)
-    item = item.join(CollectionItem.object_helper).filter_by(
-        model_type=media.__tablename__,
-        obj_pk=media.id
-    ).first()
-
     if not collection:
         messages.add_message(
             request,
@@ -312,8 +306,14 @@ def media_collect(request, media):
                     user=media.get_actor.username,
                     media_id=media.id)
 
+    item = CollectionItem.query.filter_by(collection=collection.id)
+    item = item.join(CollectionItem.object_helper).filter_by(
+        model_type=media.__tablename__,
+        obj_pk=media.id
+    ).first()
+
     # Check whether media already exists in collection
-    elif item is not None:
+    if item is not None:
         messages.add_message(
             request,
             messages.ERROR,