Skip to content

Commit e3ba021

Browse files
feat: Teach ajax_select2_search about subseries (ietf-tools#6709)
* feat: Teach ajax_select2_search about subseries * refactor: "draft,rfc" -> "all" in a missed spot
1 parent b281919 commit e3ba021

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

ietf/doc/tests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def test_indexes(self):
423423
def test_ajax_search_docs(self):
424424
draft = IndividualDraftFactory(name="draft-ietf-rfc1234bis")
425425
rfc = IndividualRfcFactory(rfc_number=1234)
426+
bcp = IndividualRfcFactory(name="bcp12345", type_id="bcp")
426427

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

445446
url = urlreverse('ietf.doc.views_search.ajax_select2_search_docs', kwargs={
446447
"model_name": "document",
447-
"doc_type": "draft,rfc",
448+
"doc_type": "all",
448449
})
449450
r = self.client.get(url, dict(q="1234"))
450451
self.assertEqual(r.status_code, 200)
451452
data = r.json()
452-
self.assertEqual(len(data), 2)
453-
pks = set([data[i]["id"] for i in range(2)])
454-
self.assertEqual(pks, set([rfc.pk, draft.pk]))
453+
self.assertEqual(len(data), 3)
454+
pks = set([data[i]["id"] for i in range(3)])
455+
self.assertEqual(pks, set([bcp.pk, rfc.pk, draft.pk]))
455456

456457

457458

ietf/doc/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
url(r'^all/?$', views_search.index_all_drafts),
9191
url(r'^active/?$', views_search.index_active_drafts),
9292
url(r'^recent/?$', views_search.recent_drafts),
93-
url(r'^select2search/(?P<model_name>document)/(?P<doc_type>(draft|rfc|draft,rfc))/$', views_search.ajax_select2_search_docs),
93+
url(r'^select2search/(?P<model_name>document)/(?P<doc_type>(draft|rfc|all))/$', views_search.ajax_select2_search_docs),
9494
url(r'^ballots/irsg/$', views_ballot.irsg_ballot_status),
9595
url(r'^ballots/rsab/$', views_ballot.rsab_ballot_status),
9696

ietf/doc/views_search.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,18 +806,30 @@ def index_active_drafts(request):
806806
return render(request, "doc/index_active_drafts.html", { 'groups': groups })
807807

808808
def ajax_select2_search_docs(request, model_name, doc_type): # TODO - remove model_name argument...
809+
"""Get results for a select2 search field
810+
811+
doc_type can be "draft", "rfc", or "all", to search for only docs of type "draft", only docs of
812+
type "rfc", or docs of type "draft" or "rfc" or any of the subseries ("bcp", "std", ...).
813+
814+
If a need arises for searching _only_ for draft or rfc, without including the subseries, then an
815+
additional option or options will be needed.
816+
"""
809817
model = Document # Earlier versions allowed searching over DocAlias which no longer exists
810818

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

813821
if not q:
814822
objs = model.objects.none()
815823
else:
816-
if "," in doc_type:
817-
qs = model.objects.filter(type__in=[t.strip() for t in doc_type.split(',')])
824+
if doc_type == "draft":
825+
types = ["draft"]
826+
elif doc_type == "rfc":
827+
types = ["rfc"]
828+
elif doc_type == "all":
829+
types = ("draft", "rfc", "bcp", "fyi", "std")
818830
else:
819-
qs = model.objects.filter(type=doc_type)
820-
831+
return HttpResponseBadRequest("Invalid document type")
832+
qs = model.objects.filter(type__in=[t.strip() for t in types])
821833
for t in q:
822834
qs = qs.filter(name__icontains=t)
823835

ietf/ipr/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def clean(self):
9595
return self.cleaned_data
9696

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

100100
class Meta:
101101
model = IprDocRel

ietf/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<label class="d-none d-md-block" aria-label="Document search">
6969
<input class="form-control select2-field search-select"
7070
id="navbar-doc-search"
71-
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='document' doc_type='draft,rfc' %}"
71+
data-select2-ajax-url="{% url 'ietf.doc.views_search.ajax_select2_search_docs' model_name='document' doc_type='all' %}"
7272
type="text"
7373
data-placeholder="Document search">
7474
</label>

0 commit comments

Comments
 (0)