Skip to content

Commit 26a9783

Browse files
committed
* More logic moved to ipr/views.py.
* Added InternationalPhoneNumberField to ipr/models.py Probably should be moved to a common model class file. - Legacy-Id: 106
1 parent e8980df commit 26a9783

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

ietf/ipr/models.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
import re
12
from django.db import models
3+
from django.template.defaultfilters import capfirst
4+
from django import oldforms
5+
from django import newforms as forms
26
from ietf.idtracker.views import InternetDraft
37
from ietf.idtracker.models import Rfc
48

9+
# ------------------------------------------------------------------------
10+
# New field classes
11+
12+
phone_re = re.compile(r'^\+?[0-9 ]*(\([0-9]+\))?[0-9 -]+$')
13+
class InternationalPhoneNumberField(models.PhoneNumberField):
14+
error_message = 'Phone numbers may have a leading "+", and otherwise only contain numbers [0-9], dash, space, and parentheses. '
15+
def validate(self, field_data, all_data):
16+
if not phone_re.search(field_data):
17+
raise ValidationError, self.error_message + ' "%s" is invalid.' % field_data
18+
19+
def clean(self, value):
20+
if value in EMPTY_VALUES:
21+
return u''
22+
self.validate(value, {})
23+
return smart_unicode(value)
24+
25+
def formfield(self, **kwargs):
26+
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name),
27+
'help_text': self.help_text,
28+
'error_message': self.error_message + "Enter a valid phone number."}
29+
defaults.update(kwargs)
30+
return forms.RegexField(phone_re, **defaults)
31+
32+
33+
# ------------------------------------------------------------------------
34+
# Models
35+
536
LICENSE_CHOICES = (
637
(1, 'No License Required for Implementers.'),
738
(2, 'Royalty-Free, Reasonable and Non-Discriminatory License to All Implementers.'),
@@ -126,8 +157,8 @@ class IprContact(models.Model):
126157
department = models.CharField(blank=True, maxlength=255)
127158
address1 = models.CharField(blank=True, maxlength=255)
128159
address2 = models.CharField(blank=True, maxlength=255)
129-
telephone = models.CharField(maxlength=25)
130-
fax = models.CharField(blank=True, maxlength=25)
160+
telephone = InternationalPhoneNumberField(maxlength=25)
161+
fax = InternationalPhoneNumberField(blank=True, maxlength=25)
131162
email = models.EmailField(maxlength=255)
132163
def __str__(self):
133164
return self.name

ietf/ipr/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ def show(request, ipr_id=None):
8383
ipr.discloser_identify = linebreaks(escape(ipr.discloser_identify))
8484
ipr.comments = linebreaks(escape(ipr.comments))
8585
ipr.other_notes = linebreaks(escape(ipr.other_notes))
86-
86+
opt = ipr.licensing_option
87+
ipr.licensing_option = dict(models.LICENSE_CHOICES)[ipr.licensing_option]
88+
ipr.selecttype = dict(models.SELECT_CHOICES)[ipr.selecttype]
89+
if ipr.selectowned:
90+
ipr.selectowned = dict(models.SELECT_CHOICES)[ipr.selectowned]
8791
return render("ipr/details.html", {"ipr": ipr, "section_list": section_list})
8892

8993
def update(request, ipr_id=None):

ietf/templates/ipr/details.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ <h4 class="ipr">The Patent Disclosure and Licensing Declaration Template for {{
253253
<td colspan="2"><i>
254254
B. Does this disclosure relate to an unpublished pending patent
255255
application?: </i>
256-
<b>{{ ipr.get_selecttype_display }}</b>
256+
<b>{{ ipr.selecttype }}</b>
257257
</tr>
258258
<tr>
259259
<td colspan="2"><i>
@@ -299,7 +299,7 @@ <h4 class="ipr">The Patent Disclosure and Licensing Declaration Template for {{
299299
</tr>
300300
<tr>
301301
<td> </td><td>
302-
<b>{{ ipr.get_licensing_option_display }}<br/>
302+
<b>{{ ipr.licensing_option }}<br/>
303303
{{ ipr.get_lic_opt_a_sub_display }}
304304
{{ ipr.get_lic_opt_b_sub_display }}
305305
{{ ipr.get_lic_opt_c_sub_display }}</b>

0 commit comments

Comments
 (0)