Пример #1
0
def upload_async(request, media_type='image'):
    """Upload images or videos from request.FILES."""
    # TODO(paul): validate the Submit File on upload modal async
    #             even better, use JS validation for title length.
    try:
        if media_type == 'image':
            file_info = upload_image(request)
        else:
            msg = _(u'Unrecognized media type.')
            return HttpResponseBadRequest(
                json.dumps({'status': 'error', 'message': msg}))
    except FileTooLargeError as e:
        return HttpResponseBadRequest(
            json.dumps({'status': 'error', 'message': e.args[0]}))

    if isinstance(file_info, dict) and 'thumbnail_url' in file_info:
        schedule_rebuild_kb()
        return HttpResponse(
            json.dumps({'status': 'success', 'file': file_info}))

    message = _(u'Could not upload your image.')
    return HttpResponseBadRequest(
        json.dumps({'status': 'error',
                    'message': unicode(message),
                    'errors': file_info}))
Пример #2
0
def upload_async(request, media_type='image'):
    """Upload images or videos from request.FILES."""
    # TODO(paul): validate the Submit File on upload modal async
    #             even better, use JS validation for title length.
    try:
        if media_type == 'image':
            file_info = upload_image(request)
        else:
            msg = _(u'Unrecognized media type.')
            return HttpResponseBadRequest(
                json.dumps({'status': 'error', 'message': msg}))
    except FileTooLargeError as e:
        return HttpResponseBadRequest(
            json.dumps({'status': 'error', 'message': e.args[0]}))

    if isinstance(file_info, dict) and 'thumbnail_url' in file_info:
        schedule_rebuild_kb()
        return HttpResponse(
            json.dumps({'status': 'success', 'file': file_info}))

    message = _(u'Could not upload your image.')
    return HttpResponseBadRequest(
        json.dumps({'status': 'error',
                    'message': unicode(message),
                    'errors': file_info}))
Пример #3
0
def upload_async(request, media_type="image"):
    """Upload images or videos from request.FILES."""
    # TODO(paul): validate the Submit File on upload modal async
    #             even better, use JS validation for title length.
    try:
        if media_type == "image":
            file_info = upload_image(request)
        else:
            msg = _("Unrecognized media type.")
            return HttpResponseBadRequest(json.dumps({"status": "error", "message": msg}))
    except FileTooLargeError as e:
        return HttpResponseBadRequest(json.dumps({"status": "error", "message": e.args[0]}))

    if isinstance(file_info, dict) and "thumbnail_url" in file_info:
        schedule_rebuild_kb()
        return HttpResponse(json.dumps({"status": "success", "file": file_info}))

    message = _("Could not upload your image.")
    return HttpResponseBadRequest(
        json.dumps({"status": "error", "message": str(message), "errors": file_info})
    )