From c6493ad8abe2bf6a552f4ec62b7453f140ce7ea2 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Thu, 21 Jun 2007 19:07:40 +0000 Subject: [PATCH] Match I-D tracker search results better: * Don't sort by ballot ID. * dictsort by filename within 'primary_flag' sets inside the template. * Change myifchanged to not reset on the first cycle of a for loop. * Introduce cyclevalue tag, to get the current cycle color from the cycle node itself instead of the context, since the context gets reset between for loops. - Legacy-Id: 596 --- ietf/idtracker/templatetags/myifchanged.py | 25 +++++++++++++++++-- ietf/idtracker/views.py | 4 +-- .../idtracker/search_result_row.html | 2 +- .../idtracker/search_result_table.html | 8 ++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ietf/idtracker/templatetags/myifchanged.py b/ietf/idtracker/templatetags/myifchanged.py index 06ea4ebc5..ffe5919a1 100644 --- a/ietf/idtracker/templatetags/myifchanged.py +++ b/ietf/idtracker/templatetags/myifchanged.py @@ -16,8 +16,8 @@ class MyIfChangedNode(Node): self._varlist = varlist def render(self, context): - if context.has_key('forloop') and context['forloop']['first']: - self._last_seen = None + #if context.has_key('forloop') and context['forloop']['first']: + # self._last_seen = None try: if self._varlist: # Consider multiple parameters. @@ -81,3 +81,24 @@ def myifchanged(parser, token): nodelist_false = NodeList() return MyIfChangedNode(nodelist_true, nodelist_false, *bits[1:]) myifchanged = register.tag(myifchanged) + + +class CycleValueNode(Node): + def __init__(self, cyclenode): + self.cyclenode = cyclenode + + def render(self, context): + return self.cyclenode.cyclevars[self.cyclenode.counter % self.cyclenode.cyclevars_len] + +def cyclevalue(parser, token): + args = token.contents.split() + if len(args) == 2: + name = args[1] + if not hasattr(parser, '_namedCycleNodes'): + raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) + if name not in parser._namedCycleNodes: + raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) + return CycleValueNode(parser._namedCycleNodes[name]) + else: + raise TemplateSyntaxError("Usage: cyclevalue cyclename") +cyclevalue = register.tag(cyclevalue) diff --git a/ietf/idtracker/views.py b/ietf/idtracker/views.py index 3e30bbe92..3a0e4fd8c 100644 --- a/ietf/idtracker/views.py +++ b/ietf/idtracker/views.py @@ -65,7 +65,7 @@ def search(request): if status != '': q_objs.append(Q(draft__status=status,rfc_flag=0)) matches = IDInternal.objects.all().filter(*q_objs) - matches = matches.order_by('cur_state', 'cur_sub_state', 'ballot', '-primary_flag') + matches = matches.order_by('cur_state', 'cur_sub_state', '-primary_flag') # # Now search by I-D exists, if there could be any results. # If searching by job owner, current state or substate, there @@ -80,7 +80,7 @@ def search(request): #'search_status_id': 'status', } q_objs = [Q(**{qdict[k]: args[k]}) for k in qdict.keys() if args.get(k, '') != ''] - idmatches = InternetDraft.objects.filter(*q_objs).exclude(id_document_tag__in=in_tracker).filter(status__status='Active') + idmatches = InternetDraft.objects.filter(*q_objs).exclude(id_document_tag__in=in_tracker).filter(status__status='Active').order_by('filename') # resolve the queryset, append wrapper objects. matches = list(matches) + [DocumentWrapper(id) for id in idmatches] if not(args.get('search_filename', '') or args.get('search_status_id', 0)) and args.get('search_rfcnumber', 0): diff --git a/ietf/templates/idtracker/search_result_row.html b/ietf/templates/idtracker/search_result_row.html index d75c04ef1..816c08e69 100644 --- a/ietf/templates/idtracker/search_result_row.html +++ b/ietf/templates/idtracker/search_result_row.html @@ -1,5 +1,5 @@ {% load myifchanged %} - + {% if match.synthetic %}   {% else %} diff --git a/ietf/templates/idtracker/search_result_table.html b/ietf/templates/idtracker/search_result_table.html index 7ad717b80..ba8647bc9 100644 --- a/ietf/templates/idtracker/search_result_table.html +++ b/ietf/templates/idtracker/search_result_table.html @@ -2,8 +2,12 @@

In State: {{ group.list.0.cur_state }}{% if group.list.0.cur_sub_state %} :: {{ group.list.0.cur_sub_state }}{% endif %}

- {% for match in group.list %} - {% include "idtracker/search_result_row.html" %} + {# Same sort algorithm as I-D tracker #} + {% regroup group.list by primary_flag as primaries %} + {% for pgroup in primaries %} + {% for match in pgroup.list|dictsort:"document.filename" %} + {% include "idtracker/search_result_row.html" %} + {% endfor %} {% endfor %}
 Name (Intended Status)VerResponsible ADStatus DateModified (EST)
{% endfor %}