Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaned up some small code issues

  • Loading branch information...
commit 7aa7e81756ee4a91e4c39ba1cc3549f6676d0772 1 parent f85fca9
Daniel Ursache Dogariu danniel authored
12 django/contrib/localflavor/ro/forms.py
View
@@ -3,6 +3,7 @@
Romanian specific form helpers.
"""
from __future__ import absolute_import, unicode_literals
+import re
from django.contrib.localflavor.ro.ro_counties import COUNTIES_CHOICES
from django.core.validators import EMPTY_VALUES
@@ -10,6 +11,9 @@
from django.utils.translation import ugettext_lazy as _
+phone_digits_re = re.compile(r'^[0-9\-\.\(\)\s]{3,20}$')
+
+
class ROCIFField(RegexField):
"""
A Romanian fiscal identity code (CIF) field
@@ -183,13 +187,13 @@ class ROPhoneNumberField(RegexField):
_('Phone numbers may only have 7 or 10 digits, except the ' +
'national short numbers which have 3 or 6 digits'),
'invalid_long_format':
- _('Normal phone numbers (7 or 10 digits) must begin with \"0\"'),
+ _('Normal phone numbers (7 or 10 digits) must begin with "0"'),
'invalid_short_format':
- _('National short numbers (3 or 6 digits) must begin with \"1\"'),
+ _('National short numbers (3 or 6 digits) must begin with "1"'),
}
def __init__(self, max_length=20, min_length=3, *args, **kwargs):
- super(ROPhoneNumberField, self).__init__(r'^[0-9\-\.\(\)\s]{3,20}$',
+ super(ROPhoneNumberField, self).__init__(phone_digits_re,
max_length, min_length, *args, **kwargs)
def clean(self, value):
@@ -205,7 +209,7 @@ def clean(self, value):
value = value.replace('.','')
value = value.replace(' ','')
length = len(value)
- if length in [3, 6, 7, 10]:
+ if length in (3, 6, 7, 10):
if (length == 7 or length == 10) and value[0] != '0':
raise ValidationError(
self.error_messages['invalid_long_format'])
4 tests/regressiontests/localflavor/ro/tests.py
View
@@ -119,9 +119,9 @@ def test_ROPhoneNumberField(self):
error_invalid_length = ['Phone numbers may only have 7 or 10 digits,' +
' except the national short numbers which have 3 or 6 digits']
error_invalid_long_format = ['Normal phone numbers (7 or 10 digits)' +
- ' must begin with \"0\"']
+ ' must begin with "0"']
error_invalid_short_format = ['National short numbers (3 or 6 digits)' +
- ' must begin with \"1\"']
+ ' must begin with "1"']
valid = {
'112': '112',
'123.456': '123456',
Please sign in to comment.
Something went wrong with that request. Please try again.