Porting the piwigo submit system over to using the new submit utility.
This also adds upload limit checks to the piwigo plugin! This commit sponsored by Sam Black. Thank you!
This commit is contained in:
parent
5d754da741
commit
860b380bb5
@ -16,17 +16,17 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from os.path import splitext
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
from werkzeug.exceptions import MethodNotAllowed, BadRequest, NotImplemented
|
from werkzeug.exceptions import MethodNotAllowed, BadRequest, NotImplemented
|
||||||
from werkzeug.wrappers import BaseResponse
|
from werkzeug.wrappers import BaseResponse
|
||||||
|
|
||||||
|
from mediagoblin.tools.translate import pass_to_ugettext as _
|
||||||
from mediagoblin.meddleware.csrf import csrf_exempt
|
from mediagoblin.meddleware.csrf import csrf_exempt
|
||||||
from mediagoblin.auth.tools import check_login_simple
|
from mediagoblin.auth.tools import check_login_simple
|
||||||
from mediagoblin.media_types import sniff_media
|
from mediagoblin.submit.lib import \
|
||||||
from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
|
submit_media, check_file_field, get_upload_file_limits, \
|
||||||
run_process_media, new_upload_entry
|
FileUploadLimit, UserUploadLimit, UserPastUploadLimit
|
||||||
|
|
||||||
|
|
||||||
from mediagoblin.user_pages.lib import add_media_to_collection
|
from mediagoblin.user_pages.lib import add_media_to_collection
|
||||||
from mediagoblin.db.models import Collection
|
from mediagoblin.db.models import Collection
|
||||||
@ -126,58 +126,39 @@ def pwg_images_addSimple(request):
|
|||||||
if not check_file_field(request, 'image'):
|
if not check_file_field(request, 'image'):
|
||||||
raise BadRequest()
|
raise BadRequest()
|
||||||
|
|
||||||
filename = request.files['image'].filename
|
upload_limit, max_file_size = get_upload_file_limits(request.user)
|
||||||
|
|
||||||
# Sniff the submitted media to determine which
|
try:
|
||||||
# media plugin should handle processing
|
entry = submit_media(
|
||||||
media_type, media_manager = sniff_media(
|
request.app, request.user,
|
||||||
request.files['image'])
|
request.files['image'], request.files['image'].filename,
|
||||||
|
unicode(form.name.data),
|
||||||
|
unicode(form.comment.data),
|
||||||
|
upload_limit, max_file_size)
|
||||||
|
|
||||||
# create entry and save in database
|
collection_id = form.category.data
|
||||||
entry = new_upload_entry(request.user)
|
if collection_id > 0:
|
||||||
entry.media_type = unicode(media_type)
|
collection = Collection.query.get(collection_id)
|
||||||
entry.title = (
|
if collection is not None and collection.creator == request.user.id:
|
||||||
unicode(form.name.data)
|
add_media_to_collection(collection, entry, "")
|
||||||
or unicode(splitext(filename)[0]))
|
|
||||||
|
|
||||||
entry.description = unicode(form.comment.data)
|
return {
|
||||||
|
'image_id': entry.id,
|
||||||
|
'url': entry.url_for_self(
|
||||||
|
request.urlgen,
|
||||||
|
qualified=True)}
|
||||||
|
|
||||||
'''
|
# Handle upload limit issues
|
||||||
# Process the user's folksonomy "tags"
|
except FileUploadLimit:
|
||||||
entry.tags = convert_to_tag_list_of_dicts(
|
raise BadRequest(
|
||||||
form.tags.data)
|
_(u'Sorry, the file size is too big.'))
|
||||||
'''
|
except UserUploadLimit:
|
||||||
|
raise BadRequest(
|
||||||
# Generate a slug from the title
|
_('Sorry, uploading this file will put you over your'
|
||||||
entry.generate_slug()
|
' upload limit.'))
|
||||||
|
except UserPastUploadLimit:
|
||||||
queue_file = prepare_queue_task(request.app, entry, filename)
|
raise BadRequest(
|
||||||
|
_('Sorry, you have reached your upload limit.'))
|
||||||
with queue_file:
|
|
||||||
shutil.copyfileobj(request.files['image'].stream,
|
|
||||||
queue_file,
|
|
||||||
length=4 * 1048576)
|
|
||||||
|
|
||||||
# Save now so we have this data before kicking off processing
|
|
||||||
entry.save()
|
|
||||||
|
|
||||||
# Pass off to processing
|
|
||||||
#
|
|
||||||
# (... don't change entry after this point to avoid race
|
|
||||||
# conditions with changes to the document via processing code)
|
|
||||||
feed_url = request.urlgen(
|
|
||||||
'mediagoblin.user_pages.atom_feed',
|
|
||||||
qualified=True, user=request.user.username)
|
|
||||||
run_process_media(entry, feed_url)
|
|
||||||
|
|
||||||
collection_id = form.category.data
|
|
||||||
if collection_id > 0:
|
|
||||||
collection = Collection.query.get(collection_id)
|
|
||||||
if collection is not None and collection.creator == request.user.id:
|
|
||||||
add_media_to_collection(collection, entry, "")
|
|
||||||
|
|
||||||
return {'image_id': entry.id, 'url': entry.url_for_self(request.urlgen,
|
|
||||||
qualified=True)}
|
|
||||||
|
|
||||||
|
|
||||||
md5sum_matcher = re.compile(r"^[0-9a-fA-F]{32}$")
|
md5sum_matcher = re.compile(r"^[0-9a-fA-F]{32}$")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user