diff --git a/k4ever/api2/decorators.py b/k4ever/api2/decorators.py index a124f05..496e7ad 100644 --- a/k4ever/api2/decorators.py +++ b/k4ever/api2/decorators.py @@ -88,11 +88,12 @@ def requirePlugin(apiFunc): def fix_mime(mime_func): """ Fix mimetype by truncating everything behind a ';'. - This is used to fix pistons ``piston.utils.Mimer.loader_for_type``.""" + This is used to fix pistons ``piston.utils.Mimer.content_type``.""" @wraps(mime_func) - def wrapper(self, ctype): + def wrapper(self): + ctype = self.request.META.get('CONTENT_TYPE', None) if ctype and ctype.find(";") >= 0: - ctype = ctype.split(";")[0] - return mime_func(self, ctype) + ctype = self.request.META['CONTENT_TYPE'] = ctype.split(";")[0] + return mime_func(self) return wrapper diff --git a/k4ever/api2/urls.py b/k4ever/api2/urls.py index ae60471..163bb65 100644 --- a/k4ever/api2/urls.py +++ b/k4ever/api2/urls.py @@ -6,17 +6,17 @@ from api2.handlers import * from api2.decorators import fix_mime import piston.utils -# piston does not understand mimetypes with charsets, HACK: fix loader_for_type -piston.utils.Mimer.loader_for_type = fix_mime(piston.utils.Mimer.loader_for_type) +# piston does not understand mimetypes with charsets, HACK: fix content_type +piston.utils.Mimer.content_type = fix_mime(piston.utils.Mimer.content_type) -class CsrfExemptResource( Resource ): +class CsrfExemptResource(Resource): """ Except a :class:`Resource` from djangos CSRF-Framework. This idea is taken from http://www.robertshady.com/content/creating-very-basic-api-using-python-django-and-piston """ - def __init__( self, handler, authentication = None ): + def __init__(self, handler, authentication = None): super( CsrfExemptResource, self ).__init__( handler, authentication ) self.csrf_exempt = getattr( self.handler, 'csrf_exempt', True )