Merged [2967] from jelte@nlnetlabs.nl:
Make search result table headers clickable; clicking will sort on said column, see trac #484 - Legacy-Id: 2974 Note: SVN reference [2967] has been migrated to Git commit a6ef460f3a3a24b9f32f83bf8dbeffe2fa220958
This commit is contained in:
parent
662514fe22
commit
4e5ce997e5
|
@ -576,13 +576,47 @@ class IdRfcWrapper:
|
|||
return 'Active Internet-Draft'
|
||||
else:
|
||||
return 'Old Internet-Draft'
|
||||
def view_sort_key(self):
|
||||
if self.rfc:
|
||||
return "2%04d" % self.rfc.rfc_number
|
||||
elif self.id.draft_status == "Active":
|
||||
return "1"+self.id.draft_name
|
||||
|
||||
def view_sort_key(self, sort_by=None):
|
||||
if sort_by is None:
|
||||
if self.rfc:
|
||||
return "2%04d" % self.rfc.rfc_number
|
||||
elif self.id.draft_status == "Active":
|
||||
return "1"+self.id.draft_name
|
||||
else:
|
||||
return "3"+self.id.draft_name
|
||||
else:
|
||||
return "3"+self.id.draft_name
|
||||
if self.rfc:
|
||||
sort_key = "2"
|
||||
elif self.id.draft_status == "Active":
|
||||
sort_key = "1"
|
||||
else:
|
||||
sort_key = "3"
|
||||
|
||||
# Depending on what we're sorting on, we may
|
||||
# need to do some conversion.
|
||||
if sort_by == "title":
|
||||
sort_key += self.title()
|
||||
elif sort_by == "date":
|
||||
sort_key = sort_key + str(self.publication_date())
|
||||
elif sort_by == "status":
|
||||
if self.rfc:
|
||||
sort_key += "%04d" % self.rfc.rfc_number
|
||||
else:
|
||||
sort_key += self.id.draft_status
|
||||
elif sort_by == "ipr":
|
||||
sort_key += self.iprUrl
|
||||
elif sort_by == "ad":
|
||||
return self.view_sort_key_byad()
|
||||
else:
|
||||
# sort default or unknown sort value, revert to default
|
||||
if self.rfc:
|
||||
sort_key += "%04d" % self.rfc.rfc_number
|
||||
else:
|
||||
sort_key += self.id.draft_name
|
||||
|
||||
return sort_key
|
||||
|
||||
def view_sort_key_byad(self):
|
||||
if self.rfc:
|
||||
return "2%04d" % self.rfc.rfc_number
|
||||
|
|
|
@ -98,7 +98,7 @@ class SearchForm(forms.Form):
|
|||
q['subState'] = ""
|
||||
return q
|
||||
|
||||
def search_query(query_original):
|
||||
def search_query(query_original, sort_by=None):
|
||||
query = dict(query_original.items())
|
||||
drafts = query['activeDrafts'] or query['oldDrafts']
|
||||
if (not drafts) and (not query['rfcs']):
|
||||
|
@ -258,7 +258,8 @@ def search_query(query_original):
|
|||
if d or r:
|
||||
doc = IdRfcWrapper(d, r)
|
||||
results.append(doc)
|
||||
results.sort(key=lambda obj: obj.view_sort_key())
|
||||
results.sort(key=lambda obj: obj.view_sort_key(sort_by))
|
||||
|
||||
meta = {}
|
||||
if maxReached:
|
||||
meta['max'] = MAX
|
||||
|
@ -266,15 +267,49 @@ def search_query(query_original):
|
|||
meta['advanced'] = True
|
||||
return (results,meta)
|
||||
|
||||
def genParamURL(request, ignore_list):
|
||||
"""Recreates the parameter string from the given request, and
|
||||
returns it as a string.
|
||||
Any parameter names present in ignore_list shall not be put
|
||||
in the result string.
|
||||
"""
|
||||
params = []
|
||||
for i in request.GET:
|
||||
if not i in ignore_list:
|
||||
params.append(i + "=" + request.GET[i])
|
||||
return "?" + "&".join(params)
|
||||
|
||||
def search_results(request):
|
||||
if len(request.REQUEST.items()) == 0:
|
||||
return search_main(request)
|
||||
form = SearchForm(dict(request.REQUEST.items()))
|
||||
if not form.is_valid():
|
||||
return HttpResponse("form not valid?", mimetype="text/plain")
|
||||
(results,meta) = search_query(form.cleaned_data)
|
||||
|
||||
sort_by = None
|
||||
if "sortBy" in request.GET:
|
||||
sort_by = request.GET["sortBy"]
|
||||
|
||||
(results,meta) = search_query(form.cleaned_data, sort_by)
|
||||
|
||||
meta['searching'] = True
|
||||
meta['by'] = form.cleaned_data['by']
|
||||
meta['rqps'] = genParamURL(request, ['sortBy'])
|
||||
# With a later Django we can do this from the template (incude with tag)
|
||||
# Pass the headers and their sort key names
|
||||
meta['hdrs'] = [{'htitle': 'Document', 'htype':'doc'},
|
||||
{'htitle': 'Title', 'htype':'title'},
|
||||
{'htitle': 'Date', 'htype':'date'},
|
||||
{'htitle': 'Status', 'htype':'status', 'colspan':'2'},
|
||||
{'htitle': 'IPR', 'htype':'ipr'},
|
||||
{'htitle': 'Ad', 'htype':'ad'}]
|
||||
|
||||
# Make sure we know which one is selected (for visibility later)
|
||||
if sort_by:
|
||||
for hdr in meta['hdrs']:
|
||||
if hdr['htype'] == sort_by:
|
||||
hdr['selected'] = True
|
||||
|
||||
if 'ajax' in request.REQUEST and request.REQUEST['ajax']:
|
||||
return render_to_response('idrfc/search_results.html', {'docs':results, 'meta':meta}, context_instance=RequestContext(request))
|
||||
elif form.cleaned_data['lucky'] and len(results)==1:
|
||||
|
|
|
@ -40,10 +40,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
{% else %}
|
||||
{% regroup docs by view_sort_group as grouped_docs %}
|
||||
<table class="ietf-table ietf-doctable">
|
||||
<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>
|
||||
<tr>
|
||||
{% for hdr in meta.hdrs %}
|
||||
{% include "idrfc/table_header.html" %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% for doc_group in grouped_docs %}
|
||||
<tr class="header"><td colspan="7">{{doc_group.grouper}}s</td></tr>
|
||||
|
||||
{% for doc in doc_group.list %}
|
||||
{% include "idrfc/search_result_row.html" %}
|
||||
{% endfor %}
|
||||
|
|
15
ietf/templates/idrfc/table_header.html
Normal file
15
ietf/templates/idrfc/table_header.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{# Copyright The IETF Trust 2011, All Rights Reserved #}
|
||||
|
||||
<th class="{{hdr.htype}}"{% if hdr.colspan %}colspan="{{ hdr.colspan }}" {% endif %}
|
||||
onclick="location=unescape('{{ meta.rqps }}&sortBy={{hdr.htype}}');"
|
||||
style="white-space: nowrap;"
|
||||
>
|
||||
<span>
|
||||
<label>{{hdr.htitle}}</label>
|
||||
{% if hdr.selected %}
|
||||
<img style="border-style: none;vertical-align:top" src="/images/sort-header-filled.png"/>
|
||||
{% else %}
|
||||
<img style="border-style: none;vertical-align:top" src="/images/sort-header-clear.png"/>
|
||||
{% endif %}
|
||||
</span>
|
||||
</th>
|
BIN
static/images/sort-header-clear.png
Normal file
BIN
static/images/sort-header-clear.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 B |
BIN
static/images/sort-header-filled.png
Normal file
BIN
static/images/sort-header-filled.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 B |
Loading…
Reference in a new issue