summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-09-28 21:45:20 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-29 14:11:37 +0100
commit60f3ddb2fb6dde3a04866b1bc3df7ae6e53ea918 (patch)
treeec7bd9c11a9279940ec2814718c607a5db2b42c3 /bitbake
parenta7f43bd532513e1a5a9d84e797c707f6039c914a (diff)
downloadpoky-60f3ddb2fb6dde3a04866b1bc3df7ae6e53ea918.tar.gz
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>
Diffstat (limited to 'bitbake')
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index 2e3b822797..95df60e472 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -45,6 +45,7 @@ from django.utils import formats
45from toastergui.templatetags.projecttags import json as jsonfilter 45from toastergui.templatetags.projecttags import json as jsonfilter
46import json 46import json
47from os.path import dirname 47from os.path import dirname
48from functools import wraps
48import itertools 49import itertools
49 50
50import magic 51import magic
@@ -2314,6 +2315,18 @@ if True:
2314 2315
2315 return context 2316 return context
2316 2317
2318 def xhr_response(fun):
2319 """
2320 Decorator for REST methods.
2321 calls jsonfilter on the returned dictionary and returns result
2322 as HttpResponse object of content_type application/json
2323 """
2324 @wraps(fun)
2325 def wrapper(*args, **kwds):
2326 return HttpResponse(jsonfilter(fun(*args, **kwds)),
2327 content_type="application/json")
2328 return wrapper
2329
2317 def jsunittests(request): 2330 def jsunittests(request):
2318 """ Provides a page for the js unit tests """ 2331 """ Provides a page for the js unit tests """
2319 bbv = BitbakeVersion.objects.filter(branch="master").first() 2332 bbv = BitbakeVersion.objects.filter(branch="master").first()