datatracker/ietf/ipr/views.py
Bill Fenner 2fa81f4940 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
2007-06-27 04:07:01 +00:00

113 lines
4.2 KiB
Python

import django.utils.html
from django.shortcuts import render_to_response as render
from django.template import RequestContext
from django.utils.html import escape
from ietf.idtracker.models import IETFWG
from ietf.ipr.models import IprDetail, SELECT_CHOICES, LICENSE_CHOICES
from ietf.ipr.view_sections import section_table
from ietf.ipr.new import new
from ietf.utils import log
def linebreaks(value):
if value:
return django.utils.html.linebreaks(value)
else:
return value
def default(request):
"""Default page, with links to sub-pages"""
return render("ipr/disclosure.html", {}, context_instance=RequestContext(request))
def showlist(request):
"""Display a list of existing disclosures"""
return list_all(request, 'ipr/list.html')
def updatelist(request):
"""Display a list of existing disclosures, with links to update forms"""
return list_all(request, 'ipr/update_list.html')
def list_all(request, template):
"""Display a list of existing disclosures, using the provided template"""
disclosures = IprDetail.objects.all()
generic_disclosures = disclosures.filter(status__in=[1,3], generic=1)
specific_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=0)
thirdpty_disclosures = disclosures.filter(status__in=[1,3], generic=0, third_party=1)
return render(template,
{
'generic_disclosures' : generic_disclosures.order_by(* ['-submitted_date', ] ),
'specific_disclosures': specific_disclosures.order_by(* ['-submitted_date', ] ),
'thirdpty_disclosures': thirdpty_disclosures.order_by(* ['-submitted_date', ] ),
}, context_instance=RequestContext(request) )
# Details views
def show(request, ipr_id=None):
"""Show a specific IPR disclosure"""
assert ipr_id != None
ipr = IprDetail.objects.get(ipr_id=ipr_id)
section_list = get_section_list(ipr)
contacts = ipr.contact.all()
for contact in contacts:
if contact.contact_type == 1:
ipr.holder_contact = contact
elif contact.contact_type == 2:
ipr.ietf_contact = contact
elif contact.contact_type == 3:
ipr.submitter = contact
else:
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.notes = linebreaks(escape(ipr.notes))
ipr.document_sections = linebreaks(escape(ipr.document_sections))
ipr.comments = linebreaks(escape(ipr.comments))
ipr.other_notes = linebreaks(escape(ipr.other_notes))
if ipr.licensing_option:
text = dict(LICENSE_CHOICES)[ipr.licensing_option]
# Very hacky way to get rid of the last part of option 'd':
cut = text.find(" (")
if cut > 0:
text = text[cut:] + "."
# get rid of the "a) ", "b) ", etc.
ipr.licensing_option = text[3:]
if ipr.is_pending:
ipr.is_pending = dict(SELECT_CHOICES)[ipr.is_pending]
if ipr.applies_to_all:
ipr.applies_to_all = dict(SELECT_CHOICES)[ipr.applies_to_all]
return render("ipr/details.html", {"ipr": ipr, "section_list": section_list},
context_instance=RequestContext(request))
def update(request, ipr_id=None):
"""Update a specific IPR disclosure"""
ipr = IprDetail.objects.get(ipr_id=ipr_id)
type = "specific"
if ipr.generic:
type = "generic"
if ipr.third_party:
type = "third-party"
return new(request, type, ipr)
def form(request):
wgs = IETFWG.objects.filter(group_type__group_type_id=1).exclude(group_acronym__acronym='2000').select_related().order_by('acronym.acronym')
log("Search form")
return render("ipr/search.html", {"wgs": wgs}, context_instance=RequestContext(request))
# ---- Helper functions ------------------------------------------------------
def get_section_list(ipr):
if ipr.legacy_url_0:
return section_table["legacy"]
elif ipr.generic:
#assert not ipr.third_party
return section_table["generic"]
elif ipr.third_party:
return section_table["third-party"]
else:
return section_table["specific"]