Skip to contentSkip to conversation

toaster: use cookies for count and sorting in templates tables

PATCH Superseded Marius Avram 2 participants 3 messages Aug 29, 2014 – Sep 1, 2014 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 toaster: use cookies for count and sorting in templates tables

Until now cookies were used to save which columns were shown and which were hidden in toaster tables. The tables from the templates also have functionalities like sorting the entries on a certain column and limiting the number of entries displayed on a page. The later however were not saved using cookies. This patch brings this new feature.

The cookies are not saved only in the front-end. They are saved both in the frontend in case the user uses the inputs/buttons to change a parameter and also in the backend in case the user specifies manually using GET variables the value of the parameters.

When no GET parameters are given the views will redirect the url to one containg the parameters saved as cookies. When no cookies exist, default values will be used.

[YOCTO #6126]

---
 .../toastergui/templates/basetable_bottom.html     |   56 +++++----
 .../toastergui/templates/basetable_top.html        |   18 ++-
 bitbake/lib/toaster/toastergui/views.py            |  128 +++++++++++++-------
 3 files changed, 135 insertions(+), 67 deletions(-)
bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +35 -21
index ac14363..bccb77a 100644
@@ -23,13 +23,14 @@
 {%endif%}
   </ul>
   <div class="pull-right">
-                            <span class="help-inline" style="padding-top:5px;">Show rows:</span>
-                            <select style="margin-top:5px;margin-bottom:0px;" class="pagesize">
-  {% with "2 5 10 25 50 100" as list%}
-    {% for i in list.split %}<option{%if i == request.GET.count %} selected{%endif%}>{{i}}</option>
-    {% endfor %}
-  {% endwith %}
-                            </select>
+    <span class="help-inline" style="padding-top:5px;">Show rows:</span>
+      <select style="margin-top:5px;margin-bottom:0px;" class="pagesize">
+        {% with "2 5 10 25 50 100" as list%}
+          {% for i in list.split %}
+            <option value="{{ i }}">{{i}}</option>
+          {% endfor %}
+        {% endwith %}
+     </select>
    </div>
 </div>
 
@@ -40,21 +41,33 @@
 
     // we load cookies for the column display
     save = $.cookie('_displaycols_{{objectname}}');
-		if (save != undefined) {
-    setting = save.split(';');
-    for ( i = 0; i < setting.length; i++) {
-        if (setting[i].length > 0) {
-            splitlist = setting[i].split(':');
-            id = splitlist[0], v = splitlist[1];
-            if (v == 'true') {
-                $('.chbxtoggle#'+id).prop('checked', true);
-            }
-            else {
-                $('.chbxtoggle#'+id).prop('checked', false);
+    if (save != undefined) {
+        setting = save.split(';');
+        for ( i = 0; i < setting.length; i++) {
+            if (setting[i].length > 0) {
+                splitlist = setting[i].split(':');
+                id = splitlist[0], v = splitlist[1];
+                if (v == 'true') {
+                    $('.chbxtoggle#'+id).prop('checked', true);
+                }
+                else {
+                    $('.chbxtoggle#'+id).prop('checked', false);
+                }
             }
         }
     }
-    }
+
+    // load cookie for number of entries to be displayed on page
+    pagesize = $.cookie('count');
+    if (!pagesize)
+        pagesize = 10;
+    console.log("pagesize " + pagesize);
+    $('.pagesize option').prop('selected', false)
+                         .filter('[value="' + pagesize + '"]')
+                         .attr('selected', true);
+
+    // save cookie for sorting table (orderby)
+
 
     $('.chbxtoggle').each(function () {
         showhideTableColumn($(this).attr('id'), $(this).is(':checked'))
@@ -72,8 +85,9 @@
     $('.progress, .lead span').tooltip({container:'table', placement:'top'});
 
     $(".pagesize").change(function () {
-        console.log("page size change");
-        reload_params({"count":$(this).val()}); ;
+        reload_params({"count":$(this).val()});
+        // save cookie with pagesize
+        $.cookie("count", $(this).val());
     });
 });
 </script>
bitbake/lib/toaster/toastergui/templates/basetable_top.html +13 -5
index 1231e1f..b76f578 100644
@@ -156,6 +156,13 @@
         showhideImmediateTableAction( clname, sh, orderkey );
     }
 
+    //
+    // saves a cookie with selected order field
+    //
+    function saveOrderCookie( orderfield ) {
+        $.cookie("orderby", orderfield);
+    }
+
     </script>
 
 <!-- control header -->
@@ -204,10 +211,11 @@
                 <span class="divider-vertical"></span>
                 <span class="help-inline" style="padding-top:5px;">Show rows:</span>
                 <select style="margin-top:5px;margin-bottom:0px;" class="pagesize">
-  {% with "2 5 10 25 50 100" as list%}
-{% for i in list.split %}                    <option{%if i == request.GET.count %} selected{%endif%}>{{i}}</option>
-    {% endfor %}
-  {% endwith %}
+                  {% with "2 5 10 25 50 100" as list%}
+                    {% for i in list.split %}
+                      <option value="{{ i }}">{{i}}</option>
+                    {% endfor %}
+                  {% endwith %}
                 </select>
            </div>
         </div>
@@ -221,7 +229,7 @@
         <tr>
             {% for tc in tablecols %}<th class="{{tc.dclass}} {{tc.clclass}}">
                 {%if tc.qhelp%}<i class="icon-question-sign get-help" title="{{tc.qhelp}}"></i>{%endif%}
-                {%if tc.orderfield%}<a {%if tc.ordericon%} class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" >{{tc.name}}</a>{%else%}<span class="muted">{{tc.name}}</span>{%endif%}
+                {%if tc.orderfield%}<a {%if tc.ordericon%} class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" onclick="saveOrderCookie('{{tc.orderfield}}')">{{tc.name}}</a>{%else%}<span class="muted">{{tc.name}}</span>{%endif%}
                 {%if tc.ordericon%} <i class="icon-caret-{{tc.ordericon}}"></i>{%endif%}
                 {%if tc.filter%}<div class="btn-group pull-right">
                     <a href="#filter_{{tc.filter.class}}" role="button" class="btn btn-mini {%if request.GET.filter%}{{tc.filter.options|filtered_icon:request.GET.filter}} {%endif%}" {%if request.GET.filter and tc.filter.options|filtered_tooltip:request.GET.filter %} title="<p>{{tc.filter.options|filtered_tooltip:request.GET.filter}}</p><p><a class='btn btn-small btn-primary' href=javascript:reload_params({'filter':''})>Show all {% if filter_search_display %}{{filter_search_display}}{% else %}{{objectname}}{% endif %}</a></p>" {%endif%} data-toggle="modal"> <i class="icon-filter filtered"></i> </a>
bitbake/lib/toaster/toastergui/views.py +87 -41

318 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

Just tested this, and found a couple of issues:

* The patches break all task-based pages (Tasks, Time, CPU usage and Disk I/O). This is the trace:

Environment:

Request Method: GET
Request URL:
http://localhost:8000/toastergui/build/16/tasks/?count=2&orderby=order%3A%2
B&page=1

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.staticfiles',
'django.contrib.humanize',
'orm',
'toastermain',
'toastergui',
'bldviewer',
'south',
'bldcontrol')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in tasks
1127. return tasks_common(request, build_id, 'tasks', '')
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in tasks_common
1122. f = open("/home/marius/file.txt", "w")

Exception Type: IOError at /toastergui/build/16/tasks/ Exception Value: [Errno 2] No such file or directory:
'/home/marius/file.txt'

* Everything seems to work great in the Recipes and Packages pages but, if I set a "Show rows" value for the BitBake variables table in the Configuration page, that value overrides the value of show rows menu in the Recipes and Packages pages. To test this, go to the variables table and set the show rows menu to '5', then go to the Recipes page. Independently of the value set in the show rows menu in the Recipes page, I only see 5 recipes.

* The value of the show rows menu is not kept for the Packages included table in the image page.

* The breadcrumb of the package installed details page (package_included_detail) is broken. Go to a package and click on the image name in the breadcrumb to check this out. This is the trace

Environment:

Request Method: GET
Request URL:
http://localhost:8000/toastergui/build/16/target/17?count=5&orderby=size%25
3A-&page=1

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.staticfiles',
'django.contrib.humanize',
'orm',
'toastermain',
'toastergui',
'bldviewer',
'south',
'bldcontrol')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in target
740. return( target_common( request, build_id, target_id, "target" ))
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in target_common
583. ( filter_string, search_term, ordering_string ) =
_search_tuple( request, Package )
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in _search_tuple
170. raise BaseException("Invalid ordering model:" + str(model)
+ str(invalid))

Exception Type: BaseException at /toastergui/build/16/target/17 Exception Value: Invalid ordering model:<class 'orm.models.Package'>We have an invalid number of separators: size%3A- -> [u'size%3A-']

Cheers

Belén

Quoted 631 lines · Marius Avram

Until now cookies were used to save which columns were shown and which were hidden in toaster tables. The tables from the templates also have functionalities like sorting the entries on a certain column and limiting the number of entries displayed on a page. The later however were not saved using cookies. This patch brings this new feature.

The cookies are not saved only in the front-end. They are saved both in the frontend in case the user uses the inputs/buttons to change a parameter and also in the backend in case the user specifies manually using GET variables the value of the parameters.

When no GET parameters are given the views will redirect the url to one containg the parameters saved as cookies. When no cookies exist, default values will be used.

[YOCTO #6126]

---

.../toastergui/templates/basetable_bottom.html     |   56 +++++----
.../toastergui/templates/basetable_top.html        |   18 ++-
bitbake/lib/toaster/toastergui/views.py            |  128
+++++++++++++-------
3 files changed, 135 insertions(+), 67 deletions(-)
(quoted diff) +0 -0

a/bitbake/lib/toaster/toastergui/templates/basetable_bottom.html b/bitbake/lib/toaster/toastergui/templates/basetable_bottom.html index ac14363..bccb77a 100644

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +0 -1
@@ -23,13 +23,14 @@
 {%endif%}
  </ul>
  <div class="pull-right">
-                            <span class="help-inline"

style="padding-top:5px;">Show rows:</span>
- <select
style="margin-top:5px;margin-bottom:0px;" class="pagesize">

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +0 -2
-  {% with "2 5 10 25 50 100" as list%}
-    {% for i in list.split %}<option{%if i == request.GET.count %}

selected{%endif%}>{{i}}</option>

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +8 -3
-    {% endfor %}
-  {% endwith %}
-                            </select>
+    <span class="help-inline" style="padding-top:5px;">Show rows:</span>
+      <select style="margin-top:5px;margin-bottom:0px;" class="pagesize">
+        {% with "2 5 10 25 50 100" as list%}
+          {% for i in list.split %}
+            <option value="{{ i }}">{{i}}</option>
+          {% endfor %}
+        {% endwith %}
+     </select>
   </div>

</div>

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +27 -14
@@ -40,21 +41,33 @@
 
    // we load cookies for the column display
    save = $.cookie('_displaycols_{{objectname}}');
-		if (save != undefined) {
-    setting = save.split(';');
-    for ( i = 0; i < setting.length; i++) {
-        if (setting[i].length > 0) {
-            splitlist = setting[i].split(':');
-            id = splitlist[0], v = splitlist[1];
-            if (v == 'true') {
-                $('.chbxtoggle#'+id).prop('checked', true);
-            }
-            else {
-                $('.chbxtoggle#'+id).prop('checked', false);
+    if (save != undefined) {
+        setting = save.split(';');
+        for ( i = 0; i < setting.length; i++) {
+            if (setting[i].length > 0) {
+                splitlist = setting[i].split(':');
+                id = splitlist[0], v = splitlist[1];
+                if (v == 'true') {
+                    $('.chbxtoggle#'+id).prop('checked', true);
+                }
+                else {
+                    $('.chbxtoggle#'+id).prop('checked', false);
+                }
            }
        }
    }
-    }
+
+    // load cookie for number of entries to be displayed on page
+    pagesize = $.cookie('count');
+    if (!pagesize)
+        pagesize = 10;
+    console.log("pagesize " + pagesize);
+    $('.pagesize option').prop('selected', false)
+                         .filter('[value="' + pagesize + '"]')
+                         .attr('selected', true);
+
+    // save cookie for sorting table (orderby)
+
 
    $('.chbxtoggle').each(function () {
        showhideTableColumn($(this).attr('id'), $(this).is(':checked'))
@@ -72,8 +85,9 @@
    $('.progress, .lead span').tooltip({container:'table',
 placement:'top'});
 
    $(".pagesize").change(function () {
-        console.log("page size change");
-        reload_params({"count":$(this).val()}); ;
+        reload_params({"count":$(this).val()});
+        // save cookie with pagesize
+        $.cookie("count", $(this).val());
    });
 });

</script>

bitbake/lib/toaster/toastergui/templates/basetable_top.html +7 -0
index 1231e1f..b76f578 100644
@@ -156,6 +156,13 @@
        showhideImmediateTableAction( clname, sh, orderkey );
    }
 
+    //
+    // saves a cookie with selected order field
+    //
+    function saveOrderCookie( orderfield ) {
+        $.cookie("orderby", orderfield);
+    }
+
    </script>
 

<!-- control header -->

bitbake/lib/toaster/toastergui/templates/basetable_top.html +0 -0
@@ -204,10 +211,11 @@
                <span class="divider-vertical"></span>
                <span class="help-inline" style="padding-top:5px;">Show

rows:</span>
<select style="margin-top:5px;margin-bottom:0px;"
class="pagesize">

bitbake/lib/toaster/toastergui/templates/basetable_top.html +0 -2
-  {% with "2 5 10 25 50 100" as list%}
-{% for i in list.split %}                    <option{%if i ==

request.GET.count %} selected{%endif%}>{{i}}</option>

bitbake/lib/toaster/toastergui/templates/basetable_top.html +5 -2
-    {% endfor %}
-  {% endwith %}
+                  {% with "2 5 10 25 50 100" as list%}
+                    {% for i in list.split %}
+                      <option value="{{ i }}">{{i}}</option>
+                    {% endfor %}
+                  {% endwith %}
                </select>
           </div>
        </div>
@@ -221,7 +229,7 @@
        <tr>
            {% for tc in tablecols %}<th class="{{tc.dclass}}

{{tc.clclass}}">
{%if tc.qhelp%}<i class="icon-question-sign get-help"
title="{{tc.qhelp}}"></i>{%endif%}
- {%if tc.orderfield%}<a {%if tc.ordericon%}
class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" >{{tc.name}}</a>{%else%}<span class="muted">{{tc.name}}</span>{%endif%}
+ {%if tc.orderfield%}<a {%if tc.ordericon%}
class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" onclick="saveOrderCookie('{{tc.orderfield}}')">{{tc.name}}</a>{%else%}<spa n class="muted">{{tc.name}}</span>{%endif%}

                {%if tc.ordericon%} <i

class="icon-caret-{{tc.ordericon}}"></i>{%endif%}
{%if tc.filter%}<div class="btn-group pull-right">
<a href="#filter_{{tc.filter.class}}" role="button"
class="btn btn-mini {%if request.GET.filter%}{{tc.filter.options|filtered_icon:request.GET.filter}} {%endif%}" {%if request.GET.filter and tc.filter.options|filtered_tooltip:request.GET.filter %} title="<p>{{tc.filter.options|filtered_tooltip:request.GET.filter}}</p><p> <a class='btn btn-small btn-primary' href=javascript:reload_params({'filter':''})>Show all {% if filter_search_display %}{{filter_search_display}}{% else %}{{objectname}}{% endif %}</a></p>" {%endif%} data-toggle="modal"> <i class="icon-filter filtered"></i> </a>

bitbake/lib/toaster/toastergui/views.py +0 -0
index bd65c08..6b46a03 100755
@@ -20,6 +20,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 

import operator,re
+import HTMLParser

from django.db.models import Q, Sum
from django.db import IntegrityError

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -32,6 +33,7 @@ from django.core.urlresolvers import reverse

from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.http import HttpResponseBadRequest, HttpResponseNotFound from django.utils import timezone
+from django.utils.html import escape
from datetime import timedelta
from django.utils import formats
import json

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -200,6 +202,26 @@ def _get_queryset(model, queryset, filter_string,
 search_term, ordering_string,
    # insure only distinct records (e.g. from multiple search hits) are

returned
return queryset.distinct()

+# returns the value of entries per page and the name of the applied sorting field.
+# if the value is given explicitly as a GET parameter it will be the first selected,

bitbake/lib/toaster/toastergui/views.py +3 -0
+# otherwise the cookie value will be used.
+def _get_parameters_values(request, default_count, default_order):
+    pagesize = request.GET.get('count', request.COOKIES.get('count',

default_count))
+ orderby = request.GET.get('orderby', request.COOKIES.get('orderby',
default_order))

bitbake/lib/toaster/toastergui/views.py +13 -0
+    return (pagesize, orderby)
+
+
+# set cookies for parameters. this is usefull in case parameters are set
+# manually from the GET values of the link
+def _save_parameters_cookies(response, pagesize, orderby, request):
+    html_parser = HTMLParser.HTMLParser()
+    # last '/' not used in jQuery path
+    request_path = request.path
+    if request_path.endswith('/'):
+        request_path = request.path[0:-1]
+    response.set_cookie(key='count', value=pagesize, path=request_path)
+    response.set_cookie(key='orderby',

value=html_parser.unescape(orderby), path=request_path)
+ return response

# shows the "all builds" page
def builds(request):
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -207,7 +229,8 @@ def builds(request):
    # define here what parameters the view needs in the GET portion in

order to

    # be able to display something.  'count' and 'page' are mandatory
for all views
    # that use paginators.
-    mandatory_parameters = { 'count': 10,  'page' : 1, 'orderby' :
'completed_on:-' };
+    (pagesize, orderby) = _get_parameters_values(request, 10,
'completed_on:-')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :
orderby }
    retval = _verify_parameters( request.GET, mandatory_parameters )
    if retval:
        return _redirect_parameters( 'all-builds', request.GET,
mandatory_parameters)
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -220,7 +243,7 @@ def builds(request):
    queryset = _get_queryset(Build, queryset_all, filter_string,
 search_term, ordering_string, '-completed_on')
 
    # retrieve the objects that will be displayed in the table; builds a

paginator and gets a page range to display
- build_info = _build_page_range(Paginator(queryset,
request.GET.get('count', 10)),request.GET.get('page', 1))
+ build_info = _build_page_range(Paginator(queryset, pagesize),
request.GET.get('page', 1))

    # build view-specific information; this is rendered specifically in
the builds page, at the top of the page (i.e. Recent builds)
    build_mru = 
Build.objects.filter(completed_on__gte=(timezone.now()-timedelta(hours=24)
)).order_by("-started_on")[:3]
bitbake/lib/toaster/toastergui/views.py +3 -1
@@ -379,7 +402,9 @@ def builds(request):
                ]
            }
 
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 
 
 ##
@@ -548,8 +573,8 @@ def recipe(request, build_id, recipe_id):
 

def target_common( request, build_id, target_id, variant ):
template = "target.html"

bitbake/lib/toaster/toastergui/views.py +0 -2
-    default_orderby = 'name:+';
-    mandatory_parameters = { 'count': 25,  'page' : 1,

'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'name:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby':

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters(

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -565,8 +590,7 @@ def target_common( request, build_id, target_id,

variant ):
packages_sum = queryset.aggregate( Sum( 'installed_size' )) queryset = _get_queryset(
Package, queryset, filter_string, search_term,
ordering_string, 'name' )

bitbake/lib/toaster/toastergui/views.py +0 -2
-    packages = _build_page_range( Paginator(
-            queryset, request.GET.get( 'count', 25 )),request.GET.get(

'page', 1 ))
+ packages = _build_page_range( Paginator(queryset, pagesize),
request.GET.get( 'page', 1 ))

    # bring in package dependencies
    for p in packages.object_list:
bitbake/lib/toaster/toastergui/views.py +5 -2
@@ -690,7 +714,7 @@ his package',
        'objects'              : packages,
        'packages_sum'         : packages_sum[ 'installed_size__sum' ],
        'object_search_display': "packages included",
-        'default_orderby'      : default_orderby,
+        'default_orderby'      : orderby,
        'tablecols'            : [
                    tc_package,
                    tc_packageVersion,
@@ -707,7 +731,10 @@ his package',
                    tc_layerDir,
                ]
        }
-    return( render( request, template, context ))
+
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def target( request, build_id, target_id ):
return( target_common( request, build_id, target_id, "target" ))

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -889,26 +916,25 @@ def tasks_common(request, build_id, variant,

task_anchor):
title_variant='Time'
object_search_display="time data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'elapsed_time:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'elapsed_time:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'elapsed_time:-')
elif 'diskio' == variant:
title_variant='Disk I/O'
object_search_display="disk I/O data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'disk_io:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'disk_io:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'disk_io:-')
elif 'cpuusage' == variant:
title_variant='CPU usage'
object_search_display="CPU usage data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'cpu_usage:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'cpu_usage:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'cpu_usage:-')
else :
title_variant='Tasks'
object_search_display="tasks"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'order:+'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'order:+';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'order:+')

bitbake/lib/toaster/toastergui/views.py +3 -0
+
+
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby':

orderby }

template = 'tasks.html'
retval = _verify_parameters( request.GET, mandatory_parameters )

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -934,7 +960,7 @@ def tasks_common(request, build_id, variant,

task_anchor):

        del request.GET['anchor']
        i=0
        a=int(anchor)
bitbake/lib/toaster/toastergui/views.py +1 -1
-		count_per_page=int(request.GET.get('count', 100))
+		count_per_page=int(pagesize)
        for task in queryset.iterator():
            if a == task.order:
				new_page= (i / count_per_page ) + 1
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -943,7 +969,7 @@ def tasks_common(request, build_id, variant,

task_anchor):
return _redirect_parameters( variant, request.GET,
mandatory_parameters, build_id = build_id)

            i += 1

- tasks = _build_page_range(Paginator(queryset,
request.GET.get('count', 100)),request.GET.get('page', 1))
+ tasks = _build_page_range(Paginator(queryset,
pagesize),request.GET.get('page', 1))

    # define (and modify by variants) the 'tablecols' members
    tc_order={
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1074,7 +1100,7 @@ def tasks_common(request, build_id, variant,

task_anchor):

                'title': title_variant,
                'build': Build.objects.filter(pk=build_id)[0],
                'objects': tasks,
bitbake/lib/toaster/toastergui/views.py +1 -1
-                'default_orderby' : default_orderby,
+                'default_orderby' : orderby,
                'search_term': search_term,
                'total_count': queryset_with_search.count(),
                'tablecols':[
@@ -1091,7 +1117,11 @@ def tasks_common(request, build_id, variant,

task_anchor):

                    tc_log,
                ]}
bitbake/lib/toaster/toastergui/views.py +5 -1
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    f = open("/home/marius/file.txt", "w")
+    f.write("pagesize %s, orderby %s" % (pagesize, orderby))
+    return response

def tasks(request, build_id):
return tasks_common(request, build_id, 'tasks', '')

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1111,7 +1141,8 @@ def cpuusage(request, build_id):
 

def recipes(request, build_id):
template = 'recipes.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'recipes', request.GET,
mandatory_parameters, build_id = build_id)

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1119,7 +1150,7 @@ def recipes(request, build_id):
    queryset = 

