33import ietf .utils
44import django .utils .html
55import django .newforms as forms
6+
7+ from datetime import datetime
68from django .shortcuts import render_to_response as render
79from ietf .utils import log
810from ietf .ipr .view_sections import section_table
911from ietf .idtracker .models import Rfc , InternetDraft
12+ from django .http import HttpResponseRedirect
1013
1114# ----------------------------------------------------------------
1215# Callback methods for special field cases.
@@ -20,6 +23,8 @@ def ipr_detail_form_callback(field, **kwargs):
2023 if field .name in ["rfc_number" , "id_document_tag" ]:
2124 log (field .name )
2225 return forms .CharFieldField (required = False )
26+ if field .name in ["date_applied" ]:
27+ return forms .DateField ()
2328 return field .formfield (** kwargs )
2429
2530def ipr_contact_form_callback (field , ** kwargs ):
@@ -136,6 +141,7 @@ def clean_draftlist(self):
136141 if draftlist :
137142 draftlist = re .sub (" *[,;] *" , " " , draftlist )
138143 draftlist = draftlist .strip ().split ()
144+ drafts = []
139145 for draft in draftlist :
140146 if draft .endswith (".txt" ):
141147 draft = draft [:- 4 ]
@@ -145,19 +151,41 @@ def clean_draftlist(self):
145151 else :
146152 filename = draft
147153 rev = None
148- #log("ID: %s, rev %s" % (filename, rev))
149154 try :
150155 id = InternetDraft .objects .get (filename = filename )
151- #log("ID Lookup result: %s, %s" % (id.filename, id.revision))
152156 except Exception , e :
153157 log ("Exception: %s" % e )
154158 raise forms .ValidationError ("Unknown Internet-Draft: %s - please correct this." % filename )
155159 if rev and id .revision != rev :
156160 raise forms .ValidationError ("Unexpected revision '%s' for draft %s - the current revision is %s. Please check this." % (rev , filename , id .revision ))
157- pass
161+ drafts .append ("%s-%s" % (filename , id .revision ))
162+ return " " .join (drafts )
163+ return ""
164+ def clean_holder_contact (self ):
165+ return self .holder_contact .full_clean ()
166+ def clean_ietf_contact (self ):
167+ return self .ietf_contact .full_clean ()
168+ def clean_submitter (self ):
169+ return self .submitter .full_clean ()
170+
158171
159172 if request .method == 'POST' :
160173 data = request .POST .copy ()
174+ data ["submitted_date" ] = datetime .now ().strftime ("%Y-%m-%d" )
175+ data ["third_party" ] = section_list ["third_party" ]
176+ data ["generic" ] = section_list ["generic" ]
177+ data ["status" ] = "0"
178+ data ["comply" ] = "1"
179+
180+ if type == "general" :
181+ data ["document_title" ] = """%(p_h_legal_name)s's General License Statement""" % data
182+ if type == "specific" :
183+ data ["ipr_summary" ] = get_ipr_summary (data )
184+ data ["document_title" ] = """%(p_h_legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data
185+ if type == "third-party" :
186+ data ["ipr_summary" ] = get_ipr_summary (data )
187+ data ["document_title" ] = """%(submitter)s's Statement about IPR related to %(ipr_summary)s belonging to %(p_h_legal_name)s""" % data
188+
161189 for src in ["hold" , "ietf" ]:
162190 if "%s_contact_is_submitter" % src in data :
163191 for subfield in ["name" , "title" , "department" , "address1" , "address2" , "telephone" , "fax" , "email" ]:
@@ -167,15 +195,53 @@ def clean_draftlist(self):
167195 #log("Caught exception: %s"%e)
168196 pass
169197 form = IprForm (data )
170- if form .ietf_contact_is_submitter :
171- form .ietf_contact_is_submitter_checked = "checked"
172198 if form .is_valid ():
173- #instance = form.save()
174- #return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id)
199+ # Save data :
200+ # IprDetail, IprContact+, IprDraft+, IprRfc+, IprNotification
201+
202+ # Save IprDetail
203+ instance = form .save ()
204+ contact_type = {"hold" :1 , "ietf" :2 , "subm" : 3 }
205+
206+ # Save IprContact(s)
207+ for prefix in ["hold" , "ietf" , "subm" ]:
208+ # cdata = {"ipr": instance.ipr_id, "contact_type":contact_type[prefix]}
209+ cdata = {"ipr" : instance , "contact_type" :contact_type [prefix ]}
210+ for item in data :
211+ if item .startswith (prefix + "_" ):
212+ cdata [item [5 :]] = data [item ]
213+ try :
214+ del cdata ["contact_is_submitter" ]
215+ except KeyError :
216+ pass
217+ contact = models .IprContact (** cdata )
218+ contact .save ()
219+ # contact = ContactForm(cdata)
220+ # if contact.is_valid():
221+ # contact.save()
222+ # else:
223+ # log("Invalid contact: %s" % contact)
224+
225+ # Save IprDraft(s)
226+ for draft in form .clean_data ["draftlist" ].split ():
227+ id = InternetDraft .objects .get (filename = draft [:- 3 ])
228+ iprdraft = models .IprDraft (document = id , ipr = instance , revision = draft [- 2 :])
229+ iprdraft .save ()
230+
231+ # Save IprRfc(s)
232+ for rfcnum in form .clean_data ["rfclist" ].split ():
233+ rfc = Rfc .objects .get (rfc_number = int (rfcnum ))
234+ iprrfc = models .IprRfc (rfc_number = rfc , ipr = instance )
235+ iprrfc .save ()
236+
237+ return HttpResponseRedirect ("/ipr/ipr-%s" % instance .ipr_id )
175238 #return HttpResponseRedirect("/ipr/")
176239
177240 pass
178241 else :
242+ if form .ietf_contact_is_submitter :
243+ form .ietf_contact_is_submitter_checked = "checked"
244+
179245 for error in form .errors :
180246 log ("Form error for field: %s" % error )
181247 # Fall through, and let the partially bound form, with error
@@ -187,3 +253,21 @@ def clean_draftlist(self):
187253
188254 # ietf.utils.log(dir(form.ietf_contact_is_submitter))
189255 return render ("ipr/details.html" , {"ipr" : form , "section_list" :section_list , "debug" : debug })
256+
257+
258+ def get_ipr_summary (data ):
259+
260+ rfc_ipr = [ "RFC %s" % item for item in data ["rfclist" ].split () ]
261+ draft_ipr = data ["draftlist" ].split ()
262+ ipr = rfc_ipr + draft_ipr
263+ if data ["other_designations" ]:
264+ ipr += [ data ["other_designations" ] ]
265+
266+ if len (ipr ) == 1 :
267+ ipr = ipr [0 ]
268+ elif len (ipr ) == 2 :
269+ ipr = " and " .join (ipr )
270+ else :
271+ ipr = ", " .join (ipr [:- 1 ] + ", and " + ipr [- 1 ])
272+
273+ return ipr
0 commit comments