def wrapped(*args, **kwargs): request = flask.request codec = encoder(request) if request.method in ['POST', 'PUT']: # check for multipart form data. this will be submitted with the jquery # forms plugin, which makes the request slightly different from # the backbone request. # # right now, since we're only accepting CSV files as upload this way, # we don't need to save the file anywhere, but we'll simply add the files # to the data hash keyed with the name values. if 'CONTENT_TYPE' in request.environ \ and ('multipart/form-data' in request.environ['CONTENT_TYPE'] or 'application/x-www-form-urlencoded' \ in request.environ['CONTENT_TYPE']): data = request.form.copy() data.update(request.files) kwargs['data'] = data else: try: kwargs['data'] = codec.decode(request) except Exception, e: return error({ 'client': [str(e)] })
def error(msg, status=400): codec = encoder(flask.request, 'errors') response = Response(status=status) if isinstance(msg, dict): response.data = codec.encode(msg) else: response.data = codec.encode(msg._errors) return response
def error(msg): codec = encoder(flask.request, 'errors') response = Response(status=400) if isinstance(msg, dict): response.data = codec.encode(msg) else: response.data = codec.encode(msg._errors) return response
def _serialize(item, request=None): if request is None: request = flask.request codec = encoder(request) if isinstance(item, BaseResponse): return item if hasattr(item, '__iter__') and not isinstance(item, dict): return codec.encode([_simplify(i) for i in item]) return codec.encode(_simplify(item))