Recipe.objects.filter(layer_version__id__in=Layer_Version.objects.filter(b uild=build_id))
queryset = _get_queryset(Recipe, queryset, filter_string,
search_term, ordering_string, 'name')

- recipes = _build_page_range(Paginator(queryset,
request.GET.get('count', 100)),request.GET.get('page', 1))
+ recipes = _build_page_range(Paginator(queryset,
pagesize),request.GET.get('page', 1))

    # prefetch the forward and reverse recipe dependencies
    deps = { }; revs = { }
bitbake/lib/toaster/toastergui/views.py +3 -2
@@ -1218,8 +1249,9 @@ def recipes(request, build_id):
            ]
        }
 
-    return render(request, template, context)
-
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def configuration(request, build_id):
template = 'configuration.html'

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1258,7 +1290,8 @@ def configuration(request, build_id):
 

def configvars(request, build_id):
template = 'configvars.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'variable_name:+', 'filter':'description__regex:.+'};
+ (pagesize, orderby) = _get_parameters_values(request, 100,
'variable_name:+')
+ mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' :
orderby, 'filter' : 'description__regex:.+' }
retval = _verify_parameters( request.GET, mandatory_parameters ) (filter_string, search_term, ordering_string) =
_search_tuple(request, Variable)
if retval:

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1273,7 +1306,7 @@ def configvars(request, build_id):
    # remove records where the value is empty AND there are no history

