diff options
| author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-06-30 15:58:36 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-07-14 14:10:03 +0100 |
| commit | e7fa0c325d59811c272b7dad671225fea8c29609 (patch) | |
| tree | 599e0c75cef2d37fc1573d7ff91b9f3ce7b6f180 /bitbake/lib/toaster/toastergui | |
| parent | d19b784c1a2a4380c63947690ae6f7fa393c1ebc (diff) | |
| download | poky-e7fa0c325d59811c272b7dad671225fea8c29609.tar.gz | |
bitbake: toaster: new project page implementation
We add the logic to create a new project. This page
also serves as user registration and silent login
for users.
Once the project is added, the main project page is displayed.
(Bitbake rev: 8855daebe55917c4f5855413d02ae1f3f7f76571)
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')
| -rw-r--r-- | bitbake/lib/toaster/toastergui/templates/newproject.html | 13 | ||||
| -rw-r--r-- | bitbake/lib/toaster/toastergui/urls.py | 2 | ||||
| -rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 48 |
3 files changed, 43 insertions, 20 deletions
diff --git a/bitbake/lib/toaster/toastergui/templates/newproject.html b/bitbake/lib/toaster/toastergui/templates/newproject.html index ce01800e08..8f1867a94f 100644 --- a/bitbake/lib/toaster/toastergui/templates/newproject.html +++ b/bitbake/lib/toaster/toastergui/templates/newproject.html | |||
| @@ -8,9 +8,9 @@ | |||
| 8 | <h1>Create a new project</h1> | 8 | <h1>Create a new project</h1> |
| 9 | </div> | 9 | </div> |
| 10 | <div class="container-fluid"> | 10 | <div class="container-fluid"> |
| 11 | {% for a in alerts %} | 11 | {% if alert %} |
| 12 | <div class="alert alert-error row-fluid" role="alert">{{a}}</div> | 12 | <div class="alert alert-error row-fluid" role="alert">{{alert}}</div> |
| 13 | {% endfor %} | 13 | {% endif %} |
| 14 | </div> | 14 | </div> |
| 15 | <form method="POST">{% csrf_token %} | 15 | <form method="POST">{% csrf_token %} |
| 16 | <fieldset> | 16 | <fieldset> |
| @@ -27,10 +27,9 @@ | |||
| 27 | Yocto Project version | 27 | Yocto Project version |
| 28 | <i class="icon-question-sign get-help" title="This sets the branch for the Yocto Project core layers (meta, meta-yocto and meta-yocto-bsp), and for the layers you use from the OpenEmbedded Metadata Index"></i> | 28 | <i class="icon-question-sign get-help" title="This sets the branch for the Yocto Project core layers (meta, meta-yocto and meta-yocto-bsp), and for the layers you use from the OpenEmbedded Metadata Index"></i> |
| 29 | </label> | 29 | </label> |
| 30 | <select name="projectversion"> | 30 | <select name="projectversion" id="projectversion"> |
| 31 | <option value="1.7" {%if projectversion == "1.7" %}selected{%endif%}>Yocto Project 1.7 "D?"</option> | 31 | <!-- TODO: XHR data from http://layers.openembedded.org/layerindex/branch/master/layers/ --> |
| 32 | <option value="1.6" {%if projectversion == "1.6" %}selected{%endif%}>Yocto Project 1.6 "Daisy"</option> | 32 | <option value="master" {%if projectversion == "master" %}selected{%endif%}>master</option> |
| 33 | <option value="1.5" {%if projectversion == "1.5" %}selected{%endif%}>Yocto Project 1.5 "Dora"</option> | ||
| 34 | </select> | 33 | </select> |
| 35 | </fieldset> | 34 | </fieldset> |
| 36 | 35 | ||
diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index bba4fda074..0d7a4c35fa 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py | |||
| @@ -68,7 +68,7 @@ urlpatterns = patterns('toastergui.views', | |||
| 68 | 68 | ||
| 69 | # project URLs | 69 | # project URLs |
| 70 | url(r'^newproject/$', 'newproject', name='newproject'), | 70 | url(r'^newproject/$', 'newproject', name='newproject'), |
| 71 | url(r'^project/$', 'project', name='project'), | 71 | url(r'^project/(?P<pid>\d+)/$', 'project', name='project'), |
| 72 | 72 | ||
| 73 | # default redirection | 73 | # default redirection |
| 74 | url(r'^$', RedirectView.as_view( url= 'builds/')), | 74 | url(r'^$', RedirectView.as_view( url= 'builds/')), |
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index a57f001459..8fbe8a3640 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
| @@ -22,11 +22,13 @@ | |||
| 22 | import operator,re | 22 | import operator,re |
| 23 | 23 | ||
| 24 | from django.db.models import Q, Sum | 24 | from django.db.models import Q, Sum |
| 25 | from django.db import IntegrityError | ||
| 25 | from django.shortcuts import render, redirect | 26 | from django.shortcuts import render, redirect |
| 26 | from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable | 27 | from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable |
| 27 | from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency | 28 | from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency |
| 28 | from orm.models import Target_Installed_Package, Target_File, Target_Image_File | 29 | from orm.models import Target_Installed_Package, Target_File, Target_Image_File |
| 29 | from django.views.decorators.cache import cache_control | 30 | from django.views.decorators.cache import cache_control |
| 31 | from django.core.urlresolvers import reverse | ||
| 30 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | 32 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
| 31 | from django.http import HttpResponseBadRequest | 33 | from django.http import HttpResponseBadRequest |
| 32 | from django.utils import timezone | 34 | from django.utils import timezone |
| @@ -68,7 +70,6 @@ def _verify_parameters(g, mandatory_parameters): | |||
| 68 | 70 | ||
| 69 | def _redirect_parameters(view, g, mandatory_parameters, *args, **kwargs): | 71 | def _redirect_parameters(view, g, mandatory_parameters, *args, **kwargs): |
| 70 | import urllib | 72 | import urllib |
| 71 | from django.core.urlresolvers import reverse | ||
| 72 | url = reverse(view, kwargs=kwargs) | 73 | url = reverse(view, kwargs=kwargs) |
| 73 | params = {} | 74 | params = {} |
| 74 | for i in g: | 75 | for i in g: |
| @@ -1772,6 +1773,16 @@ if toastermain.settings.MANAGED: | |||
| 1772 | from django.contrib.auth import authenticate, login | 1773 | from django.contrib.auth import authenticate, login |
| 1773 | from django.contrib.auth.decorators import login_required | 1774 | from django.contrib.auth.decorators import login_required |
| 1774 | 1775 | ||
| 1776 | import traceback | ||
| 1777 | |||
| 1778 | class BadParameterException(Exception): pass # error thrown on invalid POST requests | ||
| 1779 | |||
| 1780 | # the context processor that supplies data used across all the pages | ||
| 1781 | def managedcontextprocessor(request): | ||
| 1782 | return { | ||
| 1783 | "projects": Project.objects.all(), | ||
| 1784 | "MANAGED" : toastermain.settings.MANAGED | ||
| 1785 | } | ||
| 1775 | 1786 | ||
| 1776 | # new project | 1787 | # new project |
| 1777 | def newproject(request): | 1788 | def newproject(request): |
| @@ -1787,28 +1798,41 @@ if toastermain.settings.MANAGED: | |||
| 1787 | return render(request, template, context) | 1798 | return render(request, template, context) |
| 1788 | elif request.method == "POST": | 1799 | elif request.method == "POST": |
| 1789 | mandatory_fields = ['projectname', 'email', 'username', 'projectversion'] | 1800 | mandatory_fields = ['projectname', 'email', 'username', 'projectversion'] |
| 1790 | if reduce( lambda x, y: x and y, map(lambda x: x in request.POST and len(request.POST[x]) > 0, mandatory_fields)): | 1801 | try: |
| 1802 | # make sure we have values for all mandatory_fields | ||
| 1803 | if reduce( lambda x, y: x or y, map(lambda x: len(request.POST.get(x, '')) == 0, mandatory_fields)): | ||
| 1804 | # set alert for missing fields | ||
| 1805 | raise BadParameterException("Fields missing: " + | ||
| 1806 | ", ".join([x for x in mandatory_fields if len(request.POST.get(x, '')) == 0 ])) | ||
| 1807 | |||
| 1791 | if not request.user.is_authenticated(): | 1808 | if not request.user.is_authenticated(): |
| 1792 | user = authenticate(username = request.POST['username'], password = 'nopass') | 1809 | user = authenticate(username = request.POST['username'], password = 'nopass') |
| 1793 | if user is None: | 1810 | if user is None: |
| 1794 | user = User.objects.create_user(username = request.POST['username'], email = request.POST['email'], password = "nopass") | 1811 | user = User.objects.create_user(username = request.POST['username'], email = request.POST['email'], password = "nopass") |
| 1795 | raise Exception("User cannot be authed, creating") | 1812 | |
| 1796 | user = authenticate(username = request.POST['username'], password = '') | 1813 | user = authenticate(username = user.username, password = 'nopass') |
| 1797 | login(request, user) | 1814 | login(request, user) |
| 1798 | 1815 | ||
| 1799 | return redirect(project) | 1816 | # save the project |
| 1800 | else: | 1817 | prj = Project.objects.create_project(name = request.POST['projectname'], |
| 1801 | alerts = [] | 1818 | branch = request.POST['projectversion'].split(" ")[0], |
| 1802 | # set alerts for missing fields | 1819 | short_description=request.POST['projectversion'].split(" ")[1:]) |
| 1803 | map(lambda x: alerts.append('Field '+ x + ' not filled in') if not x in request.POST or len(request.POST[x]) == 0 else None, mandatory_fields) | 1820 | prj.user_id = request.user.pk |
| 1804 | # fill in new page with already submitted values | 1821 | prj.save() |
| 1822 | return redirect(reverse(project, args = (prj.pk,))) | ||
| 1823 | |||
| 1824 | except (IntegrityError, BadParameterException) as e: | ||
| 1825 | # fill in page with previously submitted values | ||
| 1805 | map(lambda x: context.__setitem__(x, request.POST[x]), mandatory_fields) | 1826 | map(lambda x: context.__setitem__(x, request.POST[x]), mandatory_fields) |
| 1806 | context['alerts'] = alerts | 1827 | if isinstance(e, IntegrityError) and "username" in str(e): |
| 1828 | context['alert'] = "Your chosen username is already used" | ||
| 1829 | else: | ||
| 1830 | context['alert'] = str(e) | ||
| 1807 | return render(request, template, context) | 1831 | return render(request, template, context) |
| 1808 | raise Exception("Invalid HTTP method for this page") | 1832 | raise Exception("Invalid HTTP method for this page") |
| 1809 | 1833 | ||
| 1810 | # Shows the edit project page | 1834 | # Shows the edit project page |
| 1811 | def project(request): | 1835 | def project(request, pid): |
| 1812 | template = "project.html" | 1836 | template = "project.html" |
| 1813 | context = {} | 1837 | context = {} |
| 1814 | return render(request, template, context) | 1838 | return render(request, template, context) |
