Merge branch 'master' of gitorious.org:mediagoblin/mediagoblin
This commit is contained in:
commit
047d8d5871
@ -18,7 +18,6 @@ import json
|
||||
import logging
|
||||
|
||||
from os.path import splitext
|
||||
from werkzeug.datastructures import FileStorage
|
||||
from werkzeug.exceptions import BadRequest, Forbidden
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
@ -27,7 +26,8 @@ from mediagoblin.meddleware.csrf import csrf_exempt
|
||||
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 prepare_queue_task, run_process_media
|
||||
from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
|
||||
run_process_media
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
@ -45,9 +45,7 @@ def post_entry(request):
|
||||
_log.debug('Must POST against post_entry')
|
||||
raise BadRequest()
|
||||
|
||||
if not 'file' in request.files \
|
||||
or not isinstance(request.files['file'], FileStorage) \
|
||||
or not request.files['file'].stream:
|
||||
if not check_file_field(request, 'file'):
|
||||
_log.debug('File field not found')
|
||||
raise BadRequest()
|
||||
|
||||
|
28
mediagoblin/plugins/piwigo/forms.py
Normal file
28
mediagoblin/plugins/piwigo/forms.py
Normal file
@ -0,0 +1,28 @@
|
||||
# GNU MediaGoblin -- federated, autonomous media hosting
|
||||
# Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import wtforms
|
||||
|
||||
|
||||
class AddSimpleForm(wtforms.Form):
|
||||
image = wtforms.FileField()
|
||||
name = wtforms.TextField(
|
||||
validators=[wtforms.validators.Length(min=0, max=500)])
|
||||
comment = wtforms.TextField()
|
||||
# tags = wtforms.FieldList(wtforms.TextField())
|
||||
category = wtforms.IntegerField()
|
||||
level = wtforms.IntegerField()
|
@ -24,6 +24,7 @@ from mediagoblin import mg_globals
|
||||
from mediagoblin.meddleware.csrf import csrf_exempt
|
||||
from mediagoblin.tools.response import render_404
|
||||
from .tools import CmdTable, PwgNamedArray, response_xml
|
||||
from .forms import AddSimpleForm
|
||||
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
@ -45,7 +46,7 @@ def pwg_logout(request):
|
||||
|
||||
@CmdTable("pwg.getVersion")
|
||||
def pwg_getversion(request):
|
||||
return "piwigo 2.5.0 (MediaGoblin)"
|
||||
return "2.5.0 (MediaGoblin)"
|
||||
|
||||
|
||||
@CmdTable("pwg.session.getStatus")
|
||||
@ -80,6 +81,20 @@ def pwg_images_exist(request):
|
||||
return {}
|
||||
|
||||
|
||||
@CmdTable("pwg.images.addSimple", True)
|
||||
def pwg_images_addSimple(request):
|
||||
form = AddSimpleForm(request.form)
|
||||
if not form.validate():
|
||||
_log.error("addSimple: form failed")
|
||||
raise BadRequest()
|
||||
dump = []
|
||||
for f in form:
|
||||
dump.append("%s=%r" % (f.name, f.data))
|
||||
_log.info("addimple: %r %s %r", request.form, " ".join(dump), request.files)
|
||||
|
||||
return {'image_id': 123456, 'url': ''}
|
||||
|
||||
|
||||
md5sum_matcher = re.compile(r"^[0-9a-fA-F]{32}$")
|
||||
|
||||
def fetch_md5(request, parm_name, optional_parm=False):
|
||||
|
@ -17,6 +17,7 @@
|
||||
import logging
|
||||
import uuid
|
||||
from werkzeug.utils import secure_filename
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from mediagoblin.processing import mark_entry_failed
|
||||
from mediagoblin.processing.task import process_media
|
||||
@ -25,6 +26,16 @@ from mediagoblin.processing.task import process_media
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def check_file_field(request, field_name):
|
||||
"""Check if a file field meets minimal criteria"""
|
||||
retval = (field_name in request.files
|
||||
and isinstance(request.files[field_name], FileStorage)
|
||||
and request.files[field_name].stream)
|
||||
if not retval:
|
||||
_log.debug("Form did not contain proper file field %s", field_name)
|
||||
return retval
|
||||
|
||||
|
||||
def prepare_queue_task(app, entry, filename):
|
||||
"""
|
||||
Prepare a MediaEntry for the processing queue and get a queue file
|
||||
|
@ -22,7 +22,6 @@ import logging
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from mediagoblin.tools.text import convert_to_tag_list_of_dicts
|
||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
||||
@ -32,7 +31,8 @@ from mediagoblin.submit import forms as submit_forms
|
||||
from mediagoblin.messages import add_message, SUCCESS
|
||||
from mediagoblin.media_types import sniff_media, \
|
||||
InvalidFileType, FileTypeNotSupported
|
||||
from mediagoblin.submit.lib import run_process_media, prepare_queue_task
|
||||
from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
|
||||
run_process_media
|
||||
|
||||
|
||||
@require_active_login
|
||||
@ -44,9 +44,7 @@ def submit_start(request):
|
||||
license=request.user.license_preference)
|
||||
|
||||
if request.method == 'POST' and submit_form.validate():
|
||||
if not ('file' in request.files
|
||||
and isinstance(request.files['file'], FileStorage)
|
||||
and request.files['file'].stream):
|
||||
if not check_file_field(request, 'file'):
|
||||
submit_form.file.errors.append(
|
||||
_(u'You must provide a file.'))
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user