Skip to content

Commit 64dc0f8

Browse files
committed
* Some code reorganization, moving the large new-disclosure functiality
into view_new.py * Added error indication of the top of the page, in case there are any errors further down. * Set more fields to required, matching the old perl code * Various other tweaks. - Legacy-Id: 140
1 parent b0f1f5d commit 64dc0f8

7 files changed

Lines changed: 257 additions & 213 deletions

File tree

ietf/ipr/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class IprDetail(models.Model):
7878
discloser_identify = models.TextField("Specific document sections covered", blank=True, maxlength=255, db_column='disclouser_identify')
7979

8080
# Patent Information fieldset
81-
p_applications = models.TextField("Patent Applications", blank=True, maxlength=255)
82-
date_applied = models.CharField(blank=True, maxlength=255)
83-
country = models.CharField(blank=True, maxlength=100)
81+
p_applications = models.TextField("Patent Applications", maxlength=255)
82+
date_applied = models.DateField(maxlength=255)
83+
country = models.CharField(maxlength=100)
8484
p_notes = models.TextField("Additional notes", blank=True)
8585
selecttype = models.IntegerField("Unpublished Pending Patent Application", null=True, choices=SELECT_CHOICES)
8686
selectowned = models.IntegerField("Applies to all IPR owned by Submitter", null=True, blank=True, choices=SELECT_CHOICES)

ietf/ipr/view_new.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import re
2+
import models
3+
import ietf.utils
4+
import django.utils.html
5+
import django.newforms as forms
6+
from django.shortcuts import render_to_response as render
7+
from ietf.utils import log
8+
from ietf.ipr.view_sections import section_table
9+
10+
# ----------------------------------------------------------------
11+
# Callback methods for special field cases.
12+
# ----------------------------------------------------------------
13+
14+
def ipr_detail_form_callback(field, **kwargs):
15+
if field.name == "licensing_option":
16+
return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=True)
17+
if field.name in ["selecttype", "selectowned"]:
18+
return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
19+
return field.formfield(**kwargs)
20+
21+
def ipr_contact_form_callback(field, **kwargs):
22+
phone_re = re.compile(r'^\+?[0-9 ]*(\([0-9]+\))?[0-9 -]+$')
23+
error_message = """Phone numbers may have a leading "+", and otherwise only contain
24+
numbers [0-9]; dash, period or space; parentheses, and an optional
25+
extension number indicated by 'x'. """
26+
27+
if field.name == "telephone":
28+
return forms.RegexField(phone_re, error_message=error_message, **kwargs)
29+
if field.name == "fax":
30+
return forms.RegexField(phone_re, error_message=error_message, required=False, **kwargs)
31+
return field.formfield(**kwargs)
32+
# TODO:
33+
# Add rfc existence validation for RFC field
34+
# Add draft existence validation for Drafts field
35+
36+
# ----------------------------------------------------------------
37+
# Classes
38+
# ----------------------------------------------------------------
39+
40+
# Get a form class which renders fields using a given template
41+
CustomForm = ietf.utils.makeFormattingForm(template="ipr/formfield.html")
42+
43+
# Get base form classes for our models
44+
BaseIprForm = forms.form_for_model(models.IprDetail, form=CustomForm, formfield_callback=ipr_detail_form_callback)
45+
BaseContactForm = forms.form_for_model(models.IprContact, form=CustomForm, formfield_callback=ipr_contact_form_callback)
46+
47+
# Some subclassing:
48+
49+
# The contact form will be part of the IprForm, so it needs a widget.
50+
# Define one.
51+
class MultiformWidget(forms.Widget):
52+
def value_from_datadict(self, data, name):
53+
return data
54+
55+
class ContactForm(BaseContactForm):
56+
widget = MultiformWidget()
57+
58+
def add_prefix(self, field_name):
59+
return self.prefix and ('%s_%s' % (self.prefix, field_name)) or field_name
60+
def clean(self, *value):
61+
if value:
62+
return self.full_clean()
63+
else:
64+
return self.clean_data
65+
66+
67+
# ----------------------------------------------------------------
68+
# Form processing
69+
# ----------------------------------------------------------------
70+
71+
def new(request, type):
72+
"""Make a new IPR disclosure.
73+
74+
This is a big function -- maybe too big. Things would be easier if we didn't have
75+
one form containing fields from 4 tables -- don't build something like this again...
76+
77+
"""
78+
debug = ""
79+
80+
section_list = section_table[type].copy()
81+
section_list.update({"title":False, "new_intro":False, "form_intro":True,
82+
"form_submit":True, "form_legend": True, })
83+
84+
class IprForm(BaseIprForm):
85+
holder_contact = None
86+
rfclist = forms.CharField(required=False)
87+
draftlist = forms.CharField(required=False)
88+
stdonly_license = forms.BooleanField(required=False)
89+
ietf_contact_is_submitter = forms.BooleanField(required=False)
90+
if "holder_contact" in section_list:
91+
holder_contact = ContactForm(prefix="hold")
92+
if "ietf_contact" in section_list:
93+
ietf_contact = ContactForm(prefix="ietf")
94+
if "submitter" in section_list:
95+
submitter = ContactForm(prefix="subm")
96+
def __init__(self, *args, **kw):
97+
for contact in ["holder_contact", "ietf_contact", "submitter"]:
98+
if contact in section_list:
99+
self.base_fields[contact] = ContactForm(prefix=contact[:4], *args, **kw)
100+
self.base_fields["ietf_contact_is_submitter"] = forms.BooleanField(required=False)
101+
BaseIprForm.__init__(self, *args, **kw)
102+
# Special validation code
103+
def clean(self):
104+
# Required:
105+
# Submitter form filled in or 'same-as-ietf-contact' marked
106+
# Only one of rfc, draft, and other info fields filled in
107+
# RFC exists or draft exists and has right rev. or ...
108+
109+
if self.ietf_contact_is_submitter:
110+
self.submitter = self.ietf_contact
111+
pass
112+
if request.method == 'POST':
113+
data = request.POST.copy()
114+
if "ietf_contact_is_submitter" in data:
115+
for subfield in ["name", "title", "department", "address1", "address2", "telephone", "fax", "email"]:
116+
try:
117+
data["subm_%s"%subfield] = data["ietf_%s"%subfield]
118+
except Exception, e:
119+
#log("Caught exception: %s"%e)
120+
pass
121+
form = IprForm(data)
122+
if form.ietf_contact_is_submitter:
123+
form.ietf_contact_is_submitter_checked = "checked"
124+
if form.is_valid():
125+
#instance = form.save()
126+
#return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id)
127+
#return HttpResponseRedirect("/ipr/")
128+
129+
pass
130+
else:
131+
for error in form.errors:
132+
log("Form error for field: %s"%error)
133+
# Fall through, and let the partially bound form, with error
134+
# indications, be rendered again.
135+
pass
136+
else:
137+
form = IprForm()
138+
form.unbound_form = True
139+
140+
# ietf.utils.log(dir(form.ietf_contact_is_submitter))
141+
return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug})

ietf/ipr/view_sections.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
section_table = {
3+
"index": { "index": True },
4+
"specific": { "index": False, "title": True, "specific": True,
5+
"legacy_intro": False, "new_intro": True, "form_intro": False,
6+
"holder": True, "holder_contact": True, "ietf_contact": True,
7+
"ietf_doc": True, "patent_info": True, "licensing": True,
8+
"submitter": True, "notes": True, "form_submit": False,
9+
"disclosure_type": "Specific", "form_legend": False,
10+
"per_rfc_disclosure": True, "also_specific": False,
11+
},
12+
"generic": { "index": False, "title": True, "generic": True,
13+
"legacy_intro": False, "new_intro": True, "form_intro": False,
14+
"holder": True, "holder_contact": True, "ietf_contact": False,
15+
"ietf_doc": False, "patent_info": True, "licensing": True,
16+
"submitter": True, "notes": True, "form_submit": False,
17+
"disclosure_type": "Generic", "form_legend": False,
18+
"per_rfc_disclosure": False, "also_specific": True,
19+
},
20+
"third_party": {"index": False, "title": True, "third_party": True,
21+
"legacy_intro": False, "new_intro": True, "form_intro": False,
22+
"holder": True, "holder_contact": False, "ietf_contact": True,
23+
"ietf_doc": True, "patent_info": True, "licensing": False,
24+
"submitter": False, "notes": False, "form_submit": False,
25+
"disclosure_type": "Third Party", "form_legend": False,
26+
"per_rfc_disclosure": False, "also_specific": False,
27+
},
28+
"legacy": { "index": False, "title": True, "legacy": True,
29+
"legacy_intro": True, "new_intro": False, "form_intro": False,
30+
"holder": True, "holder_contact": True, "ietf_contact": False,
31+
"ietf_doc": True, "patent_info": False, "licensing": False,
32+
"submitter": False, "notes": False, "form_submit": False,
33+
"disclosure_type": "Legacy", "form_legend": False,
34+
"per_rfc_disclosure": False, "also_specific": False,
35+
},
36+
}

