|
1 | | -import re |
2 | 1 | import django.utils.html |
3 | 2 | from django.shortcuts import render_to_response as render |
4 | 3 | from django.utils.html import escape |
5 | | -from ietf.idtracker.models import IETFWG, InternetDraft, Rfc |
6 | | -from ietf.ipr.models import IprRfc, IprDraft, IprDetail, SELECT_CHOICES, LICENSE_CHOICES |
| 4 | +from ietf.idtracker.models import IETFWG |
| 5 | +from ietf.ipr.models import IprDetail, SELECT_CHOICES, LICENSE_CHOICES |
7 | 6 | from ietf.ipr.view_sections import section_table |
8 | | -from ietf.ipr.view_new import new |
9 | 7 | from ietf.utils import log |
10 | 8 |
|
11 | | - |
12 | 9 | def linebreaks(value): |
13 | 10 | if value: |
14 | 11 | return django.utils.html.linebreaks(value) |
@@ -79,140 +76,6 @@ def update(request, ipr_id=None): |
79 | 76 | return show(request, ipr_id) |
80 | 77 |
|
81 | 78 |
|
82 | | -inverse = { |
83 | | - 'updates': 'is_updated_by', |
84 | | - 'is_updated_by': 'updates', |
85 | | - 'obsoletes': 'is_obsoleted_by', |
86 | | - 'is_obsoleted_by': 'obsoletes', |
87 | | - 'replaces': 'is_replaced_by', |
88 | | - 'is_replaced_by': 'replaces', |
89 | | - 'is_rfc_of': 'is_draft_of', |
90 | | - 'is_draft_of': 'is_rfc_of', |
91 | | - } |
92 | | - |
93 | | -display_relation = { |
94 | | - 'updates': 'that updated', |
95 | | - 'is_updated_by': 'that was updated by', |
96 | | - 'obsoletes': 'that obsoleted', |
97 | | - 'is_obsoleted_by': 'that was obsoleted by', |
98 | | - 'replaces': 'that replaced', |
99 | | - 'is_replaced_by': 'that was replaced by', |
100 | | - 'is_rfc_of': 'which came from', |
101 | | - 'is_draft_of': 'that was published as', |
102 | | - } |
103 | | - |
104 | | -def set_related(obj, rel, target): |
105 | | - #print obj, rel, target |
106 | | - # remember only the first relationship we find. |
107 | | - if not hasattr(obj, "related"): |
108 | | - obj.related = target |
109 | | - obj.relation = display_relation[rel] |
110 | | - |
111 | | -def set_relation(first, rel, second): |
112 | | - set_related(first, rel, second) |
113 | | - set_related(second, inverse[rel], first) |
114 | | - |
115 | | -def related_docs(doc, found = []): |
116 | | - """Get a list of document related to the given document. |
117 | | - """ |
118 | | - #print "\nrelated_docs(%s, %s)" % (doc, found) |
119 | | - found.append(doc) |
120 | | - if isinstance(doc, Rfc): |
121 | | - try: |
122 | | - item = InternetDraft.objects.get(rfc_number=doc.rfc_number) |
123 | | - if not item in found: |
124 | | - set_relation(doc, 'is_rfc_of', item) |
125 | | - found = related_docs(item, found) |
126 | | - except InternetDraft.DoesNotExist: |
127 | | - pass |
128 | | - for entry in doc.updated_or_obsoleted_by.all(): |
129 | | - item = entry.rfc |
130 | | - if not item in found: |
131 | | - action = inverse[entry.action.lower()] |
132 | | - set_relation(doc, action, item) |
133 | | - found = related_docs(item, found) |
134 | | - for entry in doc.updates_or_obsoletes.all(): |
135 | | - item = entry.rfc_acted_on |
136 | | - if not item in found: |
137 | | - action = entry.action.lower() |
138 | | - set_relation(doc, action, item) |
139 | | - found = related_docs(item, found) |
140 | | - if isinstance(doc, InternetDraft): |
141 | | - if doc.replaced_by_id: |
142 | | - item = doc.replaced_by |
143 | | - if not item in found: |
144 | | - set_relation(doc, 'is_replaced_by', item) |
145 | | - found = related_docs(item, found) |
146 | | - for item in doc.replaces_set.all(): |
147 | | - if not item in found: |
148 | | - set_relation(doc, 'replaces', item) |
149 | | - found = related_docs(item, found) |
150 | | - if doc.rfc_number: |
151 | | - item = Rfc.objects.get(rfc_number=doc.rfc_number) |
152 | | - if not item in found: |
153 | | - set_relation(doc, 'is_draft_of', item) |
154 | | - found = related_docs(item, found) |
155 | | - return found |
156 | | - |
157 | | -def search(request, type="", q="", id=""): |
158 | | - wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym') |
159 | | - args = request.REQUEST.items() |
160 | | - if args: |
161 | | - for key, value in args: |
162 | | - if key == "option": |
163 | | - type = value |
164 | | - if re.match(".*search", key): |
165 | | - q = value |
166 | | - if re.match(".*id", key): |
167 | | - id = value |
168 | | - if type and q or id: |
169 | | - log("Got query: type=%s, q=%s, id=%s" % (type, q, id)) |
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") |
202 | | - elif type == "patent_search": |
203 | | - pass |
204 | | - elif type == "patent_info_search": |
205 | | - pass |
206 | | - elif type == "wg_search": |
207 | | - pass |
208 | | - elif type == "title_search": |
209 | | - pass |
210 | | - elif type == "ip_title_search": |
211 | | - pass |
212 | | - else: |
213 | | - raise ValueError("Unexpected search type in IPR query: %s" % type) |
214 | | - return django.http.HttpResponseRedirect(request.path) |
215 | | - return render("ipr/search.html", {"wgs": wgs}) |
216 | 79 |
|
217 | 80 | def form(request): |
218 | 81 | wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym') |
|
0 commit comments