From 92968fa04e7ff2c889935c8114b92cf2be6511e8 Mon Sep 17 00:00:00 2001
From: Henrik Levkowetz <henrik@levkowetz.com>
Date: Sun, 17 Jun 2007 15:21:48 +0000
Subject: [PATCH] Somewhat reorganized IPR search code.  Renamed IprDetails
 model field.  New IPR search templates.  - Legacy-Id: 476

---
 ietf/ipr/models.py                            |  2 +-
 ietf/ipr/view_new.py                          |  6 +-
 ietf/ipr/views.py                             | 64 ++++++++++---------
 ietf/templates/ipr/details.html               |  2 +-
 ...{search_list.html => search_doc_list.html} |  0
 ...rch_result.html => search_doc_result.html} |  0
 6 files changed, 40 insertions(+), 34 deletions(-)
 rename ietf/templates/ipr/{search_list.html => search_doc_list.html} (100%)
 rename ietf/templates/ipr/{search_result.html => search_doc_result.html} (100%)

diff --git a/ietf/ipr/models.py b/ietf/ipr/models.py
index 732b74348..c6c5ca758 100644
--- a/ietf/ipr/models.py
+++ b/ietf/ipr/models.py
@@ -60,7 +60,7 @@ class IprDetail(models.Model):
     additional_old_url2 = models.CharField(blank=True, maxlength=255)
 
     # Patent holder fieldset
-    p_h_legal_name = models.CharField("Legal Name", maxlength=255)
+    legal_name = models.CharField("Legal Name", db_column="p_h_legal_name", maxlength=255)
 
     # Patent Holder Contact fieldset
     # self.contacts.filter(contact_type=1)
diff --git a/ietf/ipr/view_new.py b/ietf/ipr/view_new.py
index 7b07df339..2f004acee 100644
--- a/ietf/ipr/view_new.py
+++ b/ietf/ipr/view_new.py
@@ -177,13 +177,13 @@ def new(request, type):
         data["comply"] = "1"
 
         if type == "general":
-            data["document_title"] = """%(p_h_legal_name)s's General License Statement""" % data
+            data["document_title"] = """%(legal_name)s's General License Statement""" % data
         if type == "specific":
             data["ipr_summary"] = get_ipr_summary(data)
-            data["document_title"] = """%(p_h_legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
+            data["document_title"] = """%(legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
         if type == "third-party":
             data["ipr_summary"] = get_ipr_summary(data)
-            data["document_title"] = """%(submitter)s's Statement about IPR related to %(ipr_summary)s belonging to %(p_h_legal_name)s""" % data
+            data["document_title"] = """%(submitter)s's Statement about IPR related to %(ipr_summary)s belonging to %(legal_name)s""" % data
         
         for src in ["hold", "ietf"]:
             if "%s_contact_is_submitter" % src in data:
diff --git a/ietf/ipr/views.py b/ietf/ipr/views.py
index aae932eaf..f2a3a9810 100644
--- a/ietf/ipr/views.py
+++ b/ietf/ipr/views.py
@@ -8,6 +8,7 @@ from ietf.ipr.view_sections import section_table
 from ietf.ipr.view_new import new
 from ietf.utils import log
 
+
 def linebreaks(value):
     if value:
         return django.utils.html.linebreaks(value)
@@ -112,6 +113,8 @@ def set_relation(first, rel, second):
     set_related(second, inverse[rel], first)
 
 def related_docs(doc, found = []):    
+    """Get a list of document related to the given document.
+    """
     #print "\nrelated_docs(%s, %s)" % (doc, found) 
     found.append(doc)
     if isinstance(doc, Rfc):
@@ -164,14 +167,38 @@ def search(request, type="", q="", id=""):
                 id = value
         if type and q or id:
             log("Got query: type=%s, q=%s, id=%s" % (type, q, id))
-            if type == "document_search":
-                if q:
-                    start = InternetDraft.objects.filter(filename__contains=q)
-                if id:
-                    start = InternetDraft.objects.filter(id_document_tag=id)
-            elif type == "rfc_search":
-                if q:
-                    start = Rfc.objects.filter(rfc_number=q)
+            if type in ["document_search", "rfc_search"]:
+                if type == "document_search":
+                    if q:
+                        start = InternetDraft.objects.filter(filename__contains=q)
+                    if id:
+                        start = InternetDraft.objects.filter(id_document_tag=id)
+                if type == "rfc_search":
+                    if q:
+                        start = Rfc.objects.filter(rfc_number=q)
+                if start.count() == 1:
+                    first = start[0]
+                    # get all related drafts, then search for IPRs on all
+
+                    docs = related_docs(first, [])
+                    #docs = get_doclist.get_doclist(first)
+                    iprs = []
+                    for doc in docs:
+                        if isinstance(doc, InternetDraft):
+                            disclosures = [ item.ipr for item in IprDraft.objects.filter(document=doc, ipr__status__in=[1,3]) ]
+                        elif isinstance(doc, Rfc):
+                            disclosures = [ item.ipr for item in IprRfc.objects.filter(document=doc, ipr__status__in=[1,3]) ]
+                        else:
+                            raise ValueError("Doc type is neither draft nor rfc: %s" % doc)
+                        if disclosures:
+                            doc.iprs = disclosures
+                            iprs += disclosures
+                    iprs = list(set(iprs))
+                    return render("ipr/search_doc_result.html", {"first": first, "iprs": iprs, "docs": docs})
+                elif start.count():
+                    return render("ipr/search_doc_list.html", {"docs": start })
+                else:
+                    raise ValueError("Missing or malformed search parameters, or internal error")
             elif type == "patent_search":
                 pass
             elif type == "patent_info_search":
@@ -184,27 +211,6 @@ def search(request, type="", q="", id=""):
                 pass
             else:
                 raise ValueError("Unexpected search type in IPR query: %s" % type)
-            if start.count() == 1:
-                first = start[0]
-                # get all related drafts, then search for IPRs on all
-                docs = related_docs(first, [])
-                iprs = []
-                for doc in docs:
-                    if isinstance(doc, InternetDraft):
-                        disclosures = [ item.ipr for item in IprDraft.objects.filter(document=doc) ]
-                    elif isinstance(doc, Rfc):
-                        disclosures = [ item.ipr for item in IprRfc.objects.filter(document=doc) ]
-                    else:
-                        raise ValueError("Doc type is neither draft nor rfc: %s" % doc)
-                    if disclosures:
-                        doc.iprs = disclosures
-                        iprs += disclosures
-                iprs = list(set(iprs))
-                return render("ipr/search_result.html", {"first": first, "iprs": iprs, "docs": docs})
-            elif start.count():
-                return render("ipr/search_list.html", {"docs": start })
-            else:
-                raise ValueError("Missing or malformed search parameters, or internal error")
         return django.http.HttpResponseRedirect(request.path)
     return render("ipr/search.html", {"wgs": wgs})
 
diff --git a/ietf/templates/ipr/details.html b/ietf/templates/ipr/details.html
index 76b2018b1..c48d347ce 100644
--- a/ietf/templates/ipr/details.html
+++ b/ietf/templates/ipr/details.html
@@ -190,7 +190,7 @@
 	 </tr>
 	 <tr class="{% cycle row_parity %}">
 	    {% block section1_data %}
-	    <td class="fixwidth">Legal Name:</td>	<td><b> {{ ipr.p_h_legal_name }} </b></td>
+	    <td class="fixwidth">Legal Name:</td>	<td><b> {{ ipr.legal_name }} </b></td>
 	    {% endblock %}
 	 </tr>
       </table>
diff --git a/ietf/templates/ipr/search_list.html b/ietf/templates/ipr/search_doc_list.html
similarity index 100%
rename from ietf/templates/ipr/search_list.html
rename to ietf/templates/ipr/search_doc_list.html
diff --git a/ietf/templates/ipr/search_result.html b/ietf/templates/ipr/search_doc_result.html
similarity index 100%
rename from ietf/templates/ipr/search_result.html
rename to ietf/templates/ipr/search_doc_result.html