@@ -806,18 +806,30 @@ def index_active_drafts(request):
806806 return render (request , "doc/index_active_drafts.html" , { 'groups' : groups })
807807
808808def 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
0 commit comments