Skip to content

Commit e5610d3

Browse files
committed
* Explicitly truncate a long title so that the database truncation doesn't cause problems
* Use RequestContext * Remove a couple of debugging prints that I left in * Fix parenthesis location in get_ipr_summary() which was causing it to try to concatenate a list and a string - Legacy-Id: 684
1 parent 2fa81f4 commit e5610d3

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

ietf/ipr/new.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from datetime import datetime
77
from django.shortcuts import render_to_response as render
8+
from django.template import RequestContext
89
from ietf.utils import log
910
from ietf.ipr.view_sections import section_table
1011
from ietf.idtracker.models import Rfc, InternetDraft
@@ -127,19 +128,17 @@ def __init__(self, *args, **kw):
127128

128129
BaseIprForm.__init__(self, *args, **kw)
129130
# 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
131+
def clean(self):
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+
if not rfclist and not draftlist and not other:
140+
raise forms.ValidationError("One of the Document fields below must be filled in")
141+
return self.clean_data
143142
def clean_rfclist(self):
144143
rfclist = self.clean_data.get("rfclist", None)
145144
if rfclist:
@@ -215,16 +214,23 @@ def clean_licensing_option(self):
215214
# Save IprDetail
216215
instance = form.save(commit=False)
217216

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
217+
if type == "generic":
218+
instance.title = """%(legal_name)s's General License Statement""" % data
219+
if type == "specific":
220+
data["ipr_summary"] = get_ipr_summary(form.clean_data)
221+
instance.title = """%(legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
222+
if type == "third-party":
223+
data["ipr_summary"] = get_ipr_summary(form.clean_data)
224+
instance.title = """%(ietf_name)s's Statement about IPR related to %(ipr_summary)s belonging to %(legal_name)s""" % data
225+
226+
# A long document list can create a too-long title;
227+
# saving a too-long title raises an exception,
228+
# so prevent truncation in the database layer by
229+
# performing it explicitly.
230+
if len(instance.title) > 255:
231+
instance.title = instance.title[:252] + "..."
226232

227-
instance.save()
233+
instance.save()
228234

229235
if update:
230236
updater = models.IprUpdate(ipr=instance, updated=update, status_to_be=1, processed=0)
@@ -283,7 +289,7 @@ def clean_licensing_option(self):
283289
form.unbound_form = True
284290

285291
# ietf.utils.log(dir(form.ietf_contact_is_submitter))
286-
return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug})
292+
return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug}, context_instance=RequestContext(request))
287293

288294

289295
def get_ipr_summary(data):
@@ -299,6 +305,6 @@ def get_ipr_summary(data):
299305
elif len(ipr) == 2:
300306
ipr = " and ".join(ipr)
301307
else:
302-
ipr = ", ".join(ipr[:-1] + ", and " + ipr[-1])
308+
ipr = ", ".join(ipr[:-1]) + ", and " + ipr[-1]
303309

304310
return ipr

0 commit comments

Comments
 (0)