Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def test_indexes(self):
def test_ajax_search_docs(self):
draft = IndividualDraftFactory(name="draft-ietf-rfc1234bis")
rfc = IndividualRfcFactory(rfc_number=1234)
bcp = IndividualRfcFactory(name="bcp12345", type_id="bcp")

url = urlreverse('ietf.doc.views_search.ajax_select2_search_docs', kwargs={
"model_name": "document",
Expand All @@ -444,14 +445,14 @@ def test_ajax_search_docs(self):

url = urlreverse('ietf.doc.views_search.ajax_select2_search_docs', kwargs={
"model_name": "document",
"doc_type": "draft,rfc",
"doc_type": "all",
})
r = self.client.get(url, dict(q="1234"))
self.assertEqual(r.status_code, 200)
data = r.json()
self.assertEqual(len(data), 2)
pks = set([data[i]["id"] for i in range(2)])
self.assertEqual(pks, set([rfc.pk, draft.pk]))
self.assertEqual(len(data), 3)
pks = set([data[i]["id"] for i in range(3)])
self.assertEqual(pks, set([bcp.pk, rfc.pk, draft.pk]))



Expand Down
2 changes: 1 addition & 1 deletion ietf/doc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
url(r'^all/?$', views_search.index_all_drafts),
url(r'^active/?$', views_search.index_active_drafts),
url(r'^recent/?$', views_search.recent_drafts),
url(r'^select2search/(?P<model_name>document)/(?P<doc_type>(draft|rfc|draft,rfc))/$', views_search.ajax_select2_search_docs),
url(r'^select2search/(?P<model_name>document)/(?P<doc_type>(draft|rfc|all))/$', views_search.ajax_select2_search_docs),
url(r'^ballots/irsg/$', views_ballot.irsg_ballot_status),
url(r'^ballots/rsab/$', views_ballot.rsab_ballot_status),

Expand Down
20 changes: 16 additions & 4 deletions ietf/doc/views_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,30 @@ def index_active_drafts(request):
return render(request, "doc/index_active_drafts.html", { 'groups': groups })

def ajax_select2_search_docs(request, model_name, doc_type): # TODO - remove model_name argument...
"""Get results for a select2 search field

doc_type can be "draft", "rfc", or "all", to search for only docs of type "draft", only docs of
type "rfc", or docs of type "draft" or "rfc" or any of the subseries ("bcp", "std", ...).

If a need arises for searching _only_ for draft or rfc, without including the subseries, then an
additional option or options will be needed.
"""
model = Document # Earlier versions allowed searching over DocAlias which no longer exists

q = [w.strip() for w in request.GET.get('q', '').split() if w.strip()]

if not q:
objs = model.objects.none()
else:
if "," in doc_type:
qs = model.objects.filter(type__in=[t.strip() for t in doc_type.split(',')])
if doc_type == "draft":
types = ["draft"]
elif doc_type == "rfc":
types = ["rfc"]
elif doc_type == "all":
types = ("draft", "rfc", "bcp", "fyi", "std")
else:
qs = model.objects.filter(type=doc_type)

return HttpResponseBadRequest("Invalid document type")
qs = model.objects.filter(type__in=[t.strip() for t in types])
for t in q:
qs = qs.filter(name__icontains=t)

Expand Down
2 changes: 1 addition & 1 deletion ietf/ipr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def clean(self):
return self.cleaned_data

class DraftForm(forms.ModelForm):
document = SearchableDocumentField(label="I-D name/RFC number", required=True, doc_type="draft,rfc")
document = SearchableDocumentField(label="I-D name/RFC number", required=True, doc_type="all")

class Meta:
model = IprDocRel
Expand Down
2 changes: 1 addition & 1 deletion ietf/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<label class="d-none d-md-block" aria-label="Document search">
<input class="form-control select2-field search-select"
id="navbar-doc-search"
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='document' doc_type='draft,rfc' %}"
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='document' doc_type='all' %}"
type="text"
data-placeholder="Document search">
</label>
Expand Down