diff options
author | Michael Wood <michael.g.wood@intel.com> | 2016-07-06 18:22:36 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-08 09:57:28 +0100 |
commit | 36dec688c7e50e02e55c070f04c396e2d1aa3ef3 (patch) | |
tree | 6072b631d8a122f2364cb896a268e93d0fc680b2 /bitbake/lib/toaster/toastergui | |
parent | 903c3c2ef8e31aad287d914dbb18a926cb96e6d0 (diff) | |
download | poky-36dec688c7e50e02e55c070f04c396e2d1aa3ef3.tar.gz |
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>
Diffstat (limited to 'bitbake/lib/toaster/toastergui')
-rw-r--r-- | bitbake/lib/toaster/toastergui/api.py | 99 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/layerdetails.html | 2 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/urls.py | 5 | ||||
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 43 |
4 files changed, 103 insertions, 46 deletions
diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 961b594ef4..a024748271 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py | |||
@@ -20,11 +20,14 @@ | |||
20 | # Temporary home for the UI's misc API | 20 | # Temporary home for the UI's misc API |
21 | import re | 21 | import re |
22 | 22 | ||
23 | from orm.models import Project, ProjectTarget, Build | 23 | from orm.models import Project, ProjectTarget, Build, Layer_Version |
24 | from orm.models import LayerVersionDependency, LayerSource, ProjectLayer | ||
24 | from bldcontrol.models import BuildRequest | 25 | from bldcontrol.models import BuildRequest |
25 | from bldcontrol import bbcontroller | 26 | from bldcontrol import bbcontroller |
26 | from django.http import HttpResponse, JsonResponse | 27 | from django.http import HttpResponse, JsonResponse |
27 | from django.views.generic import View | 28 | from django.views.generic import View |
29 | from django.core.urlresolvers import reverse | ||
30 | |||
28 | 31 | ||
29 | 32 | ||
30 | class XhrBuildRequest(View): | 33 | class XhrBuildRequest(View): |
@@ -109,3 +112,97 @@ class XhrBuildRequest(View): | |||
109 | response = HttpResponse() | 112 | response = HttpResponse() |
110 | response.status_code = 500 | 113 | response.status_code = 500 |
111 | return response | 114 | return response |
115 | |||
116 | |||
117 | class XhrLayer(View): | ||
118 | """ Get and Update Layer information """ | ||
119 | |||
120 | def post(self, request, *args, **kwargs): | ||
121 | """ | ||
122 | Update a layer | ||
123 | |||
124 | Entry point: /xhr_layer/<layerversion_id> | ||
125 | Method: POST | ||
126 | |||
127 | Args: | ||
128 | vcs_url, dirpath, commit, up_branch, summary, description | ||
129 | |||
130 | add_dep = append a layerversion_id as a dependency | ||
131 | rm_dep = remove a layerversion_id as a depedency | ||
132 | Returns: | ||
133 | {"error": "ok"} | ||
134 | or | ||
135 | {"error": <error message>} | ||
136 | """ | ||
137 | |||
138 | def error_response(error): | ||
139 | return JsonResponse({"error": error}) | ||
140 | |||
141 | try: | ||
142 | # We currently only allow Imported layers to be edited | ||
143 | layer_version = Layer_Version.objects.get( | ||
144 | id=kwargs['layerversion_id'], | ||
145 | project=kwargs['pid'], | ||
146 | layer_source__sourcetype=LayerSource.TYPE_IMPORTED) | ||
147 | |||
148 | except Layer_Version.DoesNotExist: | ||
149 | return error_response("Cannot find imported layer to update") | ||
150 | |||
151 | if "vcs_url" in request.POST: | ||
152 | layer_version.layer.vcs_url = request.POST["vcs_url"] | ||
153 | if "dirpath" in request.POST: | ||
154 | layer_version.dirpath = request.POST["dirpath"] | ||
155 | if "commit" in request.POST: | ||
156 | layer_version.commit = request.POST["commit"] | ||
157 | layer_version.branch = request.POST["commit"] | ||
158 | if "up_branch" in request.POST: | ||
159 | layer_version.up_branch_id = int(request.POST["up_branch"]) | ||
160 | if "summary" in request.POST: | ||
161 | layer_version.layer.summary = request.POST["summary"] | ||
162 | if "description" in request.POST: | ||
163 | layer_version.layer.description = request.POST["description"] | ||
164 | |||
165 | if "add_dep" in request.POST: | ||
166 | lvd = LayerVersionDependency( | ||
167 | layer_version=layer_version, | ||
168 | depends_on_id=request.POST["add_dep"]) | ||
169 | lvd.save() | ||
170 | |||
171 | if "rm_dep" in request.POST: | ||
172 | rm_dep = LayerVersionDependency.objects.get( | ||
173 | layer_version=layer_version, | ||
174 | depends_on_id=request.POST["rm_dep"]) | ||
175 | rm_dep.delete() | ||
176 | |||
177 | try: | ||
178 | layer_version.layer.save() | ||
179 | layer_version.save() | ||
180 | except Exception as e: | ||
181 | return error_response("Could not update layer version entry: %s" | ||
182 | % e) | ||
183 | |||
184 | return JsonResponse({"error": "ok"}) | ||
185 | |||
186 | def delete(self, request, *args, **kwargs): | ||
187 | try: | ||
188 | # We currently only allow Imported layers to be deleted | ||
189 | layer_version = Layer_Version.objects.get( | ||
190 | id=kwargs['layerversion_id'], | ||
191 | project=kwargs['pid'], | ||
192 | layer_source__sourcetype=LayerSource.TYPE_IMPORTED) | ||
193 | except Layer_Version.DoesNotExist: | ||
194 | return error_response("Cannot find imported layer to delete") | ||
195 | |||
196 | try: | ||
197 | ProjectLayer.objects.get(project=kwargs['pid'], | ||
198 | layercommit=layer_version).delete() | ||
199 | except ProjectLayer.DoesNotExist: | ||
200 | pass | ||
201 | |||
202 | layer_version.layer.delete() | ||
203 | layer_version.delete() | ||
204 | |||
205 | return JsonResponse({ | ||
206 | "error": "ok", | ||
207 | "redirect": reverse('project', args=(kwargs['pid'],)) | ||
208 | }) | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/layerdetails.html b/bitbake/lib/toaster/toastergui/templates/layerdetails.html index 0f0b2b49e6..143ec25dd7 100644 --- a/bitbake/lib/toaster/toastergui/templates/layerdetails.html +++ b/bitbake/lib/toaster/toastergui/templates/layerdetails.html | |||
@@ -44,7 +44,7 @@ | |||
44 | 44 | ||
45 | $(document).ready(function(){ | 45 | $(document).ready(function(){ |
46 | var ctx = { | 46 | var ctx = { |
47 | xhrUpdateLayerUrl : "{% url 'xhr_updatelayer' %}", | 47 | xhrUpdateLayerUrl : "{% url 'xhr_layer' layerversion.pk %}", |
48 | layerVersion : { | 48 | layerVersion : { |
49 | name : "{{layerversion.layer.name}}", | 49 | name : "{{layerversion.layer.name}}", |
50 | id : {{layerversion.id}}, | 50 | id : {{layerversion.id}}, |
diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index 9510a386ea..15b1063c59 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py | |||
@@ -190,7 +190,10 @@ urlpatterns = patterns('toastergui.views', | |||
190 | name='xhr_configvaredit'), | 190 | name='xhr_configvaredit'), |
191 | 191 | ||
192 | url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'), | 192 | url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'), |
193 | url(r'^xhr_updatelayer/$', 'xhr_updatelayer', name='xhr_updatelayer'), | 193 | |
194 | url(r'^xhr_layer/(?P<layerversion_id>\d+)$', | ||
195 | api.XhrLayer.as_view(), | ||
196 | name='xhr_layer'), | ||
194 | 197 | ||
195 | # JS Unit tests | 198 | # JS Unit tests |
196 | url(r'^js-unit-tests/$', 'jsunittests', name='js-unit-tests'), | 199 | url(r'^js-unit-tests/$', 'jsunittests', name='js-unit-tests'), |
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 2db68bdd4d..ad85fafb4d 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -1739,49 +1739,6 @@ if True: | |||
1739 | 1739 | ||
1740 | return HttpResponse(jsonfilter(json_response), content_type = "application/json") | 1740 | return HttpResponse(jsonfilter(json_response), content_type = "application/json") |
1741 | 1741 | ||
1742 | def xhr_updatelayer(request): | ||
1743 | |||
1744 | def error_response(error): | ||
1745 | return HttpResponse(jsonfilter({"error": error}), content_type = "application/json") | ||
1746 | |||
1747 | if "layer_version_id" not in request.POST: | ||
1748 | return error_response("Please specify a layer version id") | ||
1749 | try: | ||
1750 | layer_version_id = request.POST["layer_version_id"] | ||
1751 | layer_version = Layer_Version.objects.get(id=layer_version_id) | ||
1752 | except Layer_Version.DoesNotExist: | ||
1753 | return error_response("Cannot find layer to update") | ||
1754 | |||
1755 | |||
1756 | if "vcs_url" in request.POST: | ||
1757 | layer_version.layer.vcs_url = request.POST["vcs_url"] | ||
1758 | if "dirpath" in request.POST: | ||
1759 | layer_version.dirpath = request.POST["dirpath"] | ||
1760 | if "commit" in request.POST: | ||
1761 | layer_version.commit = request.POST["commit"] | ||
1762 | if "up_branch" in request.POST: | ||
1763 | layer_version.up_branch_id = int(request.POST["up_branch"]) | ||
1764 | |||
1765 | if "add_dep" in request.POST: | ||
1766 | lvd = LayerVersionDependency(layer_version=layer_version, depends_on_id=request.POST["add_dep"]) | ||
1767 | lvd.save() | ||
1768 | |||
1769 | if "rm_dep" in request.POST: | ||
1770 | rm_dep = LayerVersionDependency.objects.get(layer_version=layer_version, depends_on_id=request.POST["rm_dep"]) | ||
1771 | rm_dep.delete() | ||
1772 | |||
1773 | if "summary" in request.POST: | ||
1774 | layer_version.layer.summary = request.POST["summary"] | ||
1775 | if "description" in request.POST: | ||
1776 | layer_version.layer.description = request.POST["description"] | ||
1777 | |||
1778 | try: | ||
1779 | layer_version.layer.save() | ||
1780 | layer_version.save() | ||
1781 | except Exception as e: | ||
1782 | return error_response("Could not update layer version entry: %s" % e) | ||
1783 | |||
1784 | return HttpResponse(jsonfilter({"error": "ok",}), content_type = "application/json") | ||
1785 | 1742 | ||
1786 | @xhr_response | 1743 | @xhr_response |
1787 | def xhr_customrecipe(request): | 1744 | def xhr_customrecipe(request): |