Skip to content

Commit 6794113

Browse files
committed
Merged [5898] from adam@nostrum.com, with
additional tweaks from henrik: Added the capability to search for all kinds of documents in the main datatracker search page. Fixes bug ietf-tools#838. - Legacy-Id: 5926 Note: SVN reference [5898] has been migrated to Git commit b14a8d0
2 parents 3decaf3 + b14a8d0 commit 6794113

5 files changed

Lines changed: 76 additions & 31 deletions

File tree

ietf/idrfc/views_search.py

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class SearchForm(forms.Form):
6262

6363
sort = forms.ChoiceField(choices=(("document", "Document"), ("title", "Title"), ("date", "Date"), ("status", "Status"), ("ipr", "Ipr"), ("ad", "AD")), required=False, widget=forms.HiddenInput)
6464

65+
doctypes = DocTypeName.objects.exclude(slug='draft').order_by('name');
66+
6567
def __init__(self, *args, **kwargs):
6668
super(SearchForm, self).__init__(*args, **kwargs)
6769
responsible = Document.objects.values_list('ad', flat=True).distinct()
@@ -155,12 +157,15 @@ def fill_in_search_attributes(docs):
155157
else:
156158
d.latest_revision_date = d.time
157159

158-
if d.get_state_slug() == "rfc":
159-
d.search_heading = "RFC"
160-
elif d.get_state_slug() == "active":
161-
d.search_heading = "Active Internet-Draft"
160+
if d.type_id == "draft":
161+
if d.get_state_slug() == "rfc":
162+
d.search_heading = "RFC"
163+
elif d.get_state_slug() in ("ietf-rm", "auth-rm"):
164+
d.search_heading = "Withdrawn Internet-Draft"
165+
else:
166+
d.search_heading = "%s Internet-Draft" % d.get_state()
162167
else:
163-
d.search_heading = "Old Internet-Draft"
168+
d.search_heading = "%s" % (d.type,);
164169

165170
d.expirable = expirable_draft(d)
166171

@@ -196,39 +201,55 @@ def fill_in_search_attributes(docs):
196201
l.sort()
197202

198203

199-
def retrieve_search_results(form, types=['draft']):
204+
def retrieve_search_results(form, all_types=False):
205+
200206
"""Takes a validated SearchForm and return the results."""
201207
if not form.is_valid():
202208
raise ValueError("SearchForm doesn't validate: %s" % form.errors)
203209

204210
query = form.cleaned_data
205211

206-
if not (query['activedrafts'] or query['olddrafts'] or query['rfcs']):
212+
types=[];
213+
meta = {}
214+
215+
if (query['activedrafts'] or query['olddrafts'] or query['rfcs']):
216+
types.append('draft')
217+
218+
# Advanced document types are data-driven, so we need to read them from the
219+
# raw form.data field (and track their checked/unchecked state ourselves)
220+
meta['checked'] = {}
221+
alltypes = DocTypeName.objects.exclude(slug='draft').order_by('name');
222+
for doctype in alltypes:
223+
if form.data.__contains__('include-' + doctype.slug):
224+
types.append(doctype.slug)
225+
meta['checked'][doctype.slug] = True
226+
227+
if len(types) == 0 and not all_types:
207228
return ([], {})
208229

209230
MAX = 500
210231

211-
if types and len(types) > 0:
212-
docs = Document.objects.filter(type__in=types)
213-
else:
232+
if all_types:
214233
docs = Document.objects.all()
234+
else:
235+
docs = Document.objects.filter(type__in=types)
215236

216237
# name
217238
if query["name"]:
218239
docs = docs.filter(Q(docalias__name__icontains=query["name"]) |
219240
Q(title__icontains=query["name"])).distinct()
220241

221242
# rfc/active/old check buttons
222-
if types == ['draft']:
223-
allowed_states = []
224-
if query["rfcs"]:
225-
allowed_states.append("rfc")
226-
if query["activedrafts"]:
227-
allowed_states.append("active")
228-
if query["olddrafts"]:
229-
allowed_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
243+
allowed_draft_states = []
244+
if query["rfcs"]:
245+
allowed_draft_states.append("rfc")
246+
if query["activedrafts"]:
247+
allowed_draft_states.append("active")
248+
if query["olddrafts"]:
249+
allowed_draft_states.extend(['repl', 'expired', 'auth-rm', 'ietf-rm'])
230250

231-
docs = docs.filter(states__type="draft", states__slug__in=allowed_states)
251+
docs = docs.filter(Q(states__slug__in=allowed_draft_states) |
252+
~Q(type__slug='draft')).distinct()
232253

