bitbake: toaster: layerdetails api Fix saving of git revision of a layer

Update, clean up and move the api for updating a layerversion from the
views to api. Also update the layerdetails page to include the
layerversion id in the url getter.

[YOCTO #8952]

(Bitbake rev: 20f4e23bc86290f0a42881a7cac44c41eafa86fc)

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>
This commit is contained in:
Michael Wood 2016-07-06 18:22:36 +01:00 committed by Richard Purdie
parent 903c3c2ef8
commit 36dec688c7
4 changed files with 103 additions and 46 deletions

View File

@ -20,11 +20,14 @@
# Temporary home for the UI's misc API
import re
from orm.models import Project, ProjectTarget, Build
from orm.models import Project, ProjectTarget, Build, Layer_Version
from orm.models import LayerVersionDependency, LayerSource, ProjectLayer
from bldcontrol.models import BuildRequest
from bldcontrol import bbcontroller
from django.http import HttpResponse, JsonResponse
from django.views.generic import View
from django.core.urlresolvers import reverse
class XhrBuildRequest(View):
@ -109,3 +112,97 @@ class XhrBuildRequest(View):
response = HttpResponse()
response.status_code = 500
return response
class XhrLayer(View):
""" Get and Update Layer information """
def post(self, request, *args, **kwargs):
"""
Update a layer
Entry point: /xhr_layer/<layerversion_id>
Method: POST
Args:
vcs_url, dirpath, commit, up_branch, summary, description
add_dep = append a layerversion_id as a dependency
rm_dep = remove a layerversion_id as a depedency
Returns:
{"error": "ok"}
or
{"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(
id=kwargs['layerversion_id'],
project=kwargs['pid'],
layer_source__sourcetype=LayerSource.TYPE_IMPORTED)
except Layer_Version.DoesNotExist:
return error_response("Cannot find imported layer to update")
if "vcs_url" in request.POST:
layer_version.layer.vcs_url = request.POST["vcs_url"]
if "dirpath" in request.POST:
layer_version.dirpath = request.POST["dirpath"]
if "commit" in request.POST:
layer_version.commit = request.POST["commit"]
layer_version.branch = request.POST["commit"]
if "up_branch" in request.POST:
layer_version.up_branch_id = int(request.POST["up_branch"])
if "summary" in request.POST:
layer_version.layer.summary = request.POST["summary"]
if "description" in request.POST:
layer_version.layer.description = request.POST["description"]
if "add_dep" in request.POST:
lvd = LayerVersionDependency(
layer_version=layer_version,
depends_on_id=request.POST["add_dep"])
lvd.save()
if "rm_dep" in request.POST:
rm_dep = LayerVersionDependency.objects.get(
layer_version=layer_version,
depends_on_id=request.POST["rm_dep"])
rm_dep.delete()
try:
layer_version.layer.save()
layer_version.save()
except Exception as e:
return error_response("Could not update layer version entry: %s"
% e)
return JsonResponse({"error": "ok"})
def delete(self, request, *args, **kwargs):
try:
# We currently only allow Imported layers to be deleted
layer_version = Layer_Version.objects.get(
id=kwargs['layerversion_id'],
project=kwargs['pid'],
layer_source__sourcetype=LayerSource.TYPE_IMPORTED)
except Layer_Version.DoesNotExist:
return error_response("Cannot find imported layer to delete")
try:
ProjectLayer.objects.get(project=kwargs['pid'],
layercommit=layer_version).delete()
except ProjectLayer.DoesNotExist:
pass
layer_version.layer.delete()
layer_version.delete()
return JsonResponse({
"error": "ok",
"redirect": reverse('project', args=(kwargs['pid'],))
})

View File

@ -44,7 +44,7 @@
$(document).ready(function(){
var ctx = {
xhrUpdateLayerUrl : "{% url 'xhr_updatelayer' %}",
xhrUpdateLayerUrl : "{% url 'xhr_layer' layerversion.pk %}",
layerVersion : {
name : "{{layerversion.layer.name}}",
id : {{layerversion.id}},

View File

@ -190,7 +190,10 @@ urlpatterns = patterns('toastergui.views',
name='xhr_configvaredit'),
url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'),
url(r'^xhr_updatelayer/$', 'xhr_updatelayer', name='xhr_updatelayer'),
url(r'^xhr_layer/(?P<layerversion_id>\d+)$',
api.XhrLayer.as_view(),
name='xhr_layer'),
# JS Unit tests
url(r'^js-unit-tests/$', 'jsunittests', name='js-unit-tests'),

View File

@ -1739,49 +1739,6 @@ if True:
return HttpResponse(jsonfilter(json_response), content_type = "application/json")
def xhr_updatelayer(request):
def error_response(error):
return HttpResponse(jsonfilter({"error": error}), content_type = "application/json")
if "layer_version_id" not in request.POST:
return error_response("Please specify a layer version id")
try:
layer_version_id = request.POST["layer_version_id"]
layer_version = Layer_Version.objects.get(id=layer_version_id)
except Layer_Version.DoesNotExist:
return error_response("Cannot find layer to update")
if "vcs_url" in request.POST:
layer_version.layer.vcs_url = request.POST["vcs_url"]
if "dirpath" in request.POST:
layer_version.dirpath = request.POST["dirpath"]
if "commit" in request.POST:
layer_version.commit = request.POST["commit"]
if "up_branch" in request.POST:
layer_version.up_branch_id = int(request.POST["up_branch"])
if "add_dep" in request.POST:
lvd = LayerVersionDependency(layer_version=layer_version, depends_on_id=request.POST["add_dep"])
lvd.save()
if "rm_dep" in request.POST:
rm_dep = LayerVersionDependency.objects.get(layer_version=layer_version, depends_on_id=request.POST["rm_dep"])
rm_dep.delete()
if "summary" in request.POST:
layer_version.layer.summary = request.POST["summary"]
if "description" in request.POST:
layer_version.layer.description = request.POST["description"]
try:
layer_version.layer.save()
layer_version.save()
except Exception as e:
return error_response("Could not update layer version entry: %s" % e)
return HttpResponse(jsonfilter({"error": "ok",}), content_type = "application/json")
@xhr_response
def xhr_customrecipe(request):