summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/views.py')
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py105
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
30from django.views.decorators.cache import cache_control 30from django.views.decorators.cache import cache_control
31from django.core.urlresolvers import reverse 31from django.core.urlresolvers import reverse
32from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger 32from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
33from django.http import HttpResponseBadRequest 33from django.http import HttpResponseBadRequest, HttpResponseNotFound
34from django.utils import timezone 34from django.utils import timezone
35from datetime import timedelta 35from datetime import timedelta
36from django.utils import formats 36from django.utils import formats
@@ -1761,8 +1761,6 @@ def image_information_dir(request, build_id, target_id, packagefile_id):
1761 1761
1762 1762
1763import toastermain.settings 1763import toastermain.settings
1764def 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
1843else: 1923else:
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