From 48145f82486305fba7fd667aef865166a644e2f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sun, 8 Oct 2017 18:19:08 +0200
Subject: [PATCH] Handle collection in batchaddmedia command

Make the batchaddmedia command look for a 'collection-slug' column, that
for each row may specify the slug of a collection that the media should
be added to. This matches the '--collection-slug' argument of the
addmedia command.
---
 docs/source/siteadmin/commandline-upload.rst | 1 +
 mediagoblin/gmg_commands/batchaddmedia.py    | 7 +++----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/source/siteadmin/commandline-upload.rst b/docs/source/siteadmin/commandline-upload.rst
index ef597a44..086854ce 100644
--- a/docs/source/siteadmin/commandline-upload.rst
+++ b/docs/source/siteadmin/commandline-upload.rst
@@ -87,6 +87,7 @@ just as easy to provide this information through the correct metadata columns.
 - **license** is used to set a license for your piece a media for MediaGoblin's use. This must be a URI.
 - **title** will set the title displayed to MediaGoblin users.
 - **description** will set a description of your media.
+- **collection-slug** will add the media to a collection, if a collection with the given slug exists.
 
 Metadata columns
 ----------------
diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py
index 274d72bc..a521fe4d 100644
--- a/mediagoblin/gmg_commands/batchaddmedia.py
+++ b/mediagoblin/gmg_commands/batchaddmedia.py
@@ -28,8 +28,7 @@ from six.moves.urllib.parse import urlparse
 from mediagoblin.db.models import LocalUser
 from mediagoblin.gmg_commands import util as commands_util
 from mediagoblin.submit.lib import (
-    submit_media, get_upload_file_limits,
-    FileUploadLimit, UserUploadLimit, UserPastUploadLimit)
+    submit_media, FileUploadLimit, UserUploadLimit, UserPastUploadLimit)
 from mediagoblin.tools.metadata import compact_and_validate
 from mediagoblin.tools.translate import pass_to_ugettext as _
 from jsonschema.exceptions import ValidationError
@@ -73,8 +72,6 @@ def batchaddmedia(args):
                     username=args.username)))
         return
 
-    temp_files = []
-
     if os.path.isfile(args.metadata_path):
         metadata_path = args.metadata_path
 
@@ -113,6 +110,7 @@ def batchaddmedia(args):
         title = file_metadata.get('title') or file_metadata.get('dc:title')
         description = (file_metadata.get('description') or
             file_metadata.get('dc:description'))
+        collection_slug = file_metadata.get('collection-slug')
 
         license = file_metadata.get('license')
         try:
@@ -155,6 +153,7 @@ FAIL: Local file {filename} could not be accessed.
                 filename=filename,
                 title=maybe_unicodeify(title),
                 description=maybe_unicodeify(description),
+                collection_slug=maybe_unicodeify(collection_slug),
                 license=maybe_unicodeify(license),
                 metadata=json_ld_metadata,
                 tags_string=u"")
-- 
2.14.2

