@@ -39,46 +39,42 @@ def patent_file_search(url, q):
3939 return q in text
4040 return False
4141
42- def search (request , type = "" , q = "" , id = "" ):
42+ def search (request ):
4343 wgs = Group .objects .filter (type = "wg" ).select_related ().order_by ("acronym" )
44- args = request .REQUEST .items ()
45- if args :
46- for key , value in args :
47- if key == "option" :
48- type = value
49- if re .match (".*search" , key ):
44+
45+ search_type = request .GET .get ("option" )
46+ if search_type :
47+ docid = request .GET .get ("id" ) or request .GET .get ("id_document_tag" ) or ""
48+
49+ q = ""
50+ for key , value in request .GET .items ():
51+ if key .endswith ("search" ):
5052 q = value
51- if re .match (".*id" , key ):
52- id = value
53- if (type and q ) or id :
54- #log("Got query: type=%s, q=%s, id=%s" % (type, q, id))
5553
54+ if search_type and (q or docid ):
5655 # Search by RFC number or draft-identifier
5756 # Document list with IPRs
58- if type in ["document_search" , "rfc_search" ]:
57+ if search_type in ["document_search" , "rfc_search" ]:
5958 doc = q
60- if type == "document_search" :
61- if q :
59+
60+ if docid :
61+ start = DocAlias .objects .filter (name = docid )
62+ else :
63+ if search_type == "document_search" :
6264 q = normalize_draftname (q )
6365 start = DocAlias .objects .filter (name__contains = q , name__startswith = "draft" )
64- if id :
65- start = DocAlias .objects .filter (name = id )
66- if type == "rfc_search" :
67- if q :
68- try :
69- q = int (q , 10 )
70- except :
71- q = - 1
72- start = DocAlias .objects .filter (name__contains = q , name__startswith = "rfc" )
73- if start .count () == 1 :
66+ elif search_type == "rfc_search" :
67+ start = DocAlias .objects .filter (name = "rfc%s" % q .lstrip ("0" ))
68+
69+ if len (start ) == 1 :
7470 first = start [0 ]
7571 doc = str (first )
7672 docs = related_docs (first )
7773 iprs , docs = iprs_from_docs (docs )
7874 iprs .sort (key = lambda x : (x .submitted_date , x .ipr_id ))
7975 return render ("ipr/search_doc_result.html" , {"q" : q , "iprs" : iprs , "docs" : docs , "doc" : doc },
8076 context_instance = RequestContext (request ) )
81- elif start . count () :
77+ elif start :
8278 return render ("ipr/search_doc_list.html" , {"q" : q , "docs" : start },
8379 context_instance = RequestContext (request ) )
8480 else :
@@ -87,7 +83,7 @@ def search(request, type="", q="", id=""):
8783
8884 # Search by legal name
8985 # IPR list with documents
90- elif type == "patent_search" :
86+ elif search_type == "patent_search" :
9187 iprs = IprDetail .objects .filter (legal_name__icontains = q , status__in = [1 ,3 ]).order_by ("-submitted_date" , "-ipr_id" )
9288 count = iprs .count ()
9389 iprs = [ ipr for ipr in iprs if not ipr .updated_by .all () ]
@@ -96,7 +92,7 @@ def search(request, type="", q="", id=""):
9692
9793 # Search by content of email or pagent_info field
9894 # IPR list with documents
99- elif type == "patent_info_search" :
95+ elif search_type == "patent_info_search" :
10096 if len (q ) < 3 :
10197 return render ("ipr/search_error.html" , {"q" : q , "error" : "The search string must contain at least three characters" },
10298 context_instance = RequestContext (request ) )
@@ -119,7 +115,7 @@ def search(request, type="", q="", id=""):
119115
120116 # Search by wg acronym
121117 # Document list with IPRs
122- elif type == "wg_search" :
118+ elif search_type == "wg_search" :
123119 docs = list (DocAlias .objects .filter (document__group__acronym = q ))
124120 related = []
125121 for doc in docs :
@@ -136,7 +132,7 @@ def search(request, type="", q="", id=""):
136132
137133 # Search by rfc and id title
138134 # Document list with IPRs
139- elif type == "title_search" :
135+ elif search_type == "title_search" :
140136 docs = list (DocAlias .objects .filter (document__title__icontains = q ))
141137 related = []
142138 for doc in docs :
@@ -153,15 +149,15 @@ def search(request, type="", q="", id=""):
153149
154150 # Search by title of IPR disclosure
155151 # IPR list with documents
156- elif type == "ipr_title_search" :
152+ elif search_type == "ipr_title_search" :
157153 iprs = IprDetail .objects .filter (title__icontains = q , status__in = [1 ,3 ]).order_by ("-submitted_date" , "-ipr_id" )
158154 count = iprs .count ()
159155 iprs = [ ipr for ipr in iprs if not ipr .updated_by .all () ]
160156 return render ("ipr/search_iprtitle_result.html" , {"q" : q , "iprs" : iprs , "count" : count },
161157 context_instance = RequestContext (request ) )
162158
163159 else :
164- raise Http404 ("Unexpected search type in IPR query: %s" % type )
160+ raise Http404 ("Unexpected search type in IPR query: %s" % search_type )
165161 return HttpResponseRedirect (request .path )
166162
167163 return render ("ipr/search.html" , {"wgs" : wgs }, context_instance = RequestContext (request ))
0 commit comments