ietf/ipr/views.py

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import re
22
import models
3-
import ietf.utils
43
import django.utils.html
5-
import django.newforms as forms
64
from django.shortcuts import render_to_response as render
75
from django.utils.html import escape
8-
from ietf.contrib.form_decorator import form_decorator
9-
from ietf.utils import log as log
6+
from ietf.ipr.view_new import new
7+
from ietf.ipr.view_sections import section_table
108

119
def linebreaks(value):
1210
if value:
@@ -42,39 +40,10 @@ def list(request, template):
4240

4341
# Details views
4442

45-
section_table = {
46-
"index": { "index": True },
47-
"specific": { "index": False, "title": True, "specific": True,
48-
"legacy_intro": False, "new_intro": True, "form_intro": False,
49-
"holder": True, "holder_contact": True, "ietf_contact": True,
50-
"ietf_doc": True, "patent_info": True, "licensing": True,
51-
"submitter": True, "notes": True, "form_submit": False,
52-
},
53-
"generic": { "index": False, "title": True, "generic": True,
54-
"legacy_intro": False, "new_intro": True, "form_intro": False,
55-
"holder": True, "holder_contact": True, "ietf_contact": False,
56-
"ietf_doc": False, "patent_info": True, "licensing": True,
57-
"submitter": True, "notes": True, "form_submit": False,
58-
},
59-
"third_party": {"index": False, "title": True, "third_party": True,
60-
"legacy_intro": False, "new_intro": True, "form_intro": False,
61-
"holder": True, "holder_contact": False, "ietf_contact": True,
62-
"ietf_doc": True, "patent_info": True, "licensing": False,
63-
"submitter": False, "notes": False, "form_submit": False,
64-
},
65-
"legacy": { "index": False, "title": True, "legacy": True,
66-
"legacy_intro": True, "new_intro": False, "form_intro": False,
67-
"holder": True, "holder_contact": True, "ietf_contact": False,
68-
"ietf_doc": True, "patent_info": False, "licensing": False,
69-
"submitter": False, "notes": False, "form_submit": False,
70-
},
71-
}
72-
7343
def show(request, ipr_id=None):
7444
"""Show a specific IPR disclosure"""
7545
assert ipr_id != None
7646
ipr = models.IprDetail.objects.filter(ipr_id=ipr_id)[0]
77-
ipr.disclosure_type = get_disclosure_type(ipr)
7847
section_list = get_section_list(ipr)
7948
contacts = ipr.contact.all()
8049
for contact in contacts:
@@ -105,130 +74,10 @@ def update(request, ipr_id=None):
10574
# TODO: replace the placeholder code with the appropriate update code
10675
return show(request, ipr_id)
10776

