From 45f426ddee9900439c086a8bb3d1cfaedf3eca6f Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Mon, 21 Apr 2014 12:07:33 -0400 Subject: Made it possible to submit media with the metadata provided --- mediagoblin/submit/lib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index c70e2731..df3f7b62 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -98,7 +98,7 @@ class UserPastUploadLimit(UploadLimitError): def submit_media(mg_app, user, submitted_file, filename, title=None, description=None, - license=None, tags_string=u"", + license=None, metadata=None, tags_string=u"", upload_limit=None, max_file_size=None, callback_url=None, # If provided we'll do the feed_url update, otherwise ignore @@ -142,6 +142,8 @@ def submit_media(mg_app, user, submitted_file, filename, entry.license = license or None + entry.media_metadata = metadata or u"" + # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts(tags_string) -- cgit v1.2.3 From 2daf8ec00043a4cc5cd120f875a5382aca6ec7f9 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Wed, 14 May 2014 12:34:13 -0400 Subject: Fixed a small error relating to the default value of media_metadata --- mediagoblin/submit/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index df3f7b62..93ae7a1f 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -142,7 +142,7 @@ def submit_media(mg_app, user, submitted_file, filename, entry.license = license or None - entry.media_metadata = metadata or u"" + entry.media_metadata = metadata or {} # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts(tags_string) -- cgit v1.2.3 From 0742e11dff487e1af27652fcf63f7d53322018cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Le=20Ninan?= Date: Mon, 9 Jun 2014 15:14:23 +0200 Subject: Fixes #899 : DeprecationWarning about Required going away in WTForms 3.0. Replaced Required with InputRequired. --- mediagoblin/submit/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py index e2264645..6c0e8e9c 100644 --- a/mediagoblin/submit/forms.py +++ b/mediagoblin/submit/forms.py @@ -59,7 +59,7 @@ def get_submit_start_form(form, **kwargs): class AddCollectionForm(wtforms.Form): title = wtforms.TextField( _('Title'), - [wtforms.validators.Length(min=0, max=500), wtforms.validators.Required()]) + [wtforms.validators.Length(min=0, max=500), wtforms.validators.InputRequired()]) description = wtforms.TextAreaField( _('Description of this collection'), description=_("""You can use -- cgit v1.2.3 From 5e5d445890c6c555dff48b1613c285da983d71c8 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 28 Jul 2014 23:36:39 +0100 Subject: Fix #927 - Clean up federation code after Elrond's review - Add json_error and use inplace of json_response where appropriate. - Add garbage_collection to config spec file. - Fix bugs in both garbage collection task and test - Handle /api/whoami when no user logged in and a test for such a case. - Validate ID is correct and user has comment privilege to comment. --- mediagoblin/submit/lib.py | 31 +++++++++++++++++++++++++++++++ mediagoblin/submit/task.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 mediagoblin/submit/task.py (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 93ae7a1f..327ebbd8 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage from mediagoblin import mg_globals +from mediagoblin.tools.response import json_response from mediagoblin.tools.text import convert_to_tag_list_of_dicts from mediagoblin.db.models import MediaEntry, ProcessingMetaData from mediagoblin.processing import mark_entry_failed @@ -259,3 +260,33 @@ def run_process_media(entry, feed_url=None, mark_entry_failed(entry.id, exc) # re-raise the exception raise + + +def api_upload_request(request, file_data, entry): + """ This handles a image upload request """ + # Use the same kind of method from mediagoblin/submit/views:submit_start + entry.title = file_data.filename + entry.generate_slug() + + queue_file = prepare_queue_task(request.app, entry, file_data.filename) + with queue_file: + queue_file.write(request.data) + + entry.save() + return json_response(entry.serialize(request)) + +def api_add_to_feed(request, entry): + """ Add media to Feed """ + if entry.title: + # Shame we have to do this here but we didn't have the data in + # api_upload_request as no filename is usually specified. + entry.slug = None + entry.generate_slug() + + feed_url = request.urlgen( + 'mediagoblin.user_pages.atom_feed', + qualified=True, user=request.user.username) + + run_process_media(entry, feed_url) + add_comment_subscription(request.user, entry) + return json_response(entry.serialize(request)) \ No newline at end of file diff --git a/mediagoblin/submit/task.py b/mediagoblin/submit/task.py new file mode 100755 index 00000000..4ebde502 --- /dev/null +++ b/mediagoblin/submit/task.py @@ -0,0 +1,38 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import celery +import datetime +import pytz + +from mediagoblin.db.models import MediaEntry + +@celery.task() +def collect_garbage(): + """ + Garbage collection to clean up media + + This will look for all critera on models to clean + up. This is primerally written to clean up media that's + entered a erroneous state. + """ + cuttoff = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=1) + + garbage = MediaEntry.query.filter(MediaEntry.created < cuttoff) + garbage = garbage.filter(MediaEntry.state == "unprocessed") + + for entry in garbage.all(): + entry.delete() -- cgit v1.2.3 From 9246a6ba89ab22a07e06b673e9eb0f135d2079a6 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 5 Aug 2014 22:04:50 +0100 Subject: Tidy up federation code and add tests to cover more of the APIs --- mediagoblin/submit/lib.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mediagoblin/submit') diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 327ebbd8..aaa90ea0 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -266,7 +266,9 @@ def api_upload_request(request, file_data, entry): """ This handles a image upload request """ # Use the same kind of method from mediagoblin/submit/views:submit_start entry.title = file_data.filename - entry.generate_slug() + + # This will be set later but currently we just don't have enough information + entry.slug = None queue_file = prepare_queue_task(request.app, entry, file_data.filename) with queue_file: @@ -278,15 +280,13 @@ def api_upload_request(request, file_data, entry): def api_add_to_feed(request, entry): """ Add media to Feed """ if entry.title: - # Shame we have to do this here but we didn't have the data in - # api_upload_request as no filename is usually specified. - entry.slug = None entry.generate_slug() feed_url = request.urlgen( 'mediagoblin.user_pages.atom_feed', - qualified=True, user=request.user.username) + qualified=True, user=request.user.username + ) run_process_media(entry, feed_url) add_comment_subscription(request.user, entry) - return json_response(entry.serialize(request)) \ No newline at end of file + return json_response(entry.serialize(request)) -- cgit v1.2.3