|
1 | 1 | import re |
2 | 2 | import models |
3 | | -import ietf.utils |
4 | 3 | import django.utils.html |
5 | | -import django.newforms as forms |
6 | 4 | from django.shortcuts import render_to_response as render |
7 | 5 | from django.utils.html import escape |
8 | | -from ietf.contrib.form_decorator import form_decorator |
9 | | -from ietf.utils import log as log |
| 6 | +from ietf.ipr.view_new import new |
| 7 | +from ietf.ipr.view_sections import section_table |
10 | 8 |
|
11 | 9 | def linebreaks(value): |
12 | 10 | if value: |
@@ -42,39 +40,10 @@ def list(request, template): |
42 | 40 |
|
43 | 41 | # Details views |
44 | 42 |
|
45 | | -section_table = { |
46 | | - "index": { "index": True }, |
47 | | - "specific": { "index": False, "title": True, "specific": True, |
48 | | - "legacy_intro": False, "new_intro": True, "form_intro": False, |
49 | | - "holder": True, "holder_contact": True, "ietf_contact": True, |
50 | | - "ietf_doc": True, "patent_info": True, "licensing": True, |
51 | | - "submitter": True, "notes": True, "form_submit": False, |
52 | | - }, |
53 | | - "generic": { "index": False, "title": True, "generic": True, |
54 | | - "legacy_intro": False, "new_intro": True, "form_intro": False, |
55 | | - "holder": True, "holder_contact": True, "ietf_contact": False, |
56 | | - "ietf_doc": False, "patent_info": True, "licensing": True, |
57 | | - "submitter": True, "notes": True, "form_submit": False, |
58 | | - }, |
59 | | - "third_party": {"index": False, "title": True, "third_party": True, |
60 | | - "legacy_intro": False, "new_intro": True, "form_intro": False, |
61 | | - "holder": True, "holder_contact": False, "ietf_contact": True, |
62 | | - "ietf_doc": True, "patent_info": True, "licensing": False, |
63 | | - "submitter": False, "notes": False, "form_submit": False, |
64 | | - }, |
65 | | - "legacy": { "index": False, "title": True, "legacy": True, |
66 | | - "legacy_intro": True, "new_intro": False, "form_intro": False, |
67 | | - "holder": True, "holder_contact": True, "ietf_contact": False, |
68 | | - "ietf_doc": True, "patent_info": False, "licensing": False, |
69 | | - "submitter": False, "notes": False, "form_submit": False, |
70 | | - }, |
71 | | - } |
72 | | - |
73 | 43 | def show(request, ipr_id=None): |
74 | 44 | """Show a specific IPR disclosure""" |
75 | 45 | assert ipr_id != None |
76 | 46 | ipr = models.IprDetail.objects.filter(ipr_id=ipr_id)[0] |
77 | | - ipr.disclosure_type = get_disclosure_type(ipr) |
78 | 47 | section_list = get_section_list(ipr) |
79 | 48 | contacts = ipr.contact.all() |
80 | 49 | for contact in contacts: |
@@ -105,130 +74,10 @@ def update(request, ipr_id=None): |
105 | 74 | # TODO: replace the placeholder code with the appropriate update code |
106 | 75 | return show(request, ipr_id) |
107 | 76 |
|
108 | | -def new(request, type): |
109 | | - """Make a new IPR disclosure""" |
110 | | - debug = "" |
111 | | - |
112 | | - # define callback methods for special field cases. |
113 | | - def ipr_detail_form_callback(field, **kwargs): |
114 | | - if field.name == "licensing_option": |
115 | | - return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False) |
116 | | - if field.name in ["selecttype", "selectowned"]: |
117 | | - return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False) |
118 | | - return field.formfield(**kwargs) |
119 | | - |
120 | | - def ipr_contact_form_callback(field, **kwargs): |
121 | | - phone_re = re.compile(r'^\+?[0-9 ]*(\([0-9]+\))?[0-9 -]+$') |
122 | | - error_message = """Phone numbers may have a leading "+", and otherwise only contain |
123 | | - numbers [0-9]; dash, period or space; parentheses, and an optional |
124 | | - extension number indicated by 'x'. """ |
125 | | - |
126 | | - if field.name == "telephone": |
127 | | - return forms.RegexField(phone_re, error_message=error_message, **kwargs) |
128 | | - if field.name == "fax": |
129 | | - return forms.RegexField(phone_re, error_message=error_message, required=False, **kwargs) |
130 | | - return field.formfield(**kwargs) |
131 | | - |
132 | | - # Get a form class which renders fields using a given template |
133 | | - CustomForm = ietf.utils.makeFormattingForm(template="ipr/formfield.html") |
134 | | - |
135 | | - # Get base form classes for our models |
136 | | - BaseIprForm = forms.form_for_model(models.IprDetail, form=CustomForm, formfield_callback=ipr_detail_form_callback) |
137 | | - BaseContactForm = forms.form_for_model(models.IprContact, form=CustomForm, formfield_callback=ipr_contact_form_callback) |
138 | | - |
139 | | - section_list = section_table[type] |
140 | | - section_list.update({"title":False, "new_intro":False, "form_intro":True, "form_submit":True, }) |
141 | | - |
142 | | - # Some subclassing: |
143 | | - |
144 | | - # The contact form will be part of the IprForm, so it needs a widget. |
145 | | - # Define one. |
146 | | - class MultiformWidget(forms.Widget): |
147 | | - def value_from_datadict(self, data, name): |
148 | | - return data |
149 | | - |
150 | | - class ContactForm(BaseContactForm): |
151 | | - widget = MultiformWidget() |
152 | | - |
153 | | - def add_prefix(self, field_name): |
154 | | - return self.prefix and ('%s_%s' % (self.prefix, field_name)) or field_name |
155 | | - def clean(self, *value): |
156 | | - if value: |
157 | | - return self.full_clean() |
158 | | - else: |
159 | | - return self.clean_data |
160 | | - |
161 | | - class IprForm(BaseIprForm): |
162 | | - holder_contact = None |
163 | | - rfclist = forms.CharField(required=False) |
164 | | - draftlist = forms.CharField(required=False) |
165 | | - stdonly_license = forms.BooleanField(required=False) |
166 | | - ietf_contact_is_submitter = forms.BooleanField(required=False) |
167 | | - if "holder_contact" in section_list: |
168 | | - holder_contact = ContactForm(prefix="hold") |
169 | | - if "ietf_contact" in section_list: |
170 | | - ietf_contact = ContactForm(prefix="ietf") |
171 | | - if "submitter" in section_list: |
172 | | - submitter = ContactForm(prefix="subm") |
173 | | - def __init__(self, *args, **kw): |
174 | | - for contact in ["holder_contact", "ietf_contact", "submitter"]: |
175 | | - if contact in section_list: |
176 | | - self.base_fields[contact] = ContactForm(prefix=contact[:4], *args, **kw) |
177 | | - self.base_fields["ietf_contact_is_submitter"] = forms.BooleanField(required=False) |
178 | | - BaseIprForm.__init__(self, *args, **kw) |
179 | | - # Special validation code |
180 | | - def clean(self): |
181 | | - # Required: |
182 | | - # Submitter form filled in or 'same-as-ietf-contact' marked |
183 | | - # Only one of rfc, draft, and other info fields filled in |
184 | | - # RFC exists or draft exists and has right rev. or ... |
185 | | - if self.ietf_contact_is_submitter: |
186 | | - self.submitter = self.ietf_contact |
187 | | - pass |
188 | | - |
189 | | - if request.method == 'POST': |
190 | | - data = request.POST.copy() |
191 | | - if "ietf_contact_is_submitter" in data: |
192 | | - for subfield in ["name", "title", "department", "address1", "address2", "telephone", "fax", "email"]: |
193 | | - try: |
194 | | - data["subm_%s"%subfield] = data["ietf_%s"%subfield] |
195 | | - except Exception, e: |
196 | | - #log("Caught exception: %s"%e) |
197 | | - pass |
198 | | - form = IprForm(data) |
199 | | - if form.ietf_contact_is_submitter: |
200 | | - form.ietf_contact_is_submitter_checked = "checked" |
201 | | - if form.is_valid(): |
202 | | - #instance = form.save() |
203 | | - #return HttpResponseRedirect("/ipr/ipr-%s" % instance.ipr_id) |
204 | | - #return HttpResponseRedirect("/ipr/") |
205 | | - pass |
206 | | - else: |
207 | | - for error in form.errors: |
208 | | - log("Form error: %s"%error) |
209 | | - # Fall through, and let the partially bound form, with error |
210 | | - # indications, be rendered again. |
211 | | - pass |
212 | | - else: |
213 | | - form = IprForm() |
214 | | - form.unbound_form = True |
215 | | - |
216 | | - # ietf.utils.log(dir(form.ietf_contact_is_submitter)) |
217 | | - return render("ipr/details.html", {"ipr": form, "section_list":section_list, "debug": debug}) |
218 | | - |
219 | 77 |
|
220 | 78 |
|
221 | 79 | # ---- Helper functions ------------------------------------------------------ |
222 | 80 |
|
223 | | -def get_disclosure_type(ipr): |
224 | | - if ipr.generic: |
225 | | - assert not ipr.third_party |
226 | | - return "Generic" |
227 | | - elif ipr.third_party: |
228 | | - return "Third Party" |
229 | | - else: |
230 | | - return "Specific" |
231 | | - |
232 | 81 | def get_section_list(ipr): |
233 | 82 | if ipr.old_ipr_url: |
234 | 83 | return section_table["legacy"] |
|
0 commit comments