diff options
author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2015-09-28 21:45:20 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-29 14:11:37 +0100 |
commit | 60f3ddb2fb6dde3a04866b1bc3df7ae6e53ea918 (patch) | |
tree | ec7bd9c11a9279940ec2814718c607a5db2b42c3 | |
parent | a7f43bd532513e1a5a9d84e797c707f6039c914a (diff) | |
download | poky-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>
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 13 |
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 | |||
45 | from toastergui.templatetags.projecttags import json as jsonfilter | 45 | from toastergui.templatetags.projecttags import json as jsonfilter |
46 | import json | 46 | import json |
47 | from os.path import dirname | 47 | from os.path import dirname |
48 | from functools import wraps | ||
48 | import itertools | 49 | import itertools |
49 | 50 | ||
50 | import magic | 51 | import 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() |