Refactor submit util new_upload_entry
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 20 May 2013 22:28:37 +0000 (00:28 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 20 May 2013 22:28:37 +0000 (00:28 +0200)
This tool creates an initial media entry for a given user.
No magic. It just prefills the license with the user's
default license and adds the user as uploader.

mediagoblin/plugins/api/views.py
mediagoblin/plugins/piwigo/views.py
mediagoblin/submit/lib.py
mediagoblin/submit/views.py

index fde76fe432140796ca0f88d46e5ffd3da77ed8b3..9159fe65bf0a580b1869fa30ce8e67c7edec5704 100644 (file)
@@ -27,7 +27,7 @@ from mediagoblin.media_types import sniff_media
 from mediagoblin.plugins.api.tools import api_auth, get_entry_serializable, \
         json_response
 from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
-    run_process_media
+    run_process_media, new_upload_entry
 
 _log = logging.getLogger(__name__)
 
@@ -53,7 +53,7 @@ def post_entry(request):
 
     media_type, media_manager = sniff_media(media_file)
 
-    entry = request.db.MediaEntry()
+    entry = new_upload_entry(request.user)
     entry.media_type = unicode(media_type)
     entry.title = unicode(request.form.get('title')
             or splitext(media_file.filename)[0])
@@ -61,8 +61,6 @@ def post_entry(request):
     entry.description = unicode(request.form.get('description'))
     entry.license = unicode(request.form.get('license', ''))
 
-    entry.uploader = request.user.id
-
     entry.generate_slug()
 
     # queue appropriately
index 1c655bf5053bcf633a6920deb86b7f1affb3d665..bd6b101298d8436b0f74ffe7957a97662f69ad2b 100644 (file)
@@ -26,7 +26,7 @@ from mediagoblin.meddleware.csrf import csrf_exempt
 from mediagoblin.auth.lib import fake_login_attempt
 from mediagoblin.media_types import sniff_media
 from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
-    run_process_media
+    run_process_media, new_upload_entry
 
 from .tools import CmdTable, response_xml, check_form, \
     PWGSession, PwgNamedArray, PwgError
@@ -124,7 +124,7 @@ def pwg_images_addSimple(request):
         request.files['image'])
 
     # create entry and save in database
-    entry = request.db.MediaEntry()
+    entry = new_upload_entry(request.user)
     entry.media_type = unicode(media_type)
     entry.title = (
         unicode(form.name.data)
@@ -132,10 +132,6 @@ def pwg_images_addSimple(request):
 
     entry.description = unicode(form.comment.data)
 
-    # entry.license = unicode(form.license.data) or None
-
-    entry.uploader = request.user.id
-
     '''
     # Process the user's folksonomy "tags"
     entry.tags = convert_to_tag_list_of_dicts(
index 7c3b8ab35433240451d4804f25dfcf258b2795fa..7e85696bed4fc68d82304229ba2e421553987527 100644 (file)
@@ -19,6 +19,7 @@ import uuid
 from werkzeug.utils import secure_filename
 from werkzeug.datastructures import FileStorage
 
+from mediagoblin.db.models import MediaEntry
 from mediagoblin.processing import mark_entry_failed
 from mediagoblin.processing.task import process_media
 
@@ -36,6 +37,16 @@ def check_file_field(request, field_name):
     return retval
 
 
+def new_upload_entry(user):
+    """
+    Create a new MediaEntry for uploading
+    """
+    entry = MediaEntry()
+    entry.uploader = user.id
+    entry.license = user.license_preference
+    return entry
+
+
 def prepare_queue_task(app, entry, filename):
     """
     Prepare a MediaEntry for the processing queue and get a queue file
index e964ec126a2ff5630516af39ae2e4340122950e3..a70c89b4f608bf6db14732670cda24edbaf51fdc 100644 (file)
@@ -32,7 +32,7 @@ from mediagoblin.messages import add_message, SUCCESS
 from mediagoblin.media_types import sniff_media, \
     InvalidFileType, FileTypeNotSupported
 from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
-    run_process_media
+    run_process_media, new_upload_entry
 
 
 @require_active_login
@@ -57,7 +57,7 @@ def submit_start(request):
                     request.files['file'])
 
                 # create entry and save in database
-                entry = request.db.MediaEntry()
+                entry = new_upload_entry(request.user)
                 entry.media_type = unicode(media_type)
                 entry.title = (
                     unicode(submit_form.title.data)
@@ -67,8 +67,6 @@ def submit_start(request):
 
                 entry.license = unicode(submit_form.license.data) or None
 
-                entry.uploader = request.user.id
-
                 # Process the user's folksonomy "tags"
                 entry.tags = convert_to_tag_list_of_dicts(
                     submit_form.tags.data)