1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 12:29:55 +00:00

bitbake: toaster: implement decorator for REST responses

Implemented xhr_response decorator to decorate responses
from REST methods into Django HttpResponse objects.

This decorator should reduce amount of repeated code in
REST methods and make them more readable.

(Bitbake rev: bb0696f343aca44207581f15ff2b4f0045f7530c)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh
2015-09-28 21:45:20 -07:00
committed by Richard Purdie
parent a7f43bd532
commit 60f3ddb2fb
+13
View File
@@ -45,6 +45,7 @@ from django.utils import formats
from toastergui.templatetags.projecttags import json as jsonfilter from toastergui.templatetags.projecttags import json as jsonfilter
import json import json
from os.path import dirname from os.path import dirname
from functools import wraps
import itertools import itertools
import magic import magic
@@ -2314,6 +2315,18 @@ if True:
return context 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): def jsunittests(request):
""" Provides a page for the js unit tests """ """ Provides a page for the js unit tests """
bbv = BitbakeVersion.objects.filter(branch="master").first() bbv = BitbakeVersion.objects.filter(branch="master").first()