summaryrefslogtreecommitdiff
path: root/lib/toaster
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2015-09-04 10:37:47 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-18 09:04:25 +0100
commit38f935647dd768a912b933adebfc9cb225a01a54 (patch)
tree6a35fd388fda800b02d9c6ba4989f524c3f52c2e /lib/toaster
parentfe9a554249b623ef515502043fdbf50e1ac62a3a (diff)
downloadbitbake-38f935647dd768a912b933adebfc9cb225a01a54.zip
toaster: Simplify redirects when build page parameters are missing
A RedirectException is used to redirect the client to the correct page when their original request is missing the required parameters (page, orderby etc.). However, the code is difficult to follow. Rather than catching RedirectExceptions and rethrowing them with different view URLs, ensure that the RedirectException has the correct URL in it when thrown by passing the original page name to the _build_list_helper() method. Modified from an original patch by David Reyna <david.reyna@windriver.com>. Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: brian avery <avery.brian@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/toaster')
-rwxr-xr-xlib/toaster/toastergui/views.py49
1 files changed, 32 insertions, 17 deletions
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 67c84b29..d9802f01 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -1897,6 +1897,10 @@ if True:
pass
# shows the "all builds" page for managed mode; it displays build requests (at least started!) instead of actual builds
+ # WARNING _build_list_helper() may raise a RedirectException, which
+ # will set the GET parameters and redirect back to the
+ # all-builds or projectbuilds page as appropriate;
+ # TODO don't use exceptions to control program flow
@_template_renderer("builds.html")
def builds(request):
# define here what parameters the view needs in the GET portion in order to
@@ -1905,27 +1909,35 @@ if True:
queryset = Build.objects.all()
- try:
- context, pagesize, orderby = _build_list_helper(request, queryset)
- # all builds page as a Project column
- context['tablecols'].append({'name': 'Project', 'clcalss': 'project_column', })
- except RedirectException as re:
- # rewrite the RedirectException
- re.view = resolve(request.path_info).url_name
- raise re
+ redirect_page = resolve(request.path_info).url_name
+
+ context, pagesize, orderby = _build_list_helper(request,
+ queryset,
+ redirect_page)
+ # all builds page as a Project column
+ context['tablecols'].append({
+ 'name': 'Project',
+ 'clclass': 'project_column'
+ })
_set_parameters_values(pagesize, orderby, request)
return context
# helper function, to be used on "all builds" and "project builds" pages
- def _build_list_helper(request, queryset_all):
+ def _build_list_helper(request, queryset_all, redirect_page, pid=None):
default_orderby = 'completed_on:-'
(pagesize, orderby) = _get_parameters_values(request, 10, default_orderby)
mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
retval = _verify_parameters( request.GET, mandatory_parameters )
if retval:
- raise RedirectException( None, request.GET, mandatory_parameters)
+ params = {}
+ if pid:
+ params = {'pid': pid}
+ raise RedirectException(redirect_page,
+ request.GET,
+ mandatory_parameters,
+ **params)
# boilerplate code that takes a request for an object type and returns a queryset
# for that object type. copypasta for all needed table searches
@@ -2669,6 +2681,10 @@ if True:
return context
+ # WARNING _build_list_helper() may raise a RedirectException, which
+ # will set the GET parameters and redirect back to the
+ # all-builds or projectbuilds page as appropriate;
+ # TODO don't use exceptions to control program flow
@_template_renderer('projectbuilds.html')
def projectbuilds(request, pid):
prj = Project.objects.get(id = pid)
@@ -2708,13 +2724,12 @@ if True:
queryset = Build.objects.filter(project_id = pid)
- try:
- context, pagesize, orderby = _build_list_helper(request, queryset)
- except RedirectException as re:
- # rewrite the RedirectException with our current url information
- re.view = resolve(request.path_info).url_name
- re.okwargs = {"pid" : pid}
- raise re
+ redirect_page = resolve(request.path_info).url_name
+
+ context, pagesize, orderby = _build_list_helper(request,
+ queryset,
+ redirect_page,
+ pid)
context['project'] = prj
_set_parameters_values(pagesize, orderby, request)