files
queryset =
queryset.exclude(variable_value='',vhistory__file_name__isnull=True)

- variables = _build_page_range(Paginator(queryset,
request.GET.get('count', 50)), request.GET.get('page', 1))
+ variables = _build_page_range(Paginator(queryset, pagesize),
request.GET.get('page', 1))

    # show all matching files (not just the last one)
    file_filter= search_term + ":"
bitbake/lib/toaster/toastergui/views.py +3 -2
@@ -1339,12 +1372,14 @@ def configvars(request, build_id):
                ],
            }
 
-    return render(request, template, context)
-
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def bpackage(request, build_id):
template = 'bpackage.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
+    mandatory_parameters = { 'count' : pagesize,  'page' : 1, 'orderby'

: orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'packages', request.GET,
mandatory_parameters, build_id = build_id)

bitbake/lib/toaster/toastergui/views.py +1 -1
@@ -1352,7 +1387,7 @@ def bpackage(request, build_id):
    queryset = Package.objects.filter(build =
 build_id).filter(size__gte=0)
    queryset = _get_queryset(Package, queryset, filter_string,
 search_term, ordering_string, 'name')
 
-    packages = _build_page_range(Paginator(queryset,
 request.GET.get('count', 100)),request.GET.get('page', 1))
+    packages = _build_page_range(Paginator(queryset,

pagesize),request.GET.get('page', 1))

