Skip to content

Commit a6ef460

Browse files
author
Jelte Jansen
committed
Make search result table headers clickable; clicking will sort on said column, see trac ietf-tools#484
- Legacy-Id: 2967
1 parent e2f01ce commit a6ef460

6 files changed

Lines changed: 98 additions & 11 deletions

File tree

jelte/ietf/idrfc/idrfc_wrapper.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,47 @@ def view_sort_group(self):
573573
return 'Active Internet-Draft'
574574
else:
575575
return 'Old Internet-Draft'
576-
def view_sort_key(self):
577-
if self.rfc:
578-
return "2%04d" % self.rfc.rfc_number
579-
elif self.id.draft_status == "Active":
580-
return "1"+self.id.draft_name
576+
577+
def view_sort_key(self, sort_by=None):
578+
if sort_by is None:
579+
if self.rfc:
580+
return "2%04d" % self.rfc.rfc_number
581+
elif self.id.draft_status == "Active":
582+
return "1"+self.id.draft_name
583+
else:
584+
return "3"+self.id.draft_name
581585
else:
582-
return "3"+self.id.draft_name
586+
if self.rfc:
587+
sort_key = "2"
588+
elif self.id.draft_status == "Active":
589+
sort_key = "1"
590+
else:
591+
sort_key = "3"
592+
593+
# Depending on what we're sorting on, we may
594+
# need to do some conversion.
595+
if sort_by == "title":
596+
sort_key += self.title()
597+
elif sort_by == "date":
598+
sort_key = sort_key + str(self.publication_date())
599+
elif sort_by == "status":
600+
if self.rfc:
601+
sort_key += "%04d" % self.rfc.rfc_number
602+
else:
603+
sort_key += self.id.draft_status
604+
elif sort_by == "ipr":
605+
sort_key += self.iprUrl
606+
elif sort_by == "ad":
607+
return self.view_sort_key_byad()
608+
else:
609+
# sort default or unknown sort value, revert to default
610+
if self.rfc:
611+
sort_key += "%04d" % self.rfc.rfc_number
612+
else:
613+
sort_key += self.id.draft_name
614+
615+
return sort_key
616+
583617
def view_sort_key_byad(self):
584618
if self.rfc:
585619
return "2%04d" % self.rfc.rfc_number

jelte/ietf/idrfc/views_search.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def clean(self):
8484
q['subState'] = ""
8585
return q
8686

87-
def search_query(query_original):
87+
def search_query(query_original, sort_by=None):
8888
query = dict(query_original.items())
8989
drafts = query['activeDrafts'] or query['oldDrafts']
9090
if (not drafts) and (not query['rfcs']):
@@ -244,23 +244,58 @@ def search_query(query_original):
244244
if d or r:
245245
doc = IdRfcWrapper(d, r)
246246
results.append(doc)
247-
results.sort(key=lambda obj: obj.view_sort_key())
247+
results.sort(key=lambda obj: obj.view_sort_key(sort_by))
248+
248249
meta = {}
249250
if maxReached:
250251
meta['max'] = MAX
251252
if query['by']:
252253
meta['advanced'] = True
253254
return (results,meta)
254255

256+
def genParamURL(request, ignore_list):
257+
"""Recreates the parameter string from the given request, and
258+
returns it as a string.
259+
Any parameter names present in ignore_list shall not be put
260+
in the result string.
261+
"""
262+
params = []
263+
for i in request.GET:
264+
if not i in ignore_list:
265+
params.append(i + "=" + request.GET[i])
266+
return "?" + "&".join(params)
267+
255268
def search_results(request):
256269
if len(request.REQUEST.items()) == 0:
257270
return search_main(request)
258271
form = SearchForm(dict(request.REQUEST.items()))
259272
if not form.is_valid():
260273
return HttpResponse("form not valid?", mimetype="text/plain")
261-
(results,meta) = search_query(form.cleaned_data)
274+
275+
sort_by = None
276+
if "sortBy" in request.GET:
277+
sort_by = request.GET["sortBy"]
278+
279+
(results,meta) = search_query(form.cleaned_data, sort_by)
280+
262281
meta['searching'] = True
263282
meta['by'] = form.cleaned_data['by']
283+
meta['rqps'] = genParamURL(request, ['sortBy'])
284+
# With a later Django we can do this from the template (incude with tag)
285+
# Pass the headers and their sort key names
286+
meta['hdrs'] = [{'htitle': 'Document', 'htype':'doc'},
287+
{'htitle': 'Title', 'htype':'title'},
288+
{'htitle': 'Date', 'htype':'date'},
289+
{'htitle': 'Status', 'htype':'status', 'colspan':'2'},
290+
{'htitle': 'IPR', 'htype':'ipr'},
291+
{'htitle': 'Ad', 'htype':'ad'}]
292+
293+
# Make sure we know which one is selected (for visibility later)
294+
if sort_by:
295+
for hdr in meta['hdrs']:
296+
if hdr['htype'] == sort_by:
297+
hdr['selected'] = True
298+
264299
if 'ajax' in request.REQUEST and request.REQUEST['ajax']:
265300
return render_to_response('idrfc/search_results.html', {'docs':results, 'meta':meta}, context_instance=RequestContext(request))
266301
elif form.cleaned_data['lucky'] and len(results)==1:

jelte/ietf/templates/idrfc/search_results.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
{% else %}
4141
{% regroup docs by view_sort_group as grouped_docs %}
4242
<table class="ietf-table ietf-doctable">
43-
<tr><th class="doc">Document</th><th class="title">Title</th><th class="date">Date</th><th class="status" colspan="2">Status</th><th class="ipr">ipr</th><th class="ad">Area Director</th></tr>
43+
<tr>
44+
{% for hdr in meta.hdrs %}
45+
{% include "idrfc/table_header.html" %}
46+
{% endfor %}
47+
</tr>
4448
{% for doc_group in grouped_docs %}
4549
<tr class="header"><td colspan="7">{{doc_group.grouper}}s</td></tr>
46-
4750
{% for doc in doc_group.list %}
4851
{% include "idrfc/search_result_row.html" %}
4952
{% endfor %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{# Copyright The IETF Trust 2011, All Rights Reserved #}
2+
3+
<th class="{{hdr.htype}}"{% if hdr.colspan %}colspan="{{ hdr.colspan }}" {% endif %}
4+
onclick="location=unescape('{{ meta.rqps }}&sortBy={{hdr.htype}}');"
5+
style="white-space: nowrap;"
6+
>
7+
<span>
8+
<label>{{hdr.htitle}}</label>
9+
{% if hdr.selected %}
10+
<img style="border-style: none;vertical-align:top" src="/images/sort-header-filled.png"/>
11+
{% else %}
12+
<img style="border-style: none;vertical-align:top" src="/images/sort-header-clear.png"/>
13+
{% endif %}
14+
</span>
15+
</th>
265 Bytes
Loading
214 Bytes
Loading

0 commit comments

Comments
 (0)