Skip to content

Commit c1ea7e3

Browse files
committed
Backing out the previous change so I can commit it with proper comments...
- Legacy-Id: 387
1 parent d989d0a commit c1ea7e3

2 files changed

Lines changed: 12 additions & 130 deletions

File tree

ietf/ipr/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
(r'^update/(?P<ipr_id>\d+)/$', views.update),
1010
(r'^new-(?P<type>(specific|generic|third-party))/$', views.new),
1111
(r'^search/$', views.search),
12+
(r'^search/\?((option=(?P<option>[^&]*)|.*search=(?P<search>[^&]*)|submit=(?P<submit>[^&]*))&?)+/$', views.search),
1213
)
1314

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

ietf/ipr/views.py

Lines changed: 11 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import re
1+
import models
22
import django.utils.html
33
from django.shortcuts import render_to_response as render
44
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
75
from ietf.ipr.view_sections import section_table
86
from ietf.ipr.view_new import new
9-
from ietf.utils import log
7+
from ietf.idtracker.models import IETFWG
108

119
def linebreaks(value):
1210
if value:
@@ -20,15 +18,15 @@ def default(request):
2018

2119
def showlist(request):
2220
"""Display a list of existing disclosures"""
23-
return list_all(request, 'ipr/list.html')
21+
return list(request, 'ipr/list.html')
2422

2523
def updatelist(request):
2624
"""Display a list of existing disclosures, with links to update forms"""
27-
return list_all(request, 'ipr/update_list.html')
25+
return list(request, 'ipr/update_list.html')
2826

29-
def list_all(request, template):
27+
def list(request, template):
3028
"""Display a list of existing disclosures, using the provided template"""
31-
disclosures = ietf.ipr.models.IprDetail.objects.all()
29+
disclosures = models.IprDetail.objects.all()
3230
generic_disclosures = disclosures.filter(status__in=[1,3], generic=1)
3331
specific_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=0)
3432
thirdpty_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=1)
@@ -45,7 +43,7 @@ def list_all(request, template):
4543
def show(request, ipr_id=None):
4644
"""Show a specific IPR disclosure"""
4745
assert ipr_id != None
48-
ipr = IprDetail.objects.get(ipr_id=ipr_id)
46+
ipr = models.IprDetail.objects.get(ipr_id=ipr_id)
4947
section_list = get_section_list(ipr)
5048
contacts = ipr.contact.all()
5149
for contact in contacts:
@@ -65,11 +63,11 @@ def show(request, ipr_id=None):
6563
ipr.other_notes = linebreaks(escape(ipr.other_notes))
6664

6765
if ipr.licensing_option:
68-
ipr.licensing_option = dict(LICENSE_CHOICES)[ipr.licensing_option]
66+
ipr.licensing_option = dict(models.LICENSE_CHOICES)[ipr.licensing_option]
6967
if ipr.selecttype:
70-
ipr.selecttype = dict(SELECT_CHOICES)[ipr.selecttype]
68+
ipr.selecttype = dict(models.SELECT_CHOICES)[ipr.selecttype]
7169
if ipr.selectowned:
72-
ipr.selectowned = dict(SELECT_CHOICES)[ipr.selectowned]
70+
ipr.selectowned = dict(models.SELECT_CHOICES)[ipr.selectowned]
7371
return render("ipr/details.html", {"ipr": ipr, "section_list": section_list})
7472

7573
def update(request, ipr_id=None):
@@ -78,127 +76,10 @@ def update(request, ipr_id=None):
7876
return show(request, ipr_id)
7977

8078

