From fb5013e849380975851866067d87140af366563b Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 23 May 2007 20:11:34 +0000 Subject: [PATCH] IPR disclosure form submission now works. Closing the ipr_generic.cgi ticket, but leaving ipr.cgi and notify.cgi open till further testing has been done. Also adding a new task for the IPR update form. There may still be some dead code to clean out, but I'm committing what I have now since it provides working form submission :-) - Legacy-Id: 158 --- ietf/ipr/models.py | 46 ++++++++-------- ietf/ipr/view_new.py | 98 ++++++++++++++++++++++++++++++--- ietf/ipr/view_sections.py | 9 ++- ietf/ipr/views.py | 14 +++-- ietf/templates/ipr/details.html | 8 +-- 5 files changed, 133 insertions(+), 42 deletions(-) diff --git a/ietf/ipr/models.py b/ietf/ipr/models.py index 27faf15d4..fafacaa97 100644 --- a/ietf/ipr/models.py +++ b/ietf/ipr/models.py @@ -79,11 +79,11 @@ class IprDetail(models.Model): # Patent Information fieldset p_applications = models.TextField("Patent Applications", maxlength=255) - date_applied = models.DateField(maxlength=255) + date_applied = models.CharField(maxlength=255) country = models.CharField(maxlength=100) p_notes = models.TextField("Additional notes", blank=True) - selecttype = models.IntegerField("Unpublished Pending Patent Application", null=True, choices=SELECT_CHOICES) - selectowned = models.IntegerField("Applies to all IPR owned by Submitter", null=True, blank=True, choices=SELECT_CHOICES) + selecttype = models.IntegerField("Unpublished Pending Patent Application", blank=True, choices=SELECT_CHOICES) + selectowned = models.IntegerField("Applies to all IPR owned by Submitter", blank=True, choices=SELECT_CHOICES) # Licensing Declaration fieldset #licensing_option = models.ForeignKey(IprLicensing, db_column='licensing_option') @@ -94,16 +94,18 @@ class IprDetail(models.Model): comments = models.TextField("Licensing Comments", blank=True) lic_checkbox = models.BooleanField("All terms and conditions has been disclosed") - third_party = models.BooleanField(editable=False) # Other notes fieldset other_notes = models.TextField(blank=True) # Generated fields, not part of the submission form + # Hidden fields + third_party = models.BooleanField() + generic = models.BooleanField() + comply = models.BooleanField() + status = models.IntegerField(null=True, blank=True) - comply = models.BooleanField(editable=False) - generic = models.BooleanField(editable=False) - submitted_date = models.DateField(null=True, blank=True) + submitted_date = models.DateField(blank=True) update_notified_date = models.DateField(null=True, blank=True) def __str__(self): @@ -118,21 +120,21 @@ class IprDetail(models.Model): return "YES" else: return "NO" - def get_patent_holder_contact(self): - try: - return self.contact.filter(contact_type=1)[0] - except: - return None - def get_ietf_contact(self): - try: - return self.contact.filter(contact_type=2)[0] - except: - return None - def get_submitter(self): - try: - return self.contact.filter(contact_type=3)[0] - except: - return None +# def get_patent_holder_contact(self): +# try: +# return self.contact.filter(contact_type=1)[0] +# except: +# return None +# def get_ietf_contact(self): +# try: +# return self.contact.filter(contact_type=2)[0] +# except: +# return None +# def get_submitter(self): +# try: +# return self.contact.filter(contact_type=3)[0] +# except: +# return None def get_absolute_url(self): return "/ipr/ipr-%s" % self.ipr_id class Meta: diff --git a/ietf/ipr/view_new.py b/ietf/ipr/view_new.py index 9e9ba806e..71b014985 100644 --- a/ietf/ipr/view_new.py +++ b/ietf/ipr/view_new.py @@ -3,10 +3,13 @@ import models import ietf.utils import django.utils.html import django.newforms as forms + +from datetime import datetime from django.shortcuts import render_to_response as render from ietf.utils import log from ietf.ipr.view_sections import section_table from ietf.idtracker.models import Rfc, InternetDraft +from django.http import HttpResponseRedirect # ---------------------------------------------------------------- # Callback methods for special field cases. @@ -20,6 +23,8 @@ def ipr_detail_form_callback(field, **kwargs): if field.name in ["rfc_number", "id_document_tag"]: log(field.name) return forms.CharFieldField(required=False) + if field.name in ["date_applied"]: + return forms.DateField() return field.formfield(**kwargs) def ipr_contact_form_callback(field, **kwargs): @@ -136,6 +141,7 @@ def new(request, type): if draftlist: draftlist = re.sub(" *[,;] *", " ", draftlist) draftlist = draftlist.strip().split() + drafts = [] for draft in draftlist: if draft.endswith(".txt"): draft = draft[:-4] @@ -145,19 +151,41 @@ def new(request, type): else: filename = draft rev = None - #log("ID: %s, rev %s" % (filename, rev)) try: id = InternetDraft.objects.get(filename=filename) - #log("ID Lookup result: %s, %s" % (id.filename, id.revision)) except Exception, e: log("Exception: %s" % e) raise forms.ValidationError("Unknown Internet-Draft: %s - please correct this." % filename) if rev and id.revision != rev: raise forms.ValidationError("Unexpected revision '%s' for draft %s - the current revision is %s. Please check this." % (rev, filename, id.revision)) - pass + drafts.append("%s-%s" % (filename, id.revision)) + return " ".join(drafts) + return "" + def clean_holder_contact(self): + return self.holder_contact.full_clean() + def clean_ietf_contact(self): + return self.ietf_contact.full_clean() + def clean_submitter(self): + return self.submitter.full_clean() + if request.method == 'POST': data = request.POST.copy() + data["submitted_date"] = datetime.now().strftime("%Y-%m-%d") + data["third_party"] = section_list["third_party"] + data["generic"] = section_list["generic"] + data["status"] = "0" + data["comply"] = "1" + + if type == "general": + data["document_title"] = """%(p_h_legal_name)s's General License Statement""" % data + if type == "specific": + data["ipr_summary"] = get_ipr_summary(data) + data["document_title"] = """%(p_h_legal_name)s's Statement about IPR related to %(ipr_summary)s""" % data + if type == "third-party": + data["ipr_summary"] = get_ipr_summary(data) + data["document_title"] = """%(submitter)s's Statement about IPR related to %(ipr_summary)s belonging to %(p_h_legal_name)s""" % data + for src in ["hold", "ietf"]: if "%s_contact_is_submitter" % src in data: for subfield in ["name", "title", "department", "address1", "address2", "telephone", "fax", "email"]: @@ -167,15 +195,53 @@ def new(request, type): #log("Caught exception: %s"%e) pass form = IprForm(data) - if form.ietf_contact_is_submitter: - form.ietf_contact_is_submitter_checked = "checked" if form.is_valid(): - #instance = form.save() - #return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id) + # Save data : + # IprDetail, IprContact+, IprDraft+, IprRfc+, IprNotification + + # Save IprDetail + instance = form.save() + contact_type = {"hold":1, "ietf":2, "subm": 3} + + # Save IprContact(s) + for prefix in ["hold", "ietf", "subm"]: +# cdata = {"ipr": instance.ipr_id, "contact_type":contact_type[prefix]} + cdata = {"ipr": instance, "contact_type":contact_type[prefix]} + for item in data: + if item.startswith(prefix+"_"): + cdata[item[5:]] = data[item] + try: + del cdata["contact_is_submitter"] + except KeyError: + pass + contact = models.IprContact(**cdata) + contact.save() +# contact = ContactForm(cdata) +# if contact.is_valid(): +# contact.save() +# else: +# log("Invalid contact: %s" % contact) + + # Save IprDraft(s) + for draft in form.clean_data["draftlist"].split(): + id = InternetDraft.objects.get(filename=draft[:-3]) + iprdraft = models.IprDraft(document=id, ipr=instance, revision=draft[-2:]) + iprdraft.save() + + # Save IprRfc(s) + for rfcnum in form.clean_data["rfclist"].split(): + rfc = Rfc.objects.get(rfc_number=int(rfcnum)) + iprrfc = models.IprRfc(rfc_number=rfc, ipr=instance) + iprrfc.save() + + return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id) #return HttpResponseRedirect("/ipr/") pass else: + if form.ietf_contact_is_submitter: + form.ietf_contact_is_submitter_checked = "checked" + for error in form.errors: log("Form error for field: %s"%error) # Fall through, and let the partially bound form, with error @@ -187,3 +253,21 @@ def new(request, type): # ietf.utils.log(dir(form.ietf_contact_is_submitter)) return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug}) + + +def get_ipr_summary(data): + + rfc_ipr = [ "RFC %s" % item for item in data["rfclist"].split() ] + draft_ipr = data["draftlist"].split() + ipr = rfc_ipr + draft_ipr + if data["other_designations"]: + ipr += [ data["other_designations"] ] + + if len(ipr) == 1: + ipr = ipr[0] + elif len(ipr) == 2: + ipr = " and ".join(ipr) + else: + ipr = ", ".join(ipr[:-1] + ", and " + ipr[-1]) + + return ipr diff --git a/ietf/ipr/view_sections.py b/ietf/ipr/view_sections.py index e5d2168d5..a7fa691c0 100644 --- a/ietf/ipr/view_sections.py +++ b/ietf/ipr/view_sections.py @@ -1,7 +1,8 @@ section_table = { "index": { "index": True }, - "specific": { "index": False, "title": True, "specific": True, + "specific": { "index": False, "title": True, + "specific": 1, "generic": 0, "third_party": 0, "legacy_intro": False, "new_intro": True, "form_intro": False, "holder": True, "holder_contact": True, "ietf_contact": True, "ietf_doc": True, "patent_info": True, "licensing": True, @@ -9,7 +10,8 @@ section_table = { "disclosure_type": "Specific", "form_legend": False, "per_rfc_disclosure": True, "also_specific": False, }, - "generic": { "index": False, "title": True, "generic": True, + "generic": { "index": False, "title": True, + "specific": 0, "generic": 1, "third_party": 0, "legacy_intro": False, "new_intro": True, "form_intro": False, "holder": True, "holder_contact": True, "ietf_contact": False, "ietf_doc": False, "patent_info": True, "licensing": True, @@ -17,7 +19,8 @@ section_table = { "disclosure_type": "Generic", "form_legend": False, "per_rfc_disclosure": False, "also_specific": True, }, - "third-party": {"index": False, "title": True, "third_party": True, + "third-party": {"index": False, "title": True, + "specific": 0, "generic": 0, "third_party": 1, "legacy_intro": False, "new_intro": True, "form_intro": False, "holder": True, "holder_contact": False, "ietf_contact": True, "ietf_doc": True, "patent_info": True, "licensing": False, diff --git a/ietf/ipr/views.py b/ietf/ipr/views.py index 5284c729a..e6ab2a6af 100644 --- a/ietf/ipr/views.py +++ b/ietf/ipr/views.py @@ -5,6 +5,7 @@ from django.shortcuts import render_to_response as render from django.utils.html import escape from ietf.ipr.view_new import new from ietf.ipr.view_sections import section_table +from ietf.utils import log def linebreaks(value): if value: @@ -54,7 +55,7 @@ def show(request, ipr_id=None): elif contact.contact_type == 3: ipr.submitter = contact else: - raise KeyError("Unexpected contact_type in ipr_contacts: ipr_id=%s" % ipr.ipr_id) + raise KeyError("Unexpected contact_type (%s) in ipr_contacts for ipr_id=%s" % (contact.contact_type, ipr.ipr_id)) # do escaping and line-breaking here instead of in the template, # so that we can use the template for the form display, too. ipr.p_notes = linebreaks(escape(ipr.p_notes)) @@ -62,9 +63,10 @@ def show(request, ipr_id=None): ipr.comments = linebreaks(escape(ipr.comments)) ipr.other_notes = linebreaks(escape(ipr.other_notes)) - ipr.licensing_option = dict(models.LICENSE_CHOICES)[ipr.licensing_option] - ipr.selecttype = dict(models.SELECT_CHOICES)[ipr.selecttype] - + if ipr.licensing_option: + ipr.licensing_option = dict(models.LICENSE_CHOICES)[ipr.licensing_option] + if ipr.selecttype: + ipr.selecttype = dict(models.SELECT_CHOICES)[ipr.selecttype] if ipr.selectowned: ipr.selectowned = dict(models.SELECT_CHOICES)[ipr.selectowned] return render("ipr/details.html", {"ipr": ipr, "section_list": section_list}) @@ -82,9 +84,9 @@ def get_section_list(ipr): if ipr.old_ipr_url: return section_table["legacy"] elif ipr.generic: - assert not ipr.third_party + #assert not ipr.third_party return section_table["generic"] elif ipr.third_party: - return section_table["third_party"] + return section_table["third-party"] else: return section_table["specific"] diff --git a/ietf/templates/ipr/details.html b/ietf/templates/ipr/details.html index f3d843f1b..b3ac6289b 100644 --- a/ietf/templates/ipr/details.html +++ b/ietf/templates/ipr/details.html @@ -359,10 +359,7 @@ - {{ ipr.licensing_option }} - {{ ipr.get_lic_opt_a_sub_display }} - {{ ipr.get_lic_opt_b_sub_display }} - {{ ipr.get_lic_opt_c_sub_display }} + {{ ipr.licensing_option }} @@ -475,6 +472,9 @@ {% endif %} {% if section_list.form_submit %} + + +