From d37f65663fd43ced8a4886a6e29e4156d0182ff8 Mon Sep 17 00:00:00 2001
From: ayleph <ayleph@thisshitistemp.com>
Date: Wed, 28 Jun 2017 21:49:29 -0700
Subject: [PATCH] Fix #5514 - Add to Collection causes server error
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 | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index 484d27cd9..9556749b9 100644
a
|
b
|
def media_collect(request, media):
|
289 | 289 | collection = None |
290 | 290 | |
291 | 291 | # Make sure the user actually selected a collection |
292 | | item = CollectionItem.query.filter_by(collection=collection.id) |
293 | | item = item.join(CollectionItem.object_helper).filter_by( |
294 | | model_type=media.__tablename__, |
295 | | obj_pk=media.id |
296 | | ).first() |
297 | | |
298 | 292 | if not collection: |
299 | 293 | messages.add_message( |
300 | 294 | request, |
… |
… |
def media_collect(request, media):
|
304 | 298 | user=media.get_actor.username, |
305 | 299 | media_id=media.id) |
306 | 300 | |
| 301 | item = CollectionItem.query.filter_by(collection=collection.id) |
| 302 | item = item.join(CollectionItem.object_helper).filter_by( |
| 303 | model_type=media.__tablename__, |
| 304 | obj_pk=media.id |
| 305 | ).first() |
| 306 | |
307 | 307 | # Check whether media already exists in collection |
308 | | elif item is not None: |
| 308 | if item is not None: |
309 | 309 | messages.add_message( |
310 | 310 | request, |
311 | 311 | messages.ERROR, |