diff options
author | Tim Laszlo <tim.laszlo@gmail.com> | 2012-06-01 17:05:58 -0500 |
---|---|---|
committer | Tim Laszlo <tim.laszlo@gmail.com> | 2012-06-01 17:06:16 -0500 |
commit | b7977ff7b228802ffd2b82bfd446b6afc6e8a091 (patch) | |
tree | b17b989f74b611c8d0eda29791e283ccf208fe1f /src/lib/Bcfg2/Server/Reports/reports/views.py | |
parent | 82388019f6d271e954c07260ed3a4578cc0c47e4 (diff) | |
download | bcfg2-b7977ff7b228802ffd2b82bfd446b6afc6e8a091.tar.gz bcfg2-b7977ff7b228802ffd2b82bfd446b6afc6e8a091.tar.bz2 bcfg2-b7977ff7b228802ffd2b82bfd446b6afc6e8a091.zip |
bcfg2-web: D=Make detailed client list sortable
Diffstat (limited to 'src/lib/Bcfg2/Server/Reports/reports/views.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Reports/reports/views.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/Bcfg2/Server/Reports/reports/views.py b/src/lib/Bcfg2/Server/Reports/reports/views.py index ccd71a60e..fd6f5443a 100644 --- a/src/lib/Bcfg2/Server/Reports/reports/views.py +++ b/src/lib/Bcfg2/Server/Reports/reports/views.py @@ -18,6 +18,9 @@ from django.db import connection from Bcfg2.Server.Reports.reports.models import * +__SORT_FIELDS__ = ( 'client', 'state', 'good', 'bad', 'modified', 'extra', \ + 'timestamp', 'server' ) + class PaginationError(Exception): """This error is raised when pagination cannot be completed.""" pass @@ -177,8 +180,29 @@ def client_detailed_list(request, timestamp=None, **kwargs): """ + try: + sort = request.GET['sort'] + if sort[0] == '-': + sort_key = sort[1:] + else: + sort_key = sort + if not sort_key in __SORT_FIELDS__: + raise ValueError + + if sort_key == "client": + kwargs['orderby'] = "%s__name" % sort + elif sort_key == "good": + kwargs['orderby'] = "%scount" % sort + elif sort_key in ["bad", "modified", "extra"]: + kwargs['orderby'] = "%s_entries" % sort + else: + kwargs['orderby'] = sort + kwargs['sort'] = sort + except (ValueError, KeyError): + kwargs['orderby'] = "client__name" + kwargs['sort'] = "client" + kwargs['interaction_base'] = Interaction.objects.interaction_per_client(timestamp).select_related() - kwargs['orderby'] = "client__name" kwargs['page_limit'] = 0 return render_history_view(request, 'clients/detailed-list.html', **kwargs) @@ -349,6 +373,8 @@ def render_history_view(request, template='clients/history.html', **kwargs): if 'orderby' in kwargs and kwargs['orderby']: iquery = iquery.order_by(kwargs['orderby']) + if 'sort' in kwargs: + context['sort'] = kwargs['sort'] if 'state' in kwargs and kwargs['state']: iquery = iquery.filter(state__exact=kwargs['state']) |