summaryrefslogtreecommitdiffstats
path: root/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:06 +0100
commitaa0845242eda8650a97180bf6675551c26554cde (patch)
treed4a75686b4dd7f41eb24e79761d40bc6cdc04670 /lib/toaster/toastergui/api.py
parent20f4e23bc86290f0a42881a7cac44c41eafa86fc (diff)
downloadbitbake-contrib-aa0845242eda8650a97180bf6675551c26554cde.tar.gz
toaster: api Add util function for returning the error response
Also clean up flake8 warnings in XhrBuildRequest 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 'lib/toaster/toastergui/api.py')
-rw-r--r--lib/toaster/toastergui/api.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/toaster/toastergui/api.py b/lib/toaster/toastergui/api.py
index a02474827..112ce5891 100644
--- a/lib/toaster/toastergui/api.py
+++ b/lib/toaster/toastergui/api.py
@@ -29,6 +29,9 @@ from django.views.generic import View
from django.core.urlresolvers import reverse
+def error_response(error):
+ return JsonResponse({"error": error})
+
class XhrBuildRequest(View):
@@ -81,20 +84,24 @@ class XhrBuildRequest(View):
br.save()
except BuildRequest.DoesNotExist:
- return JsonResponse({'error':'No such build id %s' % i})
+ return error_response('No such build id %s' % i)
- return JsonResponse({'error': 'ok'})
+ return error_response('ok')
if 'buildDelete' in request.POST:
for i in request.POST['buildDelete'].strip().split(" "):
try:
- BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete()
+ BuildRequest.objects.select_for_update().get(
+ project=project,
+ pk=i,
+ state__lte=BuildRequest.REQ_DELETED).delete()
+
except BuildRequest.DoesNotExist:
pass
- return JsonResponse({'error': 'ok' })
+ return error_response("ok")
if 'targets' in request.POST:
- ProjectTarget.objects.filter(project = project).delete()
+ ProjectTarget.objects.filter(project=project).delete()
s = str(request.POST['targets'])
for t in re.sub(r'[;%|"]', '', s).split(" "):
if ":" in t:
@@ -102,12 +109,12 @@ class XhrBuildRequest(View):
else:
target = t
task = ""
- ProjectTarget.objects.create(project = project,
- target = target,
- task = task)
+ ProjectTarget.objects.create(project=project,
+ target=target,
+ task=task)
project.schedule_build()
- return JsonResponse({'error': 'ok' })
+ return error_response('ok')
response = HttpResponse()
response.status_code = 500
@@ -135,9 +142,6 @@ class XhrLayer(View):
{"error": <error message>}
"""
- def error_response(error):
- return JsonResponse({"error": error})
-
try:
# We currently only allow Imported layers to be edited
layer_version = Layer_Version.objects.get(