108-
def new(request, type):
109-
"""Make a new IPR disclosure"""
110-
debug = ""
111-
112-
# define callback methods for special field cases.
113-
def ipr_detail_form_callback(field, **kwargs):
114-
if field.name == "licensing_option":
115-
return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False)
116-
if field.name in ["selecttype", "selectowned"]:
117-
return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
118-
return field.formfield(**kwargs)
119-
120-
def ipr_contact_form_callback(field, **kwargs):
121-
phone_re = re.compile(r'^\+?[0-9 ]*(\([0-9]+\))?[0-9 -]+$')
122-
error_message = """Phone numbers may have a leading "+", and otherwise only contain
123-
numbers [0-9]; dash, period or space; parentheses, and an optional
124-
extension number indicated by 'x'. """
125-
126-
if field.name == "telephone":
127-
return forms.RegexField(phone_re, error_message=error_message, **kwargs)
128-
if field.name == "fax":
129-
return forms.RegexField(phone_re, error_message=error_message, required=False, **kwargs)
130-
return field.formfield(**kwargs)
131-
132-
# Get a form class which renders fields using a given template
133-
CustomForm = ietf.utils.makeFormattingForm(template="ipr/formfield.html")
134-
135-
# Get base form classes for our models
136-
BaseIprForm = forms.form_for_model(models.IprDetail, form=CustomForm, formfield_callback=ipr_detail_form_callback)
137-
BaseContactForm = forms.form_for_model(models.IprContact, form=CustomForm, formfield_callback=ipr_contact_form_callback)
138-
139-
section_list = section_table[type]
140-
section_list.update({"title":False, "new_intro":False, "form_intro":True, "form_submit":True, })
141-
142-
# Some subclassing:
143-
144-
# The contact form will be part of the IprForm, so it needs a widget.
145-
# Define one.
146-
class MultiformWidget(forms.Widget):
147-
def value_from_datadict(self, data, name):
148-
return data
149-
150-
class ContactForm(BaseContactForm):
151-
widget = MultiformWidget()
152-
153-
def add_prefix(self, field_name):
154-
return self.prefix and ('%s_%s' % (self.prefix, field_name)) or field_name
155-
def clean(self, *value):
156-
if value:
157-
return self.full_clean()
158-
else:
159-
return self.clean_data
160-
161-
class IprForm(BaseIprForm):
162-
holder_contact = None
163-
rfclist = forms.CharField(required=False)
164-
draftlist = forms.CharField(required=False)
165-
stdonly_license = forms.BooleanField(required=False)
166-
ietf_contact_is_submitter = forms.BooleanField(required=False)
167-
if "holder_contact" in section_list:
168-
holder_contact = ContactForm(prefix="hold")
169-
if "ietf_contact" in section_list:
170-
ietf_contact = ContactForm(prefix="ietf")
171-
if "submitter" in section_list:
172-
submitter = ContactForm(prefix="subm")
173-
def __init__(self, *args, **kw):
174-
for contact in ["holder_contact", "ietf_contact", "submitter"]:
175-
if contact in section_list:
176-
self.base_fields[contact] = ContactForm(prefix=contact[:4], *args, **kw)
177-
self.base_fields["ietf_contact_is_submitter"] = forms.BooleanField(required=False)
178-
BaseIprForm.__init__(self, *args, **kw)
179-
# Special validation code
180-
def clean(self):
181-
# Required:
182-
# Submitter form filled in or 'same-as-ietf-contact' marked
183-
# Only one of rfc, draft, and other info fields filled in
184-
# RFC exists or draft exists and has right rev. or ...
185-
if self.ietf_contact_is_submitter:
186-
self.submitter = self.ietf_contact
187-
pass
188-
189-
if request.method == 'POST':
190-
data = request.POST.copy()
191-
if "ietf_contact_is_submitter" in data:
192-
for subfield in ["name", "title", "department", "address1", "address2", "telephone", "fax", "email"]:
193-
try:
194-
data["subm_%s"%subfield] = data["ietf_%s"%subfield]
195-
except Exception, e:
196-
#log("Caught exception: %s"%e)
197-
pass
198-
form = IprForm(data)
199-
if form.ietf_contact_is_submitter:
200-
form.ietf_contact_is_submitter_checked = "checked"
201-
if form.is_valid():
202-
#instance = form.save()
203-
#return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id)
204-
#return HttpResponseRedirect("/ipr/")
205-
pass
206-
else:
207-
for error in form.errors:
208-
log("Form error: %s"%error)
209-
# Fall through, and let the partially bound form, with error
210-
# indications, be rendered again.
211-
pass
212-
else:
213-
form = IprForm()
214-
form.unbound_form = True
215-
216-
# ietf.utils.log(dir(form.ietf_contact_is_submitter))
217-
return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug})
218-
21977

22078

22179
# ---- Helper functions ------------------------------------------------------
22280

223-
def get_disclosure_type(ipr):
224-
if ipr.generic:
225-
assert not ipr.third_party
226-
return "Generic"
227-
elif ipr.third_party:
228-
return "Third Party"
229-
else:
230-
return "Specific"
231-
23281
def get_section_list(ipr):
23382
if ipr.old_ipr_url:
23483
return section_table["legacy"]

0 commit comments

Comments
 (0)