aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/submit/lib.py
diff options
context:
space:
mode:
authorJessica Tallon <jessica@megworld.co.uk>2014-07-28 23:36:39 +0100
committerJessica Tallon <jessica@megworld.co.uk>2014-07-30 21:53:52 +0100
commit5e5d445890c6c555dff48b1613c285da983d71c8 (patch)
tree6c04e0e8f2d455c3ebae77d3b6c65939dc388025 /mediagoblin/submit/lib.py
parent138d934f014d2c9c54e247298318832e88dceadb (diff)
downloadmediagoblin-5e5d445890c6c555dff48b1613c285da983d71c8.tar.lz
mediagoblin-5e5d445890c6c555dff48b1613c285da983d71c8.tar.xz
mediagoblin-5e5d445890c6c555dff48b1613c285da983d71c8.zip
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.
Diffstat (limited to 'mediagoblin/submit/lib.py')
-rw-r--r--mediagoblin/submit/lib.py31
1 files changed, 31 insertions, 0 deletions
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