diff options
-rwxr-xr-x | lib/toaster/toastergui/views.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py index 2e3b8227..95df60e4 100755 --- a/lib/toaster/toastergui/views.py +++ b/lib/toaster/toastergui/views.py @@ -45,6 +45,7 @@ from django.utils import formats from toastergui.templatetags.projecttags import json as jsonfilter import json from os.path import dirname +from functools import wraps import itertools import magic @@ -2314,6 +2315,18 @@ if True: return context + def xhr_response(fun): + """ + Decorator for REST methods. + calls jsonfilter on the returned dictionary and returns result + as HttpResponse object of content_type application/json + """ + @wraps(fun) + def wrapper(*args, **kwds): + return HttpResponse(jsonfilter(fun(*args, **kwds)), + content_type="application/json") + return wrapper + def jsunittests(request): """ Provides a page for the js unit tests """ bbv = BitbakeVersion.objects.filter(branch="master").first() |