11import models
22from django .shortcuts import render_to_response as render
33import django .newforms as forms
4+ from django .utils .html import escape , linebreaks
45import ietf .utils
56import syslog
67
@@ -30,31 +31,60 @@ def list(request, template):
3031 'thirdpty_disclosures' : thirdpty_disclosures .order_by (* ['-submitted_date' , ] ),
3132 } )
3233
34+ # Details views
35+
36+ section_table = {
37+ "index" : { "index" : True },
38+ "specific" : { "index" : False , "title" : True ,
39+ "legacy_intro" : False , "new_intro" : True , "form_intro" : False ,
40+ "holder" : True , "holder_contact" : True , "ietf_contact" : True ,
41+ "ietf_doc" : True , "patent_info" : True , "licensing" : True ,
42+ "submitter" : True , "notes" : True , "form_submit" : False ,
43+ },
44+ "generic" : { "index" : False , "title" : True ,
45+ "legacy_intro" : False , "new_intro" : True , "form_intro" : False ,
46+ "holder" : True , "holder_contact" : True , "ietf_contact" : False ,
47+ "ietf_doc" : False , "patent_info" : True , "licensing" : True ,
48+ "submitter" : True , "notes" : True , "form_submit" : False ,
49+ },
50+ "third_party" : {"index" : False , "title" : True ,
51+ "legacy_intro" : False , "new_intro" : True , "form_intro" : False ,
52+ "holder" : True , "holder_contact" : False , "ietf_contact" : True ,
53+ "ietf_doc" : True , "patent_info" : True , "licensing" : False ,
54+ "submitter" : False , "notes" : False , "form_submit" : False ,
55+ },
56+ "legacy" : { "index" : False , "title" : True ,
57+ "legacy_intro" : True , "new_intro" : False , "form_intro" : False ,
58+ "holder" : True , "holder_contact" : True , "ietf_contact" : False ,
59+ "ietf_doc" : True , "patent_info" : False , "licensing" : False ,
60+ "submitter" : False , "notes" : False , "form_submit" : False ,
61+ },
62+ }
63+
3364def show (request , ipr_id = None ):
3465 """Show a specific IPR disclosure"""
3566 assert ipr_id != None
3667 ipr = models .IprDetail .objects .filter (ipr_id = ipr_id )[0 ]
3768 ipr .disclosure_type = get_disclosure_type (ipr )
38- try :
39- ipr .holder_contact = ipr .contact .filter (contact_type = 1 )[0 ]
40- except IndexError :
41- ipr .holder_contact = ""
42- try :
43- ipr .ietf_contact = ipr .contact .filter (contact_type = 2 )[0 ]
44- except IndexError :
45- ipr .ietf_contact = ""
46- try :
47- ipr .submitter = ipr .contact .filter (contact_type = 3 )[0 ]
48- except IndexError :
49- ipr .submitter = ""
50-
51- if ipr .generic :
52- return render ("ipr/details_generic.html" , {"ipr" : ipr })
53- if ipr .third_party :
54- return render ("ipr/details_thirdpty.html" , {"ipr" : ipr })
55- else :
56- return render ("ipr/details_specific.html" , {"ipr" : ipr })
57-
69+ section_list = get_section_list (ipr )
70+ contacts = ipr .contact .all ()
71+ for contact in contacts :
72+ if contact .contact_type == 1 :
73+ ipr .holder_contact = contact
74+ elif contact .contact_type == 2 :
75+ ipr .ietf_contact = contact
76+ elif contact .contact_type == 3 :
77+ ipr .submitter = contact
78+ else :
79+ raise KeyError ("Unexpected contact_type in ipr_contacts: ipr_id=%s" % ipr .ipr_id )
80+ # do escaping and line-breaking here instead of in the template,
81+ # so that we can use the template for the form display, too.
82+ ipr .p_notes = linebreaks (escape (ipr .p_notes ))
83+ ipr .discloser_identify = linebreaks (escape (ipr .discloser_identify ))
84+ ipr .comments = linebreaks (escape (ipr .comments ))
85+ ipr .other_notes = linebreaks (escape (ipr .other_notes ))
86+
87+ return render ("ipr/details.html" , {"ipr" : ipr , "section_list" : section_list })
5888
5989def update (request , ipr_id = None ):
6090 """Update a specific IPR disclosure"""
@@ -65,34 +95,55 @@ def new(request, type):
6595 """Make a new IPR disclosure"""
6696 debug = ""
6797
68- # CustomForm = mk_formatting_form(format="%(errors)s%(field)s%(help_text)s")
6998 CustomForm = ietf .utils .makeFormattingForm (template = "ipr/formfield.html" )
7099 BaseIprForm = forms .form_for_model (models .IprDetail , form = CustomForm , formfield_callback = detail_field_fixup )
71- ContactForm = forms .form_for_model (models .IprContact , form = CustomForm )
100+ BaseContactForm = forms .form_for_model (models .IprContact , form = CustomForm )
101+
102+ section_list = section_table [type ]
103+ section_list .update ({"title" :False , "new_intro" :False , "form_intro" :True , "form_submit" :True , })
72104
73105 # Some subclassing:
106+ class MultiformWidget (forms .Widget ):
107+ def value_from_datadict (self , data , name ):
108+ return data
109+
110+ class ContactForm (BaseContactForm ):
111+ widget = MultiformWidget ()
112+
113+ def add_prefix (self , field_name ):
114+ return self .prefix and ('%s_%s' % (self .prefix , field_name )) or field_name
115+ def clean (self , * value ):
116+ if value :
117+ return self .full_clean ()
118+ else :
119+ return self .clean_data
120+
74121 class IprForm (BaseIprForm ):
75122 holder_contact = None
76123 rfclist = forms .CharField (required = False )
77124 draftlist = forms .CharField (required = False )
78125 stdonly_license = forms .BooleanField (required = False )
79126 def __init__ (self , * args , ** kw ):
80- self .base_fields ["holder_contact" ] = ContactForm (prefix = "ph" , * args , ** kw )
81- # syslog.syslog("IprForm.__init__: holder_contact: %s" % repr(self.base_fields["holder_contact"]))
82-
83- self .base_fields ["ietf_contact" ] = ContactForm (prefix = "ietf" , * args , ** kw )
84- self .base_fields ["submitter" ] = ContactForm (prefix = "sub" , * args , ** kw )
127+ for contact in ["holder_contact" , "ietf_contact" , "submitter" ]:
128+ if contact in section_list :
129+ self .base_fields [contact ] = ContactForm (prefix = contact [:4 ], * args , ** kw )
85130 BaseIprForm .__init__ (self , * args , ** kw )
86131
87132 if request .method == 'POST' :
88133 form = IprForm (request .POST )
89134 if form .is_valid ():
90- form .save ()
135+ #instance = form.save()
136+ #return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id)
91137 return HttpResponseRedirect ("/ipr/" )
138+ else :
139+ # Fall through, and let the partially bound form, with error
140+ # indications, be rendered again.
141+ pass
92142 else :
93143 form = IprForm ()
144+ form .unbound_form = True
94145
95- return render ("ipr/new_%s .html" % type , {"ipr" : form , "debug" : "" })
146+ return render ("ipr/details .html" , {"ipr" : form , "section_list" : section_list , "debug" : "" })
96147
97148def detail_field_fixup (field ):
98149 if field .name == "licensing_option" :
@@ -108,7 +159,18 @@ def get_disclosure_type(ipr):
108159 if ipr .generic :
109160 assert not ipr .third_party
110161 return "Generic"
111- if ipr .third_party :
162+ elif ipr .third_party :
112163 return "Third Party"
113164 else :
114165 return "Specific"
166+
167+ def get_section_list (ipr ):
168+ if ipr .old_ipr_url :
169+ return section_table ["legacy" ]
170+ elif ipr .generic :
171+ assert not ipr .third_party
172+ return section_table ["generic" ]
173+ elif ipr .third_party :
174+ return section_table ["third_party" ]
175+ else :
176+ return section_table ["specific" ]
0 commit comments