summaryrefslogtreecommitdiffstats
path: root/bitbake
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:05:36 +0100
commit441f04ce97d12fd6b5f6cad9e23afe7080939092 (patch)
tree9800ec5a4d7976d833bc777e33e2f06cc673b0b1 /bitbake
parent30f9f79fb96db0149a776f02f4774750653fd964 (diff)
downloadpoky-441f04ce97d12fd6b5f6cad9e23afe7080939092.tar.gz
bitbake: 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>. (Bitbake rev: 38f935647dd768a912b933adebfc9cb225a01a54) 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 'bitbake')
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py49
1 files changed, 32 insertions, 17 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index 67c84b2934..d9802f01b8 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -1897,6 +1897,10 @@ if True:
1897 pass 1897 pass
1898 1898
1899 # shows the "all builds" page for managed mode; it displays build requests (at least started!) instead of actual builds 1899 # shows the "all builds" page for managed mode; it displays build requests (at least started!) instead of actual builds
1900 # WARNING _build_list_helper() may raise a RedirectException, which
1901 # will set the GET parameters and redirect back to the
1902 # all-builds or projectbuilds page as appropriate;
1903 # TODO don't use exceptions to control program flow
1900 @_template_renderer("builds.html") 1904 @_template_renderer("builds.html")
1901 def builds(request): 1905 def builds(request):
1902 # define here what parameters the view needs in the GET portion in order to 1906 # define here what parameters the view needs in the GET portion in order to
@@ -1905,27 +1909,35 @@ if True:
1905 1909
1906 queryset = Build.objects.all() 1910 queryset = Build.objects.all()
1907 1911
1908 try: 1912 redirect_page = resolve(request.path_info).url_name
1909 context, pagesize, orderby = _build_list_helper(request, queryset) 1913
1910 # all builds page as a Project column 1914 context, pagesize, orderby = _build_list_helper(request,
1911 context['tablecols'].append({'name': 'Project', 'clcalss': 'project_column', }) 1915 queryset,
1912 except RedirectException as re: 1916 redirect_page)
1913 # rewrite the RedirectException 1917 # all builds page as a Project column
1914 re.view = resolve(request.path_info).url_name 1918 context['tablecols'].append({
1915 raise re 1919 'name': 'Project',
1920 'clclass': 'project_column'
1921 })
1916 1922
1917 _set_parameters_values(pagesize, orderby, request) 1923 _set_parameters_values(pagesize, orderby, request)
1918 return context 1924 return context
1919 1925
1920 1926
1921 # helper function, to be used on "all builds" and "project builds" pages 1927 # helper function, to be used on "all builds" and "project builds" pages
1922 def _build_list_helper(request, queryset_all): 1928 def _build_list_helper(request, queryset_all, redirect_page, pid=None):
1923 default_orderby = 'completed_on:-' 1929 default_orderby = 'completed_on:-'
1924 (pagesize, orderby) = _get_parameters_values(request, 10, default_orderby) 1930 (pagesize, orderby) = _get_parameters_values(request, 10, default_orderby)
1925 mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby } 1931 mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' : orderby }
1926 retval = _verify_parameters( request.GET, mandatory_parameters ) 1932 retval = _verify_parameters( request.GET, mandatory_parameters )
1927 if retval: 1933 if retval:
1928 raise RedirectException( None, request.GET, mandatory_parameters) 1934 params = {}
1935 if pid:
1936 params = {'pid': pid}
1937 raise RedirectException(redirect_page,
1938 request.GET,
1939 mandatory_parameters,
1940 **params)
1929 1941
1930 # boilerplate code that takes a request for an object type and returns a queryset 1942 # boilerplate code that takes a request for an object type and returns a queryset
1931 # for that object type. copypasta for all needed table searches 1943 # for that object type. copypasta for all needed table searches
@@ -2669,6 +2681,10 @@ if True:
2669 2681
2670 return context 2682 return context
2671 2683
2684 # WARNING _build_list_helper() may raise a RedirectException, which
2685 # will set the GET parameters and redirect back to the
2686 # all-builds or projectbuilds page as appropriate;
2687 # TODO don't use exceptions to control program flow
2672 @_template_renderer('projectbuilds.html') 2688 @_template_renderer('projectbuilds.html')
2673 def projectbuilds(request, pid): 2689 def projectbuilds(request, pid):
2674 prj = Project.objects.get(id = pid) 2690 prj = Project.objects.get(id = pid)
@@ -2708,13 +2724,12 @@ if True:
2708 2724
2709 queryset = Build.objects.filter(project_id = pid) 2725 queryset = Build.objects.filter(project_id = pid)
2710 2726
2711 try: 2727 redirect_page = resolve(request.path_info).url_name
2712 context, pagesize, orderby = _build_list_helper(request, queryset) 2728
2713 except RedirectException as re: 2729 context, pagesize, orderby = _build_list_helper(request,
2714 # rewrite the RedirectException with our current url information 2730 queryset,
2715 re.view = resolve(request.path_info).url_name 2731 redirect_page,
2716 re.okwargs = {"pid" : pid} 2732 pid)
2717 raise re
2718 2733
2719 context['project'] = prj 2734 context['project'] = prj
2720 _set_parameters_values(pagesize, orderby, request) 2735 _set_parameters_values(pagesize, orderby, request)