1616
1717def 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
2927def 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))
0 commit comments