Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 69F73E00C74; Fri, 18 Dec 2015 01:24:43 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [134.134.136.24 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 7F0DEE00AB7 for ; Fri, 18 Dec 2015 01:24:27 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 18 Dec 2015 01:24:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,445,1444719600"; d="scan'208";a="620057423" Received: from agusev-mobl2.ger.corp.intel.com (HELO lp.ger.corp.intel.com) ([10.252.27.121]) by FMSMGA003.fm.intel.com with ESMTP; 18 Dec 2015 01:24:25 -0800 From: Elliot Smith To: toaster@yoctoproject.org Date: Fri, 18 Dec 2015 09:23:55 +0000 Message-Id: <1450430639-14995-14-git-send-email-elliot.smith@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1450430639-14995-1-git-send-email-elliot.smith@intel.com> References: <1450430639-14995-1-git-send-email-elliot.smith@intel.com> Subject: [review-request][PATCH 13/17] toaster: toastergui Convert project builds page to ToasterTable X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2015 09:24:43 -0000 Use the all builds ToasterTable as the basis for the project builds ToasterTable. [YOCTO #8738] Signed-off-by: Elliot Smith --- .../toaster/toastergui/static/js/projecttopbar.js | 9 ++ bitbake/lib/toaster/toastergui/tables.py | 169 +++++++++++++++++---- .../toastergui/templates/baseprojectpage.html | 1 + .../toaster/toastergui/templates/mrb_section.html | 2 +- .../templates/projectbuilds-toastertable.html | 56 +++++++ bitbake/lib/toaster/toastergui/urls.py | 6 +- bitbake/lib/toaster/toastergui/views.py | 16 +- bitbake/lib/toaster/toastergui/widgets.py | 1 - 8 files changed, 223 insertions(+), 37 deletions(-) create mode 100644 bitbake/lib/toaster/toastergui/templates/projectbuilds-toastertable.html diff --git a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js index b6ad380..58a32a0 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js +++ b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js @@ -7,7 +7,10 @@ function projectTopBarInit(ctx) { var projectName = $("#project-name"); var projectNameFormToggle = $("#project-change-form-toggle"); var projectNameChangeCancel = $("#project-name-change-cancel"); + + // this doesn't exist for command-line builds var newBuildTargetInput = $("#build-input"); + var newBuildTargetBuildBtn = $("#build-button"); var selectedTarget; @@ -42,6 +45,12 @@ function projectTopBarInit(ctx) { $(this).parent().removeClass('active'); }); + if (!newBuildTargetInput.length) { + return; + } + + /* the following only applies for non-command-line projects */ + /* Recipe build input functionality */ if (ctx.numProjectLayers > 0 && ctx.machine){ newBuildTargetInput.removeAttr("disabled"); diff --git a/bitbake/lib/toaster/toastergui/tables.py b/bitbake/lib/toaster/toastergui/tables.py index b76d1aa..1449acc 100644 --- a/bitbake/lib/toaster/toastergui/tables.py +++ b/bitbake/lib/toaster/toastergui/tables.py @@ -23,9 +23,11 @@ from toastergui.widgets import ToasterTable from toastergui.querysetfilter import QuerysetFilter from orm.models import Recipe, ProjectLayer, Layer_Version, Machine, Project from orm.models import CustomImageRecipe, Package, Build, LogMessage, Task +from orm.models import ProjectTarget from django.db.models import Q, Max, Count from django.conf.urls import url -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, resolve +from django.http import HttpResponse from django.views.generic import TemplateView import itertools @@ -888,30 +890,45 @@ class BuildsTable(ToasterTable): def __init__(self, *args, **kwargs): super(BuildsTable, self).__init__(*args, **kwargs) self.default_orderby = '-completed_on' - self.title = 'All builds' self.static_context_extra['Build'] = Build self.static_context_extra['Task'] = Task + # attributes that are overridden in subclasses + + # title for the page + self.title = '' + + # 'project' or 'all'; determines how the mrb (most recent builds) + # section is displayed + self.mrb_type = '' + + def get_builds(self): + """ + overridden in ProjectBuildsTable to return builds for a + single project + """ + return Build.objects.all() + def get_context_data(self, **kwargs): context = super(BuildsTable, self).get_context_data(**kwargs) # for the latest builds section - queryset = Build.objects.all() + builds = self.get_builds() finished_criteria = Q(outcome=Build.SUCCEEDED) | Q(outcome=Build.FAILED) latest_builds = itertools.chain( - queryset.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), - queryset.filter(finished_criteria).order_by("-completed_on")[:3] + builds.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"), + builds.filter(finished_criteria).order_by("-completed_on")[:3] ) context['mru'] = list(latest_builds) - context['mrb_type'] = 'all' + context['mrb_type'] = self.mrb_type return context def setup_queryset(self, *args, **kwargs): - queryset = Build.objects.all() + queryset = self.get_builds() # don't include in progress builds queryset = queryset.exclude(outcome=Build.IN_PROGRESS) @@ -1033,19 +1050,6 @@ class BuildsTable(ToasterTable): {% endif %} ''' - project_template = ''' - {% load project_url_tag %} - - {{data.project.name}} - - {% if data.project.is_default %} - - {% endif %} - ''' - self.add_column(title='Outcome', help_text='Final state of the build (successful \ or failed)', @@ -1127,12 +1131,6 @@ class BuildsTable(ToasterTable): static_data_name='image_files', static_data_template=image_files_template) - self.add_column(title='Project', - hideable=True, - orderable=False, - static_data_name='project-name', - static_data_template=project_template) - def setup_filters(self, *args, **kwargs): # outcomes outcome_filter = TableFilter( @@ -1241,3 +1239,122 @@ class BuildsTable(ToasterTable): failed_tasks_filter.add_action(with_failed_tasks_action) failed_tasks_filter.add_action(without_failed_tasks_action) self.add_filter(failed_tasks_filter) + + def post(self, request, *args, **kwargs): + """ Process HTTP POSTs which make build requests """ + + project = Project.objects.get(pk=kwargs['pid']) + + if 'buildCancel' in request.POST: + for i in request.POST['buildCancel'].strip().split(" "): + try: + br = BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_QUEUED) + br.state = BuildRequest.REQ_DELETED + br.save() + except BuildRequest.DoesNotExist: + pass + + if 'buildDelete' in request.POST: + for i in request.POST['buildDelete'].strip().split(" "): + try: + BuildRequest.objects.select_for_update().get(project = project, pk = i, state__lte = BuildRequest.REQ_DELETED).delete() + except BuildRequest.DoesNotExist: + pass + + if 'targets' in request.POST: + ProjectTarget.objects.filter(project = project).delete() + s = str(request.POST['targets']) + for t in s.translate(None, ";%|\"").split(" "): + if ":" in t: + target, task = t.split(":") + else: + target = t + task = "" + ProjectTarget.objects.create(project = project, + target = target, + task = task) + project.schedule_build() + + # redirect back to builds page so any new builds in progress etc. + # are visible + response = HttpResponse() + response.status_code = 302 + response['Location'] = request.build_absolute_uri() + return response + +class AllBuildsTable(BuildsTable): + """ Builds page for all builds """ + + def __init__(self, *args, **kwargs): + super(AllBuildsTable, self).__init__(*args, **kwargs) + self.title = 'All project builds' + self.mrb_type = 'all' + + def setup_columns(self, *args, **kwargs): + """ + All builds page shows a column for the project + """ + + super(AllBuildsTable, self).setup_columns(*args, **kwargs) + + project_template = ''' + {% load project_url_tag %} + + {{data.project.name}} + + {% if data.project.is_default %} + + {% endif %} + ''' + + self.add_column(title='Project', + hideable=True, + orderable=False, + static_data_name='project-name', + static_data_template=project_template) + +class ProjectBuildsTable(BuildsTable): + """ + Builds page for a single project; a BuildsTable, with the queryset + filtered by project + """ + + def __init__(self, *args, **kwargs): + super(ProjectBuildsTable, self).__init__(*args, **kwargs) + self.title = 'All project builds' + self.mrb_type = 'project' + + # set from the querystring + self.project_id = None + + def setup_queryset(self, *args, **kwargs): + """ + NOTE: self.project_id must be set before calling super(), + as it's used in setup_queryset() + """ + self.project_id = kwargs['pid'] + super(ProjectBuildsTable, self).setup_queryset(*args, **kwargs) + + project = Project.objects.get(pk=self.project_id) + self.queryset = self.queryset.filter(project=project) + + def get_context_data(self, **kwargs): + """ + NOTE: self.project_id must be set before calling super(), + as it's used in get_context_data() + """ + self.project_id = kwargs['pid'] + + context = super(ProjectBuildsTable, self).get_context_data(**kwargs) + context['project'] = Project.objects.get(pk=self.project_id) + + return context + + def get_builds(self): + """ override: only return builds for the relevant project """ + + project = Project.objects.get(pk=self.project_id) + return Build.objects.filter(project=project) diff --git a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html index 1f45be4..b143b78 100644 --- a/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html +++ b/bitbake/lib/toaster/toastergui/templates/baseprojectpage.html @@ -1,4 +1,5 @@ {% extends "base.html" %} + {% load projecttags %} {% load humanize %} diff --git a/bitbake/lib/toaster/toastergui/templates/mrb_section.html b/bitbake/lib/toaster/toastergui/templates/mrb_section.html index 52b3f1a..2f4820c 100644 --- a/bitbake/lib/toaster/toastergui/templates/mrb_section.html +++ b/bitbake/lib/toaster/toastergui/templates/mrb_section.html @@ -6,7 +6,7 @@ {%if mru and mru.count > 0%} {%if mrb_type == 'project' %} -

+