Moves json_response into tools/json.py
This commit is contained in:
@@ -51,30 +51,6 @@ class Auth(object):
|
||||
def __call__(self, request, *args, **kw):
|
||||
raise NotImplemented()
|
||||
|
||||
|
||||
def json_response(serializable, _disable_cors=False, *args, **kw):
|
||||
'''
|
||||
Serializes a json objects and returns a werkzeug Response object with the
|
||||
serialized value as the response body and Content-Type: application/json.
|
||||
|
||||
:param serializable: A json-serializable object
|
||||
|
||||
Any extra arguments and keyword arguments are passed to the
|
||||
Response.__init__ method.
|
||||
'''
|
||||
response = Response(json.dumps(serializable), *args, content_type='application/json', **kw)
|
||||
|
||||
if not _disable_cors:
|
||||
cors_headers = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'}
|
||||
for key, value in cors_headers.iteritems():
|
||||
response.headers.set(key, value)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def get_entry_serializable(entry, urlgen):
|
||||
'''
|
||||
Returns a serializable dict() of a MediaEntry instance.
|
||||
|
||||
@@ -21,11 +21,11 @@ from os.path import splitext
|
||||
from werkzeug.exceptions import BadRequest, Forbidden
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
from mediagoblin.tools.json import json_response
|
||||
from mediagoblin.decorators import require_active_login
|
||||
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.plugins.api.tools import api_auth, get_entry_serializable
|
||||
from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \
|
||||
run_process_media, new_upload_entry
|
||||
|
||||
|
||||
Reference in New Issue
Block a user