feat: Teach ajax_select2_search about subseries ()

* feat: Teach ajax_select2_search about subseries

* refactor: "draft,rfc" -> "all" in a missed spot
This commit is contained in:
Jennifer Richards 2023-11-30 11:22:32 -04:00 committed by GitHub
parent b281919d4c
commit e3ba021e1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 11 deletions

View file

@ -423,6 +423,7 @@ class SearchTests(TestCase):
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",
@ -444,14 +445,14 @@ class SearchTests(TestCase):
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]))

View file

@ -90,7 +90,7 @@ urlpatterns = [
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),

View file

@ -806,6 +806,14 @@ 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()]
@ -813,11 +821,15 @@ def ajax_select2_search_docs(request, model_name, doc_type): # TODO - remove mod
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)

View file

@ -95,7 +95,7 @@ class AddEmailForm(forms.Form):
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

View file

@ -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>