diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-06-30 18:33:04 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-07-23 20:06:58 +0100 |
commit | 6e71c276b582135228419d95174b7e7784d496b2 (patch) | |
tree | b9facea21ed3a3af49c80c01275ee1d0b64f8075 /bitbake/lib/toaster/toastergui/views.py | |
parent | 8a3789a7b11565aa2ceae0b79f93edb0d353173b (diff) | |
download | poky-6e71c276b582135228419d95174b7e7784d496b2.tar.gz |
bitbake: toaster: add project main edit page
This is the first commit on the project main edit page.
At this point we have:
* the default settings for a newly created project
* the ability to add targets
* the ability to trigger a build command, and have
the build executed
Project layers now have an optional field, allowing for
removal. Default meta, meta-yocto and meta-yocto-bsp
layers cannot be optional.
We add XHR calls for interactivity in the main page.
(Bitbake rev: 4e438854120cbd10319df1b571ec93e334002325)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/views.py')
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 105 |
1 files changed, 99 insertions, 6 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index f9e8e51688..bd65c08b06 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -30,7 +30,7 @@ from orm.models import Target_Installed_Package, Target_File, Target_Image_File | |||
30 | from django.views.decorators.cache import cache_control | 30 | from django.views.decorators.cache import cache_control |
31 | from django.core.urlresolvers import reverse | 31 | from django.core.urlresolvers import reverse |
32 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | 32 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
33 | from django.http import HttpResponseBadRequest | 33 | from django.http import HttpResponseBadRequest, HttpResponseNotFound |
34 | from django.utils import timezone | 34 | from django.utils import timezone |
35 | from datetime import timedelta | 35 | from datetime import timedelta |
36 | from django.utils import formats | 36 | from django.utils import formats |
@@ -1761,8 +1761,6 @@ def image_information_dir(request, build_id, target_id, packagefile_id): | |||
1761 | 1761 | ||
1762 | 1762 | ||
1763 | import toastermain.settings | 1763 | import toastermain.settings |
1764 | def managedcontextprocessor(request): | ||
1765 | return { "MANAGED" : toastermain.settings.MANAGED } | ||
1766 | 1764 | ||
1767 | 1765 | ||
1768 | # we have a set of functions if we're in managed mode, or | 1766 | # we have a set of functions if we're in managed mode, or |
@@ -1773,7 +1771,8 @@ if toastermain.settings.MANAGED: | |||
1773 | from django.contrib.auth import authenticate, login | 1771 | from django.contrib.auth import authenticate, login |
1774 | from django.contrib.auth.decorators import login_required | 1772 | from django.contrib.auth.decorators import login_required |
1775 | 1773 | ||
1776 | from orm.models import Project | 1774 | from orm.models import Project, ProjectLayer, ProjectTarget, ProjectVariable |
1775 | from bldcontrol.models import BuildRequest | ||
1777 | 1776 | ||
1778 | import traceback | 1777 | import traceback |
1779 | 1778 | ||
@@ -1831,19 +1830,113 @@ if toastermain.settings.MANAGED: | |||
1831 | else: | 1830 | else: |
1832 | context['alert'] = str(e) | 1831 | context['alert'] = str(e) |
1833 | return render(request, template, context) | 1832 | return render(request, template, context) |
1833 | |||
1834 | raise Exception("Invalid HTTP method for this page") | 1834 | raise Exception("Invalid HTTP method for this page") |
1835 | 1835 | ||
1836 | # Shows the edit project page | 1836 | # Shows the edit project page |
1837 | def project(request, pid): | 1837 | def project(request, pid): |
1838 | template = "project.html" | 1838 | template = "project.html" |
1839 | context = {} | 1839 | try: |
1840 | prj = Project.objects.get(id = pid) | ||
1841 | except Project.DoesNotExist: | ||
1842 | return HttpResponseNotFound("<h1>Project id " + pid + " is unavailable</h1>") | ||
1843 | |||
1844 | try: | ||
1845 | puser = User.objects.get(id = prj.user_id) | ||
1846 | except User.DoesNotExist: | ||
1847 | puser = None | ||
1848 | |||
1849 | context = { | ||
1850 | "project" : prj, | ||
1851 | #"buildrequests" : prj.buildrequest_set.filter(state=BuildRequest.REQ_QUEUED), | ||
1852 | "buildrequests" : map(lambda x: (x, {"machine" : x.brvariable_set.filter(name="MACHINE")[0]}), prj.buildrequest_set.order_by("-pk")), | ||
1853 | "builds" : prj.build_set.all(), | ||
1854 | "puser": puser, | ||
1855 | } | ||
1856 | try: | ||
1857 | context["machine"] = prj.projectvariable_set.get(name="MACHINE").value | ||
1858 | except ProjectVariable.DoesNotExist: | ||
1859 | context["machine"] = "-- not set yet" | ||
1860 | |||
1861 | try: | ||
1862 | context["distro"] = prj.projectvariable_set.get(name="DISTRO").value | ||
1863 | except ProjectVariable.DoesNotExist: | ||
1864 | context["distro"] = "-- not set yet" | ||
1865 | |||
1866 | |||
1840 | return render(request, template, context) | 1867 | return render(request, template, context) |
1841 | 1868 | ||
1869 | import json | ||
1870 | |||
1871 | def xhr_projectbuild(request, pid): | ||
1872 | try: | ||
1873 | if request.method != "POST": | ||
1874 | raise BadParameterException("invalid method") | ||
1875 | prj = Project.objects.get(id = pid) | ||
1876 | |||
1877 | if prj.projecttarget_set.count() == 0: | ||
1878 | raise BadParameterException("no targets selected") | ||
1879 | |||
1880 | br = prj.schedule_build() | ||
1881 | return HttpResponse(json.dumps({"error":"ok", | ||
1882 | "brtarget" : map(lambda x: x.target, br.brtarget_set.all()), | ||
1883 | "machine" : br.brvariable_set.get(name="MACHINE").value, | ||
1884 | |||
1885 | }), content_type = "application/json") | ||
1886 | except Exception as e: | ||
1887 | return HttpResponse(json.dumps({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") | ||
1888 | |||
1889 | def xhr_projectedit(request, pid): | ||
1890 | try: | ||
1891 | prj = Project.objects.get(id = pid) | ||
1892 | # add targets | ||
1893 | if 'targetAdd' in request.POST: | ||
1894 | for t in request.POST['targetAdd'].strip().split(" "): | ||
1895 | if ":" in t: | ||
1896 | target, task = t.split(":") | ||
1897 | else: | ||
1898 | target = t | ||
1899 | task = "" | ||
1900 | |||
1901 | pt, created = ProjectTarget.objects.get_or_create(project = prj, target = target, task = task) | ||
1902 | # remove targets | ||
1903 | if 'targetDel' in request.POST: | ||
1904 | for t in request.POST['targetDel'].strip().split(" "): | ||
1905 | pt = ProjectTarget.objects.get(pk = int(t)).delete() | ||
1906 | |||
1907 | # add layers | ||
1908 | |||
1909 | # remove layers | ||
1910 | |||
1911 | # return all project settings | ||
1912 | return HttpResponse(json.dumps( { | ||
1913 | "error": "ok", | ||
1914 | "layers": map(lambda x: (x.name, x.giturl), prj.projectlayer_set.all()), | ||
1915 | "targets" : map(lambda x: {"target" : x.target, "task" : x.task, "pk": x.pk}, prj.projecttarget_set.all()), | ||
1916 | "variables": map(lambda x: (x.name, x.value), prj.projectvariable_set.all()), | ||
1917 | }), content_type = "application/json") | ||
1918 | |||
1919 | except Exception as e: | ||
1920 | return HttpResponse(json.dumps({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") | ||
1921 | |||
1842 | 1922 | ||
1843 | else: | 1923 | else: |
1844 | # these are pages that are NOT available in interactive mode | 1924 | # these are pages that are NOT available in interactive mode |
1925 | def managedcontextprocessor(request): | ||
1926 | return { | ||
1927 | "projects": [], | ||
1928 | "MANAGED" : toastermain.settings.MANAGED | ||
1929 | } | ||
1930 | |||
1845 | def newproject(request): | 1931 | def newproject(request): |
1846 | raise Exception("page not available in interactive mode") | 1932 | raise Exception("page not available in interactive mode") |
1847 | 1933 | ||
1848 | def project(request): | 1934 | def project(request, pid): |
1935 | raise Exception("page not available in interactive mode") | ||
1936 | |||
1937 | def xhr_projectbuild(request, pid): | ||
1849 | raise Exception("page not available in interactive mode") | 1938 | raise Exception("page not available in interactive mode") |
1939 | |||
1940 | def xhr_projectedit(request, pid): | ||
1941 | raise Exception("page not available in interactive mode") | ||
1942 | |||