655: Fix collection fetching for media_collect()
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 10 Mar 2013 19:56:48 +0000 (20:56 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 10 Mar 2013 20:19:16 +0000 (21:19 +0100)
The problem is:

    Collection.query.filter_by(id=X, ...)

1. X = form.collection.data
   This works nicely for the completely empty form (X = None).
   It does not work for a selected collection, because X
   will be the collection, not its id.

2. X = request.form.get('collection') (old code).
   This one works mostly, except for the completely empty
   form on postgres, because in this case X = u"__None" and
   postgres does not like comparing an integer column with
   a string.

Fix:
    collection = form.collection.data
    if collection and collection.creator != request.user.id:
        collection = None

mediagoblin/user_pages/views.py

index dc562084a3eb6c7a881c2087b8e86384c4c77e8c..c611daa103f073bbbcdada58ab580a100321b21e 100644 (file)
@@ -226,9 +226,9 @@ def media_collect(request, media):
 
     # Otherwise, use the collection selected from the drop-down
     else:
-        collection = Collection.query.filter_by(
-            id=form.collection.data,
-            creator=request.user.id).first()
+        collection = form.collection.data
+        if collection and collection.creator != request.user.id:
+            collection = None
 
     # Make sure the user actually selected a collection
     if not collection: