88from ietf .ipr .view_new import new
99from ietf .utils import log
1010
11+
1112def linebreaks (value ):
1213 if value :
1314 return django .utils .html .linebreaks (value )
@@ -112,6 +113,8 @@ def set_relation(first, rel, second):
112113 set_related (second , inverse [rel ], first )
113114
114115def related_docs (doc , found = []):
116+ """Get a list of document related to the given document.
117+ """
115118 #print "\nrelated_docs(%s, %s)" % (doc, found)
116119 found .append (doc )
117120 if isinstance (doc , Rfc ):
@@ -164,14 +167,38 @@ def search(request, type="", q="", id=""):
164167 id = value
165168 if type and q or id :
166169 log ("Got query: type=%s, q=%s, id=%s" % (type , q , id ))
167- if type == "document_search" :
168- if q :
169- start = InternetDraft .objects .filter (filename__contains = q )
170- if id :
171- start = InternetDraft .objects .filter (id_document_tag = id )
172- elif type == "rfc_search" :
173- if q :
174- start = Rfc .objects .filter (rfc_number = q )
170+ if type in ["document_search" , "rfc_search" ]:
171+ if type == "document_search" :
172+ if q :
173+ start = InternetDraft .objects .filter (filename__contains = q )
174+ if id :
175+ start = InternetDraft .objects .filter (id_document_tag = id )
176+ if type == "rfc_search" :
177+ if q :
178+ start = Rfc .objects .filter (rfc_number = q )
179+ if start .count () == 1 :
180+ first = start [0 ]
181+ # get all related drafts, then search for IPRs on all
182+
183+ docs = related_docs (first , [])
184+ #docs = get_doclist.get_doclist(first)
185+ iprs = []
186+ for doc in docs :
187+ if isinstance (doc , InternetDraft ):
188+ disclosures = [ item .ipr for item in IprDraft .objects .filter (document = doc , ipr__status__in = [1 ,3 ]) ]
189+ elif isinstance (doc , Rfc ):
190+ disclosures = [ item .ipr for item in IprRfc .objects .filter (document = doc , ipr__status__in = [1 ,3 ]) ]
191+ else :
192+ raise ValueError ("Doc type is neither draft nor rfc: %s" % doc )
193+ if disclosures :
194+ doc .iprs = disclosures
195+ iprs += disclosures
196+ iprs = list (set (iprs ))
197+ return render ("ipr/search_doc_result.html" , {"first" : first , "iprs" : iprs , "docs" : docs })
198+ elif start .count ():
199+ return render ("ipr/search_doc_list.html" , {"docs" : start })
200+ else :
201+ raise ValueError ("Missing or malformed search parameters, or internal error" )
175202 elif type == "patent_search" :
176203 pass
177204 elif type == "patent_info_search" :
@@ -184,27 +211,6 @@ def search(request, type="", q="", id=""):
184211 pass
185212 else :
186213 raise ValueError ("Unexpected search type in IPR query: %s" % type )
187- if start .count () == 1 :
188- first = start [0 ]
189- # get all related drafts, then search for IPRs on all
190- docs = related_docs (first , [])
191- iprs = []
192- for doc in docs :
193- if isinstance (doc , InternetDraft ):
194- disclosures = [ item .ipr for item in IprDraft .objects .filter (document = doc ) ]
195- elif isinstance (doc , Rfc ):
196- disclosures = [ item .ipr for item in IprRfc .objects .filter (document = doc ) ]
197- else :
198- raise ValueError ("Doc type is neither draft nor rfc: %s" % doc )
199- if disclosures :
200- doc .iprs = disclosures
201- iprs += disclosures
202- iprs = list (set (iprs ))
203- return render ("ipr/search_result.html" , {"first" : first , "iprs" : iprs , "docs" : docs })
204- elif start .count ():
205- return render ("ipr/search_list.html" , {"docs" : start })
206- else :
207- raise ValueError ("Missing or malformed search parameters, or internal error" )
208214 return django .http .HttpResponseRedirect (request .path )
209215 return render ("ipr/search.html" , {"wgs" : wgs })
210216
0 commit comments