context = {
'objectname': 'packages built',

bitbake/lib/toaster/toastergui/views.py +3 -1
@@ -1432,7 +1467,9 @@ def bpackage(request, build_id):
            ]
        }
 
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def bfile(request, build_id, package_id):
template = 'bfile.html'

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1587,7 +1624,8 @@ def package_built_detail(request, build_id,

package_id):

    # follow convention for pagination w/ search although not used for
this view
    queryset = Package_File.objects.filter(package_id__exact=package_id)
-    mandatory_parameters = { 'count': 25,  'page' : 1,
'orderby':'path:+'};
bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'package_built_detail',
request.GET, mandatory_parameters, build_id = build_id, package_id = package_id)

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1618,7 +1656,10 @@ def package_built_detail(request, build_id,

package_id):

    }
    if paths.all().count() < 2:
        context['disable_sort'] = True;
bitbake/lib/toaster/toastergui/views.py +4 -1
-    return render(request, template, context)
+
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def package_built_dependencies(request, build_id, package_id):
template = "package_built_dependencies.html"

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1643,9 +1684,9 @@ def package_included_detail(request, build_id,

target_id, package_id):

    if Build.objects.filter(pk=build_id).count() == 0 :
        return redirect(builds)

-

    # follow convention for pagination w/ search although not used for