81-
inverse = {
82-
'updates': 'is_updated_by',
83-
'is_updated_by': 'updates',
84-
'obsoletes': 'is_obsoleted_by',
85-
'is_obsoleted_by': 'obsoletes',
86-
'replaces': 'is_replaced_by',
87-
'is_replaced_by': 'replaces',
88-
'is_rfc_of': 'is_draft_of',
89-
'is_draft_of': 'is_rfc_of',
90-
}
91-
92-
display_relation = {
93-
'updates': 'that updates',
94-
'is_updated_by': 'that was updated by',
95-
'obsoletes': 'that obsoleted',
96-
'is_obsoleted_by': 'that was obsoleted by',
97-
'replaces': 'that replaced',
98-
'is_replaced_by': 'that was replaced by',
99-
'is_rfc_of': 'which came from',
100-
'is_draft_of': 'that was published as',
101-
}
102-
103-
def set_related(obj, rel, target):
104-
print obj, rel, target
105-
# remember only the first relationship we find.
106-
if not hasattr(obj, "related"):
107-
obj.related = target
108-
obj.relation = display_relation[rel]
109-
110-
def set_relation(first, rel, second):
111-
set_related(first, rel, second)
112-
set_related(second, inverse[rel], first)
113-
114-
def related_docs(doc, found = []):
115-
print "\nrelated_docs(%s, %s)" % (doc, found)
116-
found.append(doc)
117-
if isinstance(doc, Rfc):
118-
try:
119-
item = InternetDraft.objects.get(rfc_number=doc.rfc_number)
120-
if not item in found:
121-
set_relation(doc, 'is_rfc_of', item)
122-
found = related_docs(item, found)
123-
except InternetDraft.DoesNotExist:
124-
pass
125-
for entry in doc.updated_or_obsoleted_by.all():
126-
item = entry.rfc
127-
if not item in found:
128-
action = inverse[entry.action.lower()]
129-
set_relation(doc, action, item)
130-
found = related_docs(item, found)
131-
for entry in doc.updates_or_obsoletes.all():
132-
item = entry.rfc_acted_on
133-
if not item in found:
134-
action = entry.action.lower()
135-
set_relation(doc, action, item)
136-
found = related_docs(item, found)
137-
if isinstance(doc, InternetDraft):
138-
if doc.replaced_by_id:
139-
item = doc.replaced_by_id
140-
if not item in found:
141-
set_relation(doc, 'replaced_by', item)
142-
found = related_docs(item, found)
143-
for item in doc.replaces_set.all():
144-
if not item in found:
145-
set_relation(doc, 'replaces', item)
146-
found = related_docs(item, found)
147-
if doc.rfc_number:
148-
item = Rfc.objects.get(rfc_number=doc.rfc_number)
149-
if not item in found:
150-
set_relation(doc, 'is_draft_of', item)
151-
found = related_docs(item, found)
152-
return found
153-
154-
def search(request, type="", q="", id=""):
79+
def search(request, option="", search="", submit=""):
15580
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
156-
args = request.REQUEST.items()
157-
if args:
158-
for key, value in args:
159-
if key == "option":
160-
type = value
161-
if re.match(".*search", key):
162-
q = value
163-
if re.match(".*id", key):
164-
id = value
165-
if type and q or id:
166-
log("Got query: type=%s, q=%s, id=%s" % (type, q, id))
167-
if type == "document_search":
168-
log("Got document_search")
169-
if q:
170-
start = InternetDraft.objects.filter(filename__contains=q)
171-
log("Found %s drafts containing %s" % (start.count(), q))
172-
if id:
173-
start = InternetDraft.objects.filter(id_document_tag=id)
174-
log("Found %s drafts with id %s" % (start.count(), id))
175-
if start.count() == 1:
176-
first = start[0]
177-
# get all related drafts, then search for IPRs on all
178-
docs = related_docs(first, [])
179-
iprs = []
180-
for doc in docs:
181-
if isinstance(doc, InternetDraft):
182-
disclosures = [ item.ipr for item in IprDraft.objects.filter(document=doc) ]
183-
elif isinstance(doc, Rfc):
184-
disclosures = [ item.ipr for item in IprRfc.objects.filter(document=doc) ]
185-
else:
186-
raise ValueError("Neither draft nor rfc: %s" % doc)
187-
if disclosures:
188-
doc.iprs = disclosures
189-
iprs += disclosures
190-
iprs = list(set(iprs))
191-
return render("ipr/search_result.html", {"first": first, "iprs": iprs, "docs": docs})
192-
elif start.count():
193-
return render("ipr/search_list.html", {"docs": start })
194-
return django.http.HttpResponseRedirect(request.path)
19581
return render("ipr/search.html", {"wgs": wgs})
19682

197-
def form(request):
198-
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
199-
log("Search form")
200-
return render("ipr/search.html", {"wgs": wgs})
201-
20283

20384

20485
# ---- Helper functions ------------------------------------------------------

0 commit comments

Comments
 (0)