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.
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__)
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])
entry.description = unicode(request.form.get('description'))
entry.license = unicode(request.form.get('license', ''))
- entry.uploader = request.user.id
-
entry.generate_slug()
# queue appropriately
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
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)
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(
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
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
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
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)
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)