Skip to content

Commit 2fa81f4

Browse files
committed
Initial work on allowing updates:
* Allow update to pass in an object to be updated. * Pass initial values to rfclist, draftlist, 3 ContactForms and IprForm if we have an update. * Pass **kwargs through ipr_detail_form_callback to get the initial values. * Add a row in IprUpdate if updating Cleanups in that apply to both new and update: * Validate licensing_option in the clean function to allow it to be conditionally required. * Use a regular character field for date_applied, since it is a prose date in the database. * Fix typo in title setting: s/general/generic/ * Fix typo in 3rd-party title setting: s/submitter/ietf_name/ * Fix IprRfc object creation * Log the complete set of field errors * Move the validation of "one of the document fields must be filled in" to the form clean, since clean_data["draftlist"] isn't available in clean_rfclist() * Render non_field_errors since now we could have one. * Move the setting of the summary and title to after the form is cleaned, and use the clean version of the document names. - Legacy-Id: 683
1 parent 73b1c97 commit 2fa81f4

3 files changed

Lines changed: 76 additions & 31 deletions

File tree

ietf/ipr/new.py

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
def ipr_detail_form_callback(field, **kwargs):
1818
if field.name == "licensing_option":
19-
return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=True)
19+
return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False, **kwargs)
2020
if field.name in ["is_pending", "applies_to_all"]:
21-
return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
21+
return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False, **kwargs)
2222
if field.name in ["rfc_number", "id_document_tag"]:
2323
log(field.name)
24-
return forms.CharFieldField(required=False)
25-
if field.name in ["date_applied"]:
26-
return forms.DateField()
24+
return forms.CharFieldField(required=False, **kwargs)
2725
return field.formfield(**kwargs)
2826

2927
def ipr_contact_form_callback(field, **kwargs):
@@ -76,7 +74,7 @@ def clean(self, *value):
7674
# Form processing
7775
# ----------------------------------------------------------------
7876

79-
def new(request, type):
77+
def new(request, type, update=None):
8078
"""Make a new IPR disclosure.
8179
8280
This is a big function -- maybe too big. Things would be easier if we didn't have
@@ -103,11 +101,24 @@ class IprForm(BaseIprForm):
103101
if "submitter" in section_list:
104102
submitter = ContactForm(prefix="subm")
105103
def __init__(self, *args, **kw):
104+
contact_type = {1:"holder_contact", 2:"ietf_contact", 3:"submitter"}
105+
contact_initial = {}
106+
if update:
107+
for contact in update.contact.all():
108+
contact_initial[contact_type[contact.contact_type]] = contact.__dict__
109+
kwnoinit = kw.copy()
110+
kwnoinit.pop('initial', None)
106111
for contact in ["holder_contact", "ietf_contact", "submitter"]:
107112
if contact in section_list:
108-
self.base_fields[contact] = ContactForm(prefix=contact[:4], *args, **kw)
109-
self.base_fields["rfclist"] = forms.CharField(required=False)
110-
self.base_fields["draftlist"] = forms.CharField(required=False)
113+
self.base_fields[contact] = ContactForm(prefix=contact[:4], initial=contact_initial.get(contact, {}), *args, **kwnoinit)
114+
rfclist_initial = ""
115+
if update:
116+
rfclist_initial = " ".join(["RFC%d" % rfc.document_id for rfc in update.rfcs.all()])
117+
self.base_fields["rfclist"] = forms.CharField(required=False, initial=rfclist_initial)
118+
draftlist_initial = ""
119+
if update:
120+
draftlist_initial = " ".join([draft.document.filename + (draft.revision and "-%s" % draft.revision or "") for draft in update.drafts.all()])
121+
self.base_fields["draftlist"] = forms.CharField(required=False, initial=draftlist_initial)
111122
if "holder_contact" in section_list:
112123
self.base_fields["hold_contact_is_submitter"] = forms.BooleanField(required=False)
113124
if "ietf_contact" in section_list:
@@ -116,6 +127,19 @@ def __init__(self, *args, **kw):
116127

117128
BaseIprForm.__init__(self, *args, **kw)
118129
# Special validation code
130+
def clean(self):
131+
print section_list.get("ietf_doc")
132+
if section_list.get("ietf_doc", False):
133+
# would like to put this in rfclist to get the error
134+
# closer to the fields, but clean_data["draftlist"]
135+
# isn't set yet.
136+
rfclist = self.clean_data.get("rfclist", None)
137+
draftlist = self.clean_data.get("draftlist", None)
138+
other = self.clean_data.get("other_designations", None)
139+
print "rfclist %s draftlist %s other %s" % (rfclist, draftlist, other)
140+
if not rfclist and not draftlist and not other:
141+
raise forms.ValidationError("One of the Document fields below must be filled in")
142+
return self.clean_data
119143
def clean_rfclist(self):
120144
rfclist = self.clean_data.get("rfclist", None)
121145
if rfclist:
@@ -127,13 +151,6 @@ def clean_rfclist(self):
127151
except:
128152
raise forms.ValidationError("Unknown RFC number: %s - please correct this." % rfc)
129153
rfclist = " ".join(rfclist)
130-
else:
131-
# Check that not all three fields are empty. We only need to
132-
# do this for one of the fields.
133-
draftlist = self.clean_data.get("draftlist", None)
134-
other = self.clean_data.get("other_designations", None)
135-
if not draftlist and not other:
136-
raise forms.ValidationError("One of the Document fields below must be filled in")
137154
return rfclist
138155
def clean_draftlist(self):
139156
draftlist = self.clean_data.get("draftlist", None)
@@ -166,6 +183,12 @@ def clean_ietf_contact(self):
166183
return self.ietf_contact.full_clean()
167184
def clean_submitter(self):
168185
return self.submitter.full_clean()
186+
def clean_licensing_option(self):
187+
licensing_option = self.clean_data['licensing_option']
188+
if section_list.get('licensing', False):
189+
if licensing_option in (None, ''):
190+
raise forms.ValidationError, 'This field is required.'
191+
return licensing_option
169192

170193

171194
if request.method == 'POST':
@@ -175,15 +198,6 @@ def clean_submitter(self):
175198
data["generic"] = section_list["generic"]
176199
data["status"] = "0"
177200
data["comply"] = "1"
178-
179-
if type == "general":
180-
data["title"] = """%(legal_name)s's General License Statement""" % data
181-
if type == "specific":
182-
data["ipr_summary"] = get_ipr_summary(data)
183-
data["title"] = """%(legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
184-
if type == "third-party":
185-
data["ipr_summary"] = get_ipr_summary(data)
186-
data["title"] = """%(submitter)s's Statement about IPR related to %(ipr_summary)s belonging to %(legal_name)s""" % data
187201

188202
for src in ["hold", "ietf"]:
189203
if "%s_contact_is_submitter" % src in data:
@@ -199,7 +213,22 @@ def clean_submitter(self):
199213
# IprDetail, IprContact+, IprDraft+, IprRfc+, IprNotification
200214

201215
# Save IprDetail
202-
instance = form.save()
216+
instance = form.save(commit=False)
217+
218+
if type == "generic":
219+
instance.title = """%(legal_name)s's General License Statement""" % data
220+
if type == "specific":
221+
data["ipr_summary"] = get_ipr_summary(form.clean_data)
222+
instance.title = """%(legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
223+
if type == "third-party":
224+
data["ipr_summary"] = get_ipr_summary(form.clean_data)
225+
instance.title = """%(ietf_name)s's Statement about IPR related to %(ipr_summary)s belonging to %(legal_name)s""" % data
226+
227+
instance.save()
228+
229+
if update:
230+
updater = models.IprUpdate(ipr=instance, updated=update, status_to_be=1, processed=0)
231+
updater.save()
203232
contact_type = {"hold":1, "ietf":2, "subm": 3}
204233

205234
# Save IprContact(s)
@@ -230,7 +259,7 @@ def clean_submitter(self):
230259
# Save IprRfc(s)
231260
for rfcnum in form.clean_data["rfclist"].split():
232261
rfc = Rfc.objects.get(rfc_number=int(rfcnum))
233-
iprrfc = models.IprRfc(rfc_number=rfc, ipr=instance)
262+
iprrfc = models.IprRfc(document=rfc, ipr=instance)
234263
iprrfc.save()
235264

236265
return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id)
@@ -242,12 +271,15 @@ def clean_submitter(self):
242271
form.ietf_contact_is_submitter_checked = "checked"
243272

244273
for error in form.errors:
245-
log("Form error for field: %s"%error)
274+
log("Form error for field: %s: %s"%(error, form.errors[error]))
246275
# Fall through, and let the partially bound form, with error
247276
# indications, be rendered again.
248277
pass
249278
else:
250-
form = IprForm()
279+
if update:
280+
form = IprForm(initial=update.__dict__)
281+
else:
282+
form = IprForm()
251283
form.unbound_form = True
252284

253285
# ietf.utils.log(dir(form.ietf_contact_is_submitter))

ietf/ipr/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ietf.idtracker.models import IETFWG
66
from ietf.ipr.models import IprDetail, SELECT_CHOICES, LICENSE_CHOICES
77
from ietf.ipr.view_sections import section_table
8+
from ietf.ipr.new import new
89
from ietf.utils import log
910

1011
def linebreaks(value):
@@ -80,8 +81,13 @@ def show(request, ipr_id=None):
8081

8182
def update(request, ipr_id=None):
8283
"""Update a specific IPR disclosure"""
83-
# TODO: replace the placeholder code with the appropriate update code
84-
return show(request, ipr_id)
84+
ipr = IprDetail.objects.get(ipr_id=ipr_id)
85+
type = "specific"
86+
if ipr.generic:
87+
type = "generic"
88+
if ipr.third_party:
89+
type = "third-party"
90+
return new(request, type, ipr)
8591

8692

8793

ietf/templates/ipr/details.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ <h4 class="ipr">The Patent Disclosure and Licensing Declaration Template for {{
180180
{% if ipr.errors %}
181181
<p class="errorlist">
182182
There were errors in the submitted form -- see below. Please correct these and resubmit.
183+
{% if ipr.non_field_errors %}
184+
<ul class="errorlist">
185+
{% for error in ipr.non_field_errors %}
186+
<li>{{ error }}</li>
187+
{% endfor %}
188+
</ul>
189+
{% endif %}
183190
</p>
184191
{% endif %}
185192

0 commit comments

Comments
 (0)