this view
-    mandatory_parameters = { 'count': 25,  'page' : 1,
'orderby':'path:+'};
bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'package_included_detail',
request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id)

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1680,8 +1721,10 @@ def package_included_detail(request, build_id,

target_id, package_id):

            ]
    }
    if paths.all().count() < 2:
bitbake/lib/toaster/toastergui/views.py +4 -2
-        context['disable_sort'] = True;
-    return render(request, template, context)
+        context['disable_sort'] = True
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def package_included_dependencies(request, build_id, target_id, package_id):
template = "package_included_dependencies.html"

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1710,7 +1753,8 @@ def package_included_reverse_dependencies(request,

build_id, target_id, package_

    if Build.objects.filter(pk=build_id).count() == 0 :
        return redirect(builds)

- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'package__name:+'};
+ (pagesize, orderby) = _get_parameters_values(request, 25,
'package__name:+')
+ mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby':
orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters(
'package_included_reverse_dependencies', request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id)

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1752,8 +1796,10 @@ def package_included_reverse_dependencies(request,

build_id, target_id, package_

            ]
    }
    if objects.all().count() < 2:
bitbake/lib/toaster/toastergui/views.py +4 -2
-        context['disable_sort'] = True;
-    return render(request, template, context)
+        context['disable_sort'] = True
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def image_information_dir(request, build_id, target_id, packagefile_id):

    # stubbed for now
Signature · 7 lines
1.7.9.5

-- 
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster
#3 lore raw
In reply to a message not in the archive

Marius, this is working great and can be merged.

Thanks!

Belén

Quoted 782 lines · Marius

I updated the branch and I sent the new patches to the toaster mailing list.
I guess you are using the poky contrib branch:
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=mavram/YB612
6

It should work now.

-----Original Message-----
From: Avram, Marius
Sent: Friday, August 29, 2014 2:02 PM
To: Barros Pena, Belen
Subject: RE: [Toaster] [PATCH] toaster: use cookies for count and sorting in templates tables

Sorry about that. Will fix during this day and I will send a v2 PATCH.

-----Original Message-----
From: Barros Pena, Belen
Sent: Friday, August 29, 2014 2:00 PM
To: Avram, Marius; [email protected]
Subject: Re: [Toaster] [PATCH] toaster: use cookies for count and sorting in templates tables

Just tested this, and found a couple of issues:

* The patches break all task-based pages (Tasks, Time, CPU usage and Disk I/O). This is the trace:

Environment:

Request Method: GET
Request URL:
http://localhost:8000/toastergui/build/16/tasks/?count=2&orderby=order%3A%
2
B&page=1

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.staticfiles', 'django.contrib.humanize',
'orm',
'toastermain',
'toastergui',
'bldviewer',
'south',
'bldcontrol')
Installed Middleware:
('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in tasks
1127. return tasks_common(request, build_id, 'tasks', '')
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in tasks_common
1122. f = open("/home/marius/file.txt", "w")

Exception Type: IOError at /toastergui/build/16/tasks/ Exception Value:
[Errno 2] No such file or directory:
'/home/marius/file.txt'

* Everything seems to work great in the Recipes and Packages pages but, if I set a "Show rows" value for the BitBake variables table in the Configuration page, that value overrides the value of show rows menu in the Recipes and Packages pages. To test this, go to the variables table and set the show rows menu to '5', then go to the Recipes page. Independently of the value set in the show rows menu in the Recipes page, I only see 5 recipes.

* The value of the show rows menu is not kept for the Packages included table in the image page.

* The breadcrumb of the package installed details page (package_included_detail) is broken. Go to a package and click on the image name in the breadcrumb to check this out. This is the trace

Environment:

Request Method: GET
Request URL:
http://localhost:8000/toastergui/build/16/target/17?count=5&orderby=size%2
5
3A-&page=1

Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.staticfiles', 'django.contrib.humanize',
'orm',
'toastermain',
'toastergui',
'bldviewer',
'south',
'bldcontrol')
Installed Middleware:
('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in target
740. return( target_common( request, build_id, target_id, "target"
))
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in target_common
583. ( filter_string, search_term, ordering_string ) =
_search_tuple( request, Package )
File "/home/yocto/poky/bitbake/lib/toaster/toastergui/views.py" in _search_tuple
170. raise BaseException("Invalid ordering model:" + str(model)
+ str(invalid))

Exception Type: BaseException at /toastergui/build/16/target/17 Exception
Value: Invalid ordering model:<class 'orm.models.Package'>We have an invalid number of separators: size%3A- -> [u'size%3A-']

Cheers

Belén

Quoted 637 lines · Marius Avram

Until now cookies were used to save which columns were shown and which were hidden in toaster tables. The tables from the templates also have functionalities like sorting the entries on a certain column and limiting the number of entries displayed on a page. The later however were not saved using cookies. This patch brings this new feature.

The cookies are not saved only in the front-end. They are saved both in the frontend in case the user uses the inputs/buttons to change a parameter and also in the backend in case the user specifies manually using GET variables the value of the parameters.

When no GET parameters are given the views will redirect the url to one containg the parameters saved as cookies. When no cookies exist, default values will be used.

[YOCTO #6126]

---

.../toastergui/templates/basetable_bottom.html     |   56 +++++----
.../toastergui/templates/basetable_top.html        |   18 ++-
bitbake/lib/toaster/toastergui/views.py            |  128
+++++++++++++-------
3 files changed, 135 insertions(+), 67 deletions(-)

diff --git a/bitbake/lib/toaster/toastergui/templates/basetable_bottom.html b/bitbake/lib/toaster/toastergui/templates/basetable_bottom.html index ac14363..bccb77a 100644

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +0 -1
@@ -23,13 +23,14 @@
 {%endif%}
  </ul>
  <div class="pull-right">
-                            <span class="help-inline"

style="padding-top:5px;">Show rows:</span>
- <select
style="margin-top:5px;margin-bottom:0px;" class="pagesize">

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +0 -2
-  {% with "2 5 10 25 50 100" as list%}
-    {% for i in list.split %}<option{%if i == request.GET.count %}

selected{%endif%}>{{i}}</option>

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +2 -3
-    {% endfor %}
-  {% endwith %}
-                            </select>
+    <span class="help-inline" style="padding-top:5px;">Show rows:</span>
+      <select style="margin-top:5px;margin-bottom:0px;"

class="pagesize">

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +6 -0
+        {% with "2 5 10 25 50 100" as list%}
+          {% for i in list.split %}
+            <option value="{{ i }}">{{i}}</option>
+          {% endfor %}
+        {% endwith %}
+     </select>
   </div>

</div>

bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +24 -12
@@ -40,21 +41,33 @@
 
    // we load cookies for the column display
    save = $.cookie('_displaycols_{{objectname}}');
-		if (save != undefined) {
-    setting = save.split(';');
-    for ( i = 0; i < setting.length; i++) {
-        if (setting[i].length > 0) {
-            splitlist = setting[i].split(':');
-            id = splitlist[0], v = splitlist[1];
-            if (v == 'true') {
-                $('.chbxtoggle#'+id).prop('checked', true);
-            }
-            else {
-                $('.chbxtoggle#'+id).prop('checked', false);
+    if (save != undefined) {
+        setting = save.split(';');
+        for ( i = 0; i < setting.length; i++) {
+            if (setting[i].length > 0) {
+                splitlist = setting[i].split(':');
+                id = splitlist[0], v = splitlist[1];
+                if (v == 'true') {
+                    $('.chbxtoggle#'+id).prop('checked', true);
+                }
+                else {
+                    $('.chbxtoggle#'+id).prop('checked', false);
+                }
            }
        }
    }
-    }
+
+    // load cookie for number of entries to be displayed on page
+    pagesize = $.cookie('count');
+    if (!pagesize)
+        pagesize = 10;
+    console.log("pagesize " + pagesize);
+    $('.pagesize option').prop('selected', false)
+                         .filter('[value="' + pagesize + '"]')
+                         .attr('selected', true);
+
+    // save cookie for sorting table (orderby)
+
 
    $('.chbxtoggle').each(function () {
        showhideTableColumn($(this).attr('id'),

$(this).is(':checked')) @@ -72,8 +85,9 @@

    $('.progress, .lead span').tooltip({container:'table',

placement:'top'});

    $(".pagesize").change(function () {
bitbake/lib/toaster/toastergui/templates/basetable_bottom.html +3 -2
-        console.log("page size change");
-        reload_params({"count":$(this).val()}); ;
+        reload_params({"count":$(this).val()});
+        // save cookie with pagesize
+        $.cookie("count", $(this).val());
    });

});
</script>
diff --git a/bitbake/lib/toaster/toastergui/templates/basetable_top.html b/bitbake/lib/toaster/toastergui/templates/basetable_top.html index 1231e1f..b76f578 100644

bitbake/lib/toaster/toastergui/templates/basetable_top.html +7 -0
@@ -156,6 +156,13 @@
        showhideImmediateTableAction( clname, sh, orderkey );
    }
 
+    //
+    // saves a cookie with selected order field
+    //
+    function saveOrderCookie( orderfield ) {
+        $.cookie("orderby", orderfield);
+    }
+
    </script>
 

<!-- control header -->

bitbake/lib/toaster/toastergui/templates/basetable_top.html +0 -0
@@ -204,10 +211,11 @@
                <span class="divider-vertical"></span>
                <span class="help-inline"

style="padding-top:5px;">Show rows:</span>
<select style="margin-top:5px;margin-bottom:0px;"
class="pagesize">

bitbake/lib/toaster/toastergui/templates/basetable_top.html +0 -2
-  {% with "2 5 10 25 50 100" as list%}
-{% for i in list.split %}                    <option{%if i ==

request.GET.count %} selected{%endif%}>{{i}}</option>

bitbake/lib/toaster/toastergui/templates/basetable_top.html +5 -2
-    {% endfor %}
-  {% endwith %}
+                  {% with "2 5 10 25 50 100" as list%}
+                    {% for i in list.split %}
+                      <option value="{{ i }}">{{i}}</option>
+                    {% endfor %}
+                  {% endwith %}
                </select>
           </div>
        </div>
@@ -221,7 +229,7 @@
        <tr>
            {% for tc in tablecols %}<th class="{{tc.dclass}}

{{tc.clclass}}">
{%if tc.qhelp%}<i class="icon-question-sign get-help"
title="{{tc.qhelp}}"></i>{%endif%}
- {%if tc.orderfield%}<a {%if tc.ordericon%}
class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" >{{tc.name}}</a>{%else%}<span class="muted">{{tc.name}}</span>{%endif%}
+ {%if tc.orderfield%}<a {%if tc.ordericon%}
class="sorted" {%endif%}href="javascript:reload_params({'page': 1, 'orderby' : '{{tc.orderfield}}' })" onclick="saveOrderCookie('{{tc.orderfield}}')">{{tc.name}}</a>{%else%}< spa n class="muted">{{tc.name}}</span>{%endif%}

                {%if tc.ordericon%} <i

class="icon-caret-{{tc.ordericon}}"></i>{%endif%}
{%if tc.filter%}<div class="btn-group pull-right">
<a href="#filter_{{tc.filter.class}}" role="button"
class="btn btn-mini {%if request.GET.filter%}{{tc.filter.options|filtered_icon:request.GET.filte r}} {%endif%}" {%if request.GET.filter and tc.filter.options|filtered_tooltip:request.GET.filter %} title="<p>{{tc.filter.options|filtered_tooltip:request.GET.filter}}</p> <p>
<a class='btn btn-small btn-primary' href=javascript:reload_params({'filter':''})>Show all {% if filter_search_display %}{{filter_search_display}}{% else %}{{objectname}}{% endif %}</a></p>" {%endif%} data-toggle="modal"> <i class="icon-filter filtered"></i> </a> diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index bd65c08..6b46a03 100755

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -20,6 +20,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 

import operator,re
+import HTMLParser

from django.db.models import Q, Sum
from django.db import IntegrityError

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -32,6 +33,7 @@ from django.core.urlresolvers import reverse  from

django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.http import HttpResponseBadRequest, HttpResponseNotFound from django.utils import timezone
+from django.utils.html import escape
from datetime import timedelta
from django.utils import formats
import json

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -200,6 +202,26 @@ def _get_queryset(model, queryset, filter_string,
 search_term, ordering_string,
    # insure only distinct records (e.g. from multiple search hits)

are returned
return queryset.distinct()

+# returns the value of entries per page and the name of the applied sorting field.
+# if the value is given explicitly as a GET parameter it will be the first selected,

bitbake/lib/toaster/toastergui/views.py +3 -0
+# otherwise the cookie value will be used.
+def _get_parameters_values(request, default_count, default_order):
+    pagesize = request.GET.get('count', request.COOKIES.get('count',

default_count))
+ orderby = request.GET.get('orderby',
+ request.COOKIES.get('orderby',
default_order))

bitbake/lib/toaster/toastergui/views.py +13 -0
+    return (pagesize, orderby)
+
+
+# set cookies for parameters. this is usefull in case parameters are
+set # manually from the GET values of the link def
+_save_parameters_cookies(response, pagesize, orderby, request):
+    html_parser = HTMLParser.HTMLParser()
+    # last '/' not used in jQuery path
+    request_path = request.path
+    if request_path.endswith('/'):
+        request_path = request.path[0:-1]
+    response.set_cookie(key='count', value=pagesize, path=request_path)
+    response.set_cookie(key='orderby',

value=html_parser.unescape(orderby), path=request_path)
+ return response

# shows the "all builds" page
def builds(request):
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -207,7 +229,8 @@ def builds(request):
    # define here what parameters the view needs in the GET portion in

order to

    # be able to display something.  'count' and 'page' are mandatory
for all views
    # that use paginators.
-    mandatory_parameters = { 'count': 10,  'page' : 1, 'orderby' :
'completed_on:-' };
+    (pagesize, orderby) = _get_parameters_values(request, 10,
'completed_on:-')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :
orderby }
    retval = _verify_parameters( request.GET, mandatory_parameters )
    if retval:
        return _redirect_parameters( 'all-builds', request.GET,
mandatory_parameters)
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -220,7 +243,7 @@ def builds(request):
    queryset = _get_queryset(Build, queryset_all, filter_string,
 search_term, ordering_string, '-completed_on')
 
    # retrieve the objects that will be displayed in the table; builds

a paginator and gets a page range to display
- build_info = _build_page_range(Paginator(queryset,
request.GET.get('count', 10)),request.GET.get('page', 1))
+ build_info = _build_page_range(Paginator(queryset, pagesize),
request.GET.get('page', 1))

    # build view-specific information; this is rendered specifically
in the builds page, at the top of the page (i.e. Recent builds)
    build_mru =
Build.objects.filter(completed_on__gte=(timezone.now()-timedelta(hours=
24)
)).order_by("-started_on")[:3]
bitbake/lib/toaster/toastergui/views.py +3 -1
@@ -379,7 +402,9 @@ def builds(request):
                ]
            }
 
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 
 
 ##
@@ -548,8 +573,8 @@ def recipe(request, build_id, recipe_id):
 

def target_common( request, build_id, target_id, variant ):
template = "target.html"

bitbake/lib/toaster/toastergui/views.py +0 -2
-    default_orderby = 'name:+';
-    mandatory_parameters = { 'count': 25,  'page' : 1,

'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'name:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby':

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters(

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -565,8 +590,7 @@ def target_common( request, build_id, target_id,

variant ):
packages_sum = queryset.aggregate( Sum( 'installed_size' )) queryset = _get_queryset(
Package, queryset, filter_string, search_term,
ordering_string, 'name' )

bitbake/lib/toaster/toastergui/views.py +0 -2
-    packages = _build_page_range( Paginator(
-            queryset, request.GET.get( 'count', 25 )),request.GET.get(

'page', 1 ))
+ packages = _build_page_range( Paginator(queryset, pagesize),
request.GET.get( 'page', 1 ))

    # bring in package dependencies
    for p in packages.object_list:
bitbake/lib/toaster/toastergui/views.py +1 -1
@@ -690,7 +714,7 @@ his package',
        'objects'              : packages,
        'packages_sum'         : packages_sum[ 'installed_size__sum' ],
        'object_search_display': "packages included",
-        'default_orderby'      : default_orderby,
+        'default_orderby'      : orderby,
        'tablecols'            : [
                    tc_package,
                    tc_packageVersion, @@ -707,7 +731,10 @@ his

package',

                    tc_layerDir,
                ]
        }
bitbake/lib/toaster/toastergui/views.py +4 -1
-    return( render( request, template, context ))
+
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def target( request, build_id, target_id ):
return( target_common( request, build_id, target_id, "target" ))

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -889,26 +916,25 @@ def tasks_common(request, build_id, variant,

task_anchor):
title_variant='Time'
object_search_display="time data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'elapsed_time:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'elapsed_time:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'elapsed_time:-')
elif 'diskio' == variant:
title_variant='Disk I/O'
object_search_display="disk I/O data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'disk_io:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'disk_io:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'disk_io:-')
elif 'cpuusage' == variant:
title_variant='CPU usage'
object_search_display="CPU usage data"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'cpu_usage:-'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'cpu_usage:-';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'cpu_usage:-')
else :
title_variant='Tasks'
object_search_display="tasks"
filter_search_display="tasks"
- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'order:+'};

bitbake/lib/toaster/toastergui/views.py +1 -1
-        default_orderby = 'order:+';
+        (pagesize, orderby) = _get_parameters_values(request, 25,

'order:+')

bitbake/lib/toaster/toastergui/views.py +3 -0
+
+
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby':

orderby }

template = 'tasks.html'
retval = _verify_parameters( request.GET, mandatory_parameters )

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -934,7 +960,7 @@ def tasks_common(request, build_id, variant,

task_anchor):

        del request.GET['anchor']
        i=0
        a=int(anchor)
bitbake/lib/toaster/toastergui/views.py +1 -1
-		count_per_page=int(request.GET.get('count', 100))
+		count_per_page=int(pagesize)
        for task in queryset.iterator():
            if a == task.order:
				new_page= (i / count_per_page ) + 1 @@ -943,7 +969,7 @@ def

tasks_common(request, build_id, variant,
task_anchor):
return _redirect_parameters( variant, request.GET,
mandatory_parameters, build_id = build_id)

            i += 1

- tasks = _build_page_range(Paginator(queryset,
request.GET.get('count', 100)),request.GET.get('page', 1))
+ tasks = _build_page_range(Paginator(queryset,
pagesize),request.GET.get('page', 1))

    # define (and modify by variants) the 'tablecols' members
    tc_order={
bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1074,7 +1100,7 @@ def tasks_common(request, build_id, variant,

task_anchor):

                'title': title_variant,
                'build': Build.objects.filter(pk=build_id)[0],
                'objects': tasks,
bitbake/lib/toaster/toastergui/views.py +1 -1
-                'default_orderby' : default_orderby,
+                'default_orderby' : orderby,
                'search_term': search_term,
                'total_count': queryset_with_search.count(),
                'tablecols':[
@@ -1091,7 +1117,11 @@ def tasks_common(request, build_id, variant,

task_anchor):

                    tc_log,
                ]}
bitbake/lib/toaster/toastergui/views.py +5 -1
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    f = open("/home/marius/file.txt", "w")
+    f.write("pagesize %s, orderby %s" % (pagesize, orderby))
+    return response

def tasks(request, build_id):

    return tasks_common(request, build_id, 'tasks', '') @@ -1111,7

+1141,8 @@ def cpuusage(request, build_id):

def recipes(request, build_id):
template = 'recipes.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'recipes', request.GET,
mandatory_parameters, build_id = build_id) @@ -1119,7 +1150,7 @@ def recipes(request, build_id):
queryset =
Recipe.objects.filter(layer_version__id__in=Layer_Version.objects.filte r(b
uild=build_id))
queryset = _get_queryset(Recipe, queryset, filter_string,
search_term, ordering_string, 'name')

- recipes = _build_page_range(Paginator(queryset,
request.GET.get('count', 100)),request.GET.get('page', 1))
+ recipes = _build_page_range(Paginator(queryset,
pagesize),request.GET.get('page', 1))

    # prefetch the forward and reverse recipe dependencies
    deps = { }; revs = { }
bitbake/lib/toaster/toastergui/views.py +3 -2
@@ -1218,8 +1249,9 @@ def recipes(request, build_id):
            ]
        }
 
-    return render(request, template, context)
-
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def configuration(request, build_id):
template = 'configuration.html'

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1258,7 +1290,8 @@ def configuration(request, build_id):
 

def configvars(request, build_id):
template = 'configvars.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'variable_name:+', 'filter':'description__regex:.+'};
+ (pagesize, orderby) = _get_parameters_values(request, 100,
'variable_name:+')
+ mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby' :
orderby, 'filter' : 'description__regex:.+' }
retval = _verify_parameters( request.GET, mandatory_parameters ) (filter_string, search_term, ordering_string) =
_search_tuple(request, Variable)
if retval:

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1273,7 +1306,7 @@ def configvars(request, build_id):
    # remove records where the value is empty AND there are no history

files
queryset =
queryset.exclude(variable_value='',vhistory__file_name__isnull=True)

- variables = _build_page_range(Paginator(queryset,
request.GET.get('count', 50)), request.GET.get('page', 1))
+ variables = _build_page_range(Paginator(queryset, pagesize),
request.GET.get('page', 1))

    # show all matching files (not just the last one)
    file_filter= search_term + ":"
bitbake/lib/toaster/toastergui/views.py +3 -2
@@ -1339,12 +1372,14 @@ def configvars(request, build_id):
                ],
            }
 
-    return render(request, template, context)
-
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response
 

def bpackage(request, build_id):
template = 'bpackage.html'
- mandatory_parameters = { 'count': 100, 'page' : 1,
'orderby':'name:+'};

bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 100, 'name:+')
+    mandatory_parameters = { 'count' : pagesize,  'page' : 1, 'orderby'

: orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'packages', request.GET,
mandatory_parameters, build_id = build_id) @@ -1352,7 +1387,7 @@ def bpackage(request, build_id):
queryset = Package.objects.filter(build =
build_id).filter(size__gte=0)
queryset = _get_queryset(Package, queryset, filter_string,
search_term, ordering_string, 'name')

- packages = _build_page_range(Paginator(queryset,
request.GET.get('count', 100)),request.GET.get('page', 1))
+ packages = _build_page_range(Paginator(queryset,
pagesize),request.GET.get('page', 1))

    context = {
        'objectname': 'packages built', @@ -1432,7 +1467,9 @@ def
bpackage(request, build_id):
            ]
        }
bitbake/lib/toaster/toastergui/views.py +3 -1
-    return render(request, template, context)
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def bfile(request, build_id, package_id):
template = 'bfile.html'

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1587,7 +1624,8 @@ def package_built_detail(request, build_id,

package_id):

    # follow convention for pagination w/ search although not used for
this view
    queryset = Package_File.objects.filter(package_id__exact=package_id)
-    mandatory_parameters = { 'count': 25,  'page' : 1,
'orderby':'path:+'};
bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'package_built_detail',
request.GET, mandatory_parameters, build_id = build_id, package_id = package_id)

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1618,7 +1656,10 @@ def package_built_detail(request, build_id,

package_id):

    }
    if paths.all().count() < 2:
        context['disable_sort'] = True;
bitbake/lib/toaster/toastergui/views.py +4 -1
-    return render(request, template, context)
+
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def package_built_dependencies(request, build_id, package_id):
template = "package_built_dependencies.html"

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1643,9 +1684,9 @@ def package_included_detail(request, build_id,

target_id, package_id):

    if Build.objects.filter(pk=build_id).count() == 0 :
        return redirect(builds)

-

    # follow convention for pagination w/ search although not used for
this view
-    mandatory_parameters = { 'count': 25,  'page' : 1,
'orderby':'path:+'};
bitbake/lib/toaster/toastergui/views.py +2 -0
+    (pagesize, orderby) = _get_parameters_values(request, 25, 'path:+')
+    mandatory_parameters = { 'count': pagesize,  'page' : 1, 'orderby' :

orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters( 'package_included_detail',
request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id) @@ -1680,8 +1721,10 @@ def package_included_detail(request, build_id, target_id, package_id):

            ]
    }
    if paths.all().count() < 2:
bitbake/lib/toaster/toastergui/views.py +4 -2
-        context['disable_sort'] = True;
-    return render(request, template, context)
+        context['disable_sort'] = True
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def package_included_dependencies(request, build_id, target_id, package_id):
template = "package_included_dependencies.html"

bitbake/lib/toaster/toastergui/views.py +0 -0
@@ -1710,7 +1753,8 @@ def
 package_included_reverse_dependencies(request,

build_id, target_id, package_

    if Build.objects.filter(pk=build_id).count() == 0 :
        return redirect(builds)

- mandatory_parameters = { 'count': 25, 'page' : 1,
'orderby':'package__name:+'};
+ (pagesize, orderby) = _get_parameters_values(request, 25,
'package__name:+')
+ mandatory_parameters = { 'count': pagesize, 'page' : 1, 'orderby':
orderby }
retval = _verify_parameters( request.GET, mandatory_parameters ) if retval:
return _redirect_parameters(
'package_included_reverse_dependencies', request.GET, mandatory_parameters, build_id = build_id, target_id = target_id, package_id = package_id) @@ -1752,8 +1796,10 @@ def package_included_reverse_dependencies(request,
build_id, target_id, package_

            ]
    }
    if objects.all().count() < 2:
bitbake/lib/toaster/toastergui/views.py +4 -2
-        context['disable_sort'] = True;
-    return render(request, template, context)
+        context['disable_sort'] = True
+    response = render(request, template, context)
+    _save_parameters_cookies(response, pagesize, orderby, request)
+    return response

def image_information_dir(request, build_id, target_id, packagefile_id):

    # stubbed for now
--
1.7.9.5

--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster