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 13:44:48 +0100 |
commit | bb0696f343aca44207581f15ff2b4f0045f7530c (patch) | |
tree | 4931b3a22a15cd66d7ac4c122bc7fef42ff88f9f /lib/toaster | |
parent | ffc11b2c6c6bac4643233cc46418b025c94607c8 (diff) | |
download | bitbake-bb0696f343aca44207581f15ff2b4f0045f7530c.zip |
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.
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 'lib/toaster')
-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() |