233254
# radio choices
234255
by = query["by"]
@@ -259,12 +280,14 @@ def sort_key(d):
259280

260281
rfc_num = d.rfc_number()
261282

262-
if rfc_num != None:
263-
res.append(2)
264-
elif d.get_state_slug() == "active":
265-
res.append(1)
283+
284+
if d.type_id == "draft":
285+
res.append(["Active", "Expired", "Replaced", "Withdrawn", "RFC"].index(d.search_heading.split()[0] ))
266286
else:
267-
res.append(3)
287+
res.append(d.type_id);
288+
res.append("-");
289+
res.append(d.get_state_slug());
290+
res.append("-");
268291

269292
if query["sort"] == "title":
270293
res.append(d.title)
@@ -296,11 +319,10 @@ def sort_key(d):
296319
results.sort(key=sort_key)
297320

298321
# fill in a meta dict with some information for rendering the result table
299-
meta = {}
300322
if len(results) == MAX:
301323
meta['max'] = MAX
302324
meta['by'] = query['by']
303-
meta['advanced'] = bool(query['by'])
325+
meta['advanced'] = bool(query['by'] or len(meta['checked']))
304326

305327
meta['headers'] = [{'title': 'Document', 'key':'document'},
306328
{'title': 'Title', 'key':'title'},
@@ -316,7 +338,6 @@ def sort_key(d):
316338
h["sort_url"] = "?" + d.urlencode()
317339
if h['key'] == query.get('sort'):
318340
h['sorted'] = True
319-
320341
return (results, meta)
321342

322343

@@ -477,7 +498,7 @@ def docs_for_ad(request, name):
477498
form = SearchForm({'by':'ad','ad': ad.id,
478499
'rfcs':'on', 'activedrafts':'on', 'olddrafts':'on',
479500
'sort': 'status'})
480-
results, meta = retrieve_search_results(form, types=None)
501+
results, meta = retrieve_search_results(form, all_types=True)
481502
results.sort(key=ad_dashboard_sort_key)
482503
del meta["headers"][-1]
483504
#

ietf/idtracker/templatetags/ietf_filters.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,12 @@ def _test():
482482
if __name__ == "__main__":
483483
_test()
484484

485+
@register.filter
486+
def plural(text, list, arg=u's'):
487+
"Similar to pluralize, but looks at the text, too"
488+
from django.template.defaultfilters import pluralize
489+
if text.endswith('s'):
490+
return text
491+
else:
492+
return text + pluralize(len(list), arg)
493+

ietf/templates/idrfc/search_form.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
<b class="toggle_advanced"><img src="/images/{% if meta.advanced %}minus{% else %}plus{% endif %}.png" alt="" /> Advanced</b>
5353

5454
<div id="search_advanced" style="{% if not meta.advanced %}display:none;{%endif%}">
55+
56+
<div class="search_field">
57+
<label>Additional Document Types:</label>
58+
<table id="search_types">
59+
{% for doc_type in form.doctypes %}
60+
<tr><td><label><input type="checkbox" advdoctype="true" {% if doc_type.slug in meta.checked %}checked="checked"{% endif %}name="include-{{doc_type.slug}}"/>{{doc_type}}</label></td></tr>
61+
{% endfor %}
62+
</table>
63+
</div>
64+
5565
Additional search criteria:
5666

5767
<div class="search_field">

ietf/templates/idrfc/search_results.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% comment %}
1+
{% comment %}<!--
22
Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
33
All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com>
44
@@ -30,8 +30,9 @@
3030
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3131
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3232
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33-
{% endcomment %}
33+
-->{% endcomment %}
3434

35+
{% load ietf_filters %}
3536
<div class="search-results">
3637

3738
{% if not docs %}
@@ -61,7 +62,7 @@ <h2>Too many documents match the query! Returning partial result only.</h2>
6162
{% regroup docs by search_heading as grouped_docs %}
6263

6364
{% for doc_group in grouped_docs %}
64-
<tr class="header"><td colspan="10">{{ doc_group.grouper }}{{doc_group.list|length|pluralize}}</td></tr>
65+
<tr class="header"><td colspan="10">{{ doc_group.grouper|plural:doc_group.list }}</td></tr>
6566

6667
{% for doc in doc_group.list %}
6768
{% include "idrfc/search_result_row.html" %}

static/js/doc-search.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ $(function () {
1212
advanced = true;
1313
});
1414

15+
var additional_doctypes = form.find("input[advdoctype=true]:checked");
16+
if (additional_doctypes.length > 0)
17+
advanced = true;
18+
1519
return advanced;
1620
}
1721

0 commit comments

Comments
 (0)