summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/api.py
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-07-06 18:22:37 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-08 09:57:29 +0100
commite1ba2fd331b7f937b8ddf3e83389df5caf33d9e8 (patch)
tree63b56f8b46d093685d62c4a1bfaaaf8336e6f6c5 /bitbake/lib/toaster/toastergui/api.py
parent36dec688c7e50e02e55c070f04c396e2d1aa3ef3 (diff)
downloadpoky-e1ba2fd331b7f937b8ddf3e83389df5caf33d9e8.tar.gz
bitbake: toaster: api Add util function for returning the error response
Also clean up flake8 warnings in XhrBuildRequest (Bitbake rev: aa0845242eda8650a97180bf6675551c26554cde) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/api.py')
-rw-r--r--bitbake/lib/toaster/toastergui/api.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py
index a024748271..112ce58914 100644
--- a/bitbake/lib/toaster/toastergui/api.py
+++ b/bitbake/lib/toaster/toastergui/api.py
@@ -29,6 +29,9 @@ from django.views.generic import View
29from django.core.urlresolvers import reverse 29from django.core.urlresolvers import reverse
30 30
31 31
32def error_response(error):
33 return JsonResponse({"error": error})
34
32 35
33class XhrBuildRequest(View): 36class XhrBuildRequest(View):
34 37
@@ -81,20 +84,24 @@ class XhrBuildRequest(View):
81 br.save() 84 br.save()
82 85
83 except BuildRequest.DoesNotExist: 86 except BuildRequest.DoesNotExist:
84 return JsonResponse({'error':'No such build id %s' % i}) 87 return error_response('No such build id %s' % i)
85 88
86 return JsonResponse({'error': 'ok'}) 89 return error_response('ok')
87 90
88 if 'buildDelete' in request.POST: 91 if 'buildDelete' in request.POST:
89 for i in request.POST['buildDelete'].strip().split(" "): 92 for i in request.POST['buildDelete'].strip().split(" "):
90 try: 93 try:
91 BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() 94 BuildRequest.objects.select_for_update().get(
95 project=project,
96 pk=i,
97 state__lte=BuildRequest.REQ_DELETED).delete()
98
92 except BuildRequest.DoesNotExist: 99 except BuildRequest.DoesNotExist:
93 pass 100 pass
94 return JsonResponse({'error': 'ok' }) 101 return error_response("ok")
95 102
96 if 'targets' in request.POST: 103 if 'targets' in request.POST:
97 ProjectTarget.objects.filter(project = project).delete() 104 ProjectTarget.objects.filter(project=project).delete()
98 s = str(request.POST['targets']) 105 s = str(request.POST['targets'])
99 for t in re.sub(r'[;%|"]', '', s).split(" "): 106 for t in re.sub(r'[;%|"]', '', s).split(" "):
100 if ":" in t: 107 if ":" in t:
@@ -102,12 +109,12 @@ class XhrBuildRequest(View):
102 else: 109 else:
103 target = t 110 target = t
104 task = "" 111 task = ""
105 ProjectTarget.objects.create(project = project, 112 ProjectTarget.objects.create(project=project,
106 target = target, 113 target=target,
107 task = task) 114 task=task)
108 project.schedule_build() 115 project.schedule_build()
109 116
110 return JsonResponse({'error': 'ok' }) 117 return error_response('ok')
111 118
112 response = HttpResponse() 119 response = HttpResponse()
113 response.status_code = 500 120 response.status_code = 500
@@ -135,9 +142,6 @@ class XhrLayer(View):
135 {"error": <error message>} 142 {"error": <error message>}
136 """ 143 """
137 144
138 def error_response(error):
139 return JsonResponse({"error": error})
140
141 try: 145 try:
142 # We currently only allow Imported layers to be edited 146 # We currently only allow Imported layers to be edited
143 layer_version = Layer_Version.objects.get( 147 layer_version = Layer_Version.objects.get(