From a3c480248f8dbe649ced86d80b038e80cc77e9cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20P=C3=A9chard?= Date: Sun, 13 Jul 2014 19:01:09 +0200 Subject: [PATCH] Add collection option to 'addmedia' cli uploading --- docs/source/siteadmin/commandline-upload.rst | 1 + mediagoblin/gmg_commands/addmedia.py | 6 ++++++ mediagoblin/submit/lib.py | 11 +++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/source/siteadmin/commandline-upload.rst b/docs/source/siteadmin/commandline-upload.rst index 5ec0bb12..15b2377d 100644 --- a/docs/source/siteadmin/commandline-upload.rst +++ b/docs/source/siteadmin/commandline-upload.rst @@ -31,6 +31,7 @@ Here's a longer example that makes use of more options:: ./bin/gmg addmedia aveyah awesome_spaceship.png \ --title "My awesome spaceship" \ --description "Flying my awesome spaceship, since I'm an awesome pilot" \ + --collection-slug i-m-an-awesome-pilot \ --license "http://creativecommons.org/licenses/by-sa/3.0/" \ --tags "spaceships, pilots, awesome" \ --slug "awesome-spaceship" diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py index c33a8c56..2f095760 100644 --- a/mediagoblin/gmg_commands/addmedia.py +++ b/mediagoblin/gmg_commands/addmedia.py @@ -51,6 +51,11 @@ def parser_setup(subparser): help=( "Slug for this media entry. " "Will be autogenerated if unspecified.")) + subparser.add_argument( + "-c", "--collection-slug", + help=( + "Slug of the collection for this media entry." + "Should already exits.")) subparser.add_argument( '--celery', @@ -94,6 +99,7 @@ def addmedia(args): submitted_file=file(abs_filename, 'r'), filename=filename, title=maybe_unicodeify(args.title), description=maybe_unicodeify(args.description), + collection_slug=args.collection_slug, license=maybe_unicodeify(args.license), tags_string=maybe_unicodeify(args.tags) or u"", upload_limit=upload_limit, max_file_size=max_file_size) diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 93ae7a1f..b23bdf69 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -23,11 +23,12 @@ from werkzeug.datastructures import FileStorage from mediagoblin import mg_globals from mediagoblin.tools.text import convert_to_tag_list_of_dicts -from mediagoblin.db.models import MediaEntry, ProcessingMetaData +from mediagoblin.db.models import Collection, MediaEntry, ProcessingMetaData from mediagoblin.processing import mark_entry_failed from mediagoblin.processing.task import ProcessMedia from mediagoblin.notifications import add_comment_subscription from mediagoblin.media_types import sniff_media +from mediagoblin.user_pages.lib import add_media_to_collection _log = logging.getLogger(__name__) @@ -97,7 +98,7 @@ class UserPastUploadLimit(UploadLimitError): def submit_media(mg_app, user, submitted_file, filename, - title=None, description=None, + title=None, description=None, collection_slug=None, license=None, metadata=None, tags_string=u"", upload_limit=None, max_file_size=None, callback_url=None, @@ -114,6 +115,7 @@ def submit_media(mg_app, user, submitted_file, filename, one on disk being referenced by submitted_file. - title: title for this media entry - description: description for this media entry + - collection_slug: collection for this media entry - license: license for this media entry - tags_string: comma separated string of tags to be associated with this entry @@ -191,6 +193,11 @@ def submit_media(mg_app, user, submitted_file, filename, else: feed_url = None + # add to collection + if collection_slug: + collection = Collection.query.filter_by(slug=collection_slug).first() + add_media_to_collection(collection, entry) + # Pass off to processing # # (... don't change entry after this point to avoid race -- 2.25.1