Skip to content

Commit 7075fe6

Browse files
committed
Code reorganization. Splitting up ipr search code into separate files, and renaming the ipr.view_new module to ipr.new.
- Legacy-Id: 478
1 parent 6829830 commit 7075fe6

5 files changed

Lines changed: 149 additions & 142 deletions

File tree

File renamed without changes.

ietf/ipr/related.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from ietf.idtracker.models import InternetDraft, Rfc
2+
3+
inverse = {
4+
'updates': 'is_updated_by',
5+
'is_updated_by': 'updates',
6+
'obsoletes': 'is_obsoleted_by',
7+
'is_obsoleted_by': 'obsoletes',
8+
'replaces': 'is_replaced_by',
9+
'is_replaced_by': 'replaces',
10+
'is_rfc_of': 'is_draft_of',
11+
'is_draft_of': 'is_rfc_of',
12+
}
13+
14+
display_relation = {
15+
'updates': 'that updated',
16+
'is_updated_by': 'that was updated by',
17+
'obsoletes': 'that obsoleted',
18+
'is_obsoleted_by': 'that was obsoleted by',
19+
'replaces': 'that replaced',
20+
'is_replaced_by': 'that was replaced by',
21+
'is_rfc_of': 'which came from',
22+
'is_draft_of': 'that was published as',
23+
}
24+
25+
def set_related(obj, rel, target):
26+
#print obj, rel, target
27+
# remember only the first relationship we find.
28+
if not hasattr(obj, "related"):
29+
obj.related = target
30+
obj.relation = display_relation[rel]
31+
32+
def set_relation(first, rel, second):
33+
set_related(first, rel, second)
34+
set_related(second, inverse[rel], first)
35+
36+
def related_docs(doc, found = []):
37+
"""Get a list of document related to the given document.
38+
"""
39+
#print "\nrelated_docs(%s, %s)" % (doc, found)
40+
found.append(doc)
41+
if isinstance(doc, Rfc):
42+
try:
43+
item = InternetDraft.objects.get(rfc_number=doc.rfc_number)
44+
if not item in found:
45+
set_relation(doc, 'is_rfc_of', item)
46+
found = related_docs(item, found)
47+
except InternetDraft.DoesNotExist:
48+
pass
49+
for entry in doc.updated_or_obsoleted_by.all():
50+
item = entry.rfc
51+
if not item in found:
52+
action = inverse[entry.action.lower()]
53+
set_relation(doc, action, item)
54+
found = related_docs(item, found)
55+
for entry in doc.updates_or_obsoletes.all():
56+
item = entry.rfc_acted_on
57+
if not item in found:
58+
action = entry.action.lower()
59+
set_relation(doc, action, item)
60+
found = related_docs(item, found)
61+
if isinstance(doc, InternetDraft):
62+
if doc.replaced_by_id:
63+
item = doc.replaced_by
64+
if not item in found:
65+
set_relation(doc, 'is_replaced_by', item)
66+
found = related_docs(item, found)
67+
for item in doc.replaces_set.all():
68+
if not item in found:
69+
set_relation(doc, 'replaces', item)
70+
found = related_docs(item, found)
71+
if doc.rfc_number:
72+
item = Rfc.objects.get(rfc_number=doc.rfc_number)
73+
if not item in found:
74+
set_relation(doc, 'is_draft_of', item)
75+
found = related_docs(item, found)
76+
return found

ietf/ipr/search.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import re
2+
import django.utils.html
3+
from django.shortcuts import render_to_response as render
4+
from ietf.idtracker.models import IETFWG, InternetDraft, Rfc
5+
from ietf.ipr.models import IprRfc, IprDraft
6+
from ietf.ipr.related import related_docs
7+
from ietf.utils import log
8+
9+
10+
def search(request, type="", q="", id=""):
11+
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
12+
args = request.REQUEST.items()
13+
if args:
14+
for key, value in args:
15+
if key == "option":
16+
type = value
17+
if re.match(".*search", key):
18+
q = value
19+
if re.match(".*id", key):
20+
id = value
21+
if type and q or id:
22+
log("Got query: type=%s, q=%s, id=%s" % (type, q, id))
23+
if type in ["document_search", "rfc_search"]:
24+
if type == "document_search":
25+
if q:
26+
start = InternetDraft.objects.filter(filename__contains=q)
27+
if id:
28+
start = InternetDraft.objects.filter(id_document_tag=id)
29+
if type == "rfc_search":
30+
if q:
31+
start = Rfc.objects.filter(rfc_number=q)
32+
if start.count() == 1:
33+
first = start[0]
34+
# get all related drafts, then search for IPRs on all
35+
36+
docs = related_docs(first, [])
37+
#docs = get_doclist.get_doclist(first)
38+
iprs = []
39+
for doc in docs:
40+
if isinstance(doc, InternetDraft):
41+
disclosures = [ item.ipr for item in IprDraft.objects.filter(document=doc, ipr__status__in=[1,3]) ]
42+
elif isinstance(doc, Rfc):
43+
disclosures = [ item.ipr for item in IprRfc.objects.filter(document=doc, ipr__status__in=[1,3]) ]
44+
else:
45+
raise ValueError("Doc type is neither draft nor rfc: %s" % doc)
46+
if disclosures:
47+
doc.iprs = disclosures
48+
iprs += disclosures
49+
iprs = list(set(iprs))
50+
return render("ipr/search_doc_result.html", {"first": first, "iprs": iprs, "docs": docs})
51+
elif start.count():
52+
return render("ipr/search_doc_list.html", {"docs": start })
53+
else:
54+
raise ValueError("Missing or malformed search parameters, or internal error")
55+
elif type == "patent_search":
56+
pass
57+
elif type == "patent_info_search":
58+
pass
59+
elif type == "wg_search":
60+
pass
61+
elif type == "title_search":
62+
pass
63+
elif type == "ip_title_search":
64+
pass
65+
else:
66+
raise ValueError("Unexpected search type in IPR query: %s" % type)
67+
return django.http.HttpResponseRedirect(request.path)
68+
return render("ipr/search.html", {"wgs": wgs})

ietf/ipr/urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from django.conf.urls.defaults import patterns
2-
from ietf.ipr import models, views
2+
from ietf.ipr import models, views, new, search
33

44
urlpatterns = patterns('',
55
(r'^$', views.showlist),
66
(r'^about/?$', views.default),
77
(r'^ipr-(?P<ipr_id>\d+)/$', views.show),
88
(r'^update/$', views.updatelist),
99
(r'^update/(?P<ipr_id>\d+)/$', views.update),
10-
(r'^new-(?P<type>(specific|generic|third-party))/$', views.new),
11-
(r'^search/$', views.search),
10+
(r'^new-(?P<type>(specific|generic|third-party))/$', new.new),
11+
(r'^search/$', search.search),
1212
)
1313

1414
queryset = models.IprDetail.objects.all()

ietf/ipr/views.py

Lines changed: 2 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import re
21
import django.utils.html
32
from django.shortcuts import render_to_response as render
43
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
76
from ietf.ipr.view_sections import section_table
8-
from ietf.ipr.view_new import new
97
from ietf.utils import log
108

11-
129
def linebreaks(value):
1310
if value:
1411
return django.utils.html.linebreaks(value)
@@ -79,140 +76,6 @@ def update(request, ipr_id=None):
7976
return show(request, ipr_id)
8077

8178

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})
21679

21780
def form(request):
21881
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')

0 commit comments

Comments
 (0)