Changeset 5019
- Timestamp:
- 04/17/07 10:57:16 (2 years ago)
- Files:
-
- django/branches/boulder-oracle-sprint/AUTHORS (modified) (1 diff)
- django/branches/boulder-oracle-sprint/django/contrib/databrowse/datastructures.py (modified) (4 diffs)
- django/branches/boulder-oracle-sprint/django/contrib/localflavor/it/forms.py (modified) (3 diffs)
- django/branches/boulder-oracle-sprint/django/contrib/localflavor/it/util.py (copied) (copied from django/trunk/django/contrib/localflavor/it/util.py)
- django/branches/boulder-oracle-sprint/django/db/backends/postgresql/base.py (modified) (2 diffs)
- django/branches/boulder-oracle-sprint/django/db/backends/postgresql_psycopg2/base.py (modified) (2 diffs)
- django/branches/boulder-oracle-sprint/tests/regressiontests/fixtures_regress/models.py (modified) (1 diff)
- django/branches/boulder-oracle-sprint/tests/regressiontests/forms/localflavor.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/boulder-oracle-sprint/AUTHORS
r4990 r5019 175 175 Michael Radziej <mir@noris.de> 176 176 ramiro 177 Massimiliano Ravelli <massimiliano.ravelli@gmail.com> 177 178 Brian Ray <http://brianray.chipy.org/> 178 179 remco@diji.biz django/branches/boulder-oracle-sprint/django/contrib/databrowse/datastructures.py
r5014 r5019 4 4 """ 5 5 6 from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE7 6 from django.db import models 8 7 from django.utils import dateformat 9 8 from django.utils.text import capfirst 10 9 from django.utils.translation import get_date_formats 10 11 EMPTY_VALUE = '(None)' 11 12 12 13 class EasyModel(object): … … 133 134 so we can accomodate many-to-many fields. 134 135 """ 136 # This import is deliberately inside the function because it causes 137 # some settings to be imported, and we don't want to do that at the 138 # module level. 135 139 if self.field.rel: 136 140 if isinstance(self.field.rel, models.ManyToOneRel): … … 139 143 return list(getattr(self.instance.instance, self.field.name).all()) 140 144 elif self.field.choices: 141 objs = dict(self.field.choices).get(self.raw_value, EMPTY_ CHANGELIST_VALUE)145 objs = dict(self.field.choices).get(self.raw_value, EMPTY_VALUE) 142 146 elif isinstance(self.field, models.DateField) or isinstance(self.field, models.TimeField): 143 147 if self.raw_value: … … 150 154 objs = capfirst(dateformat.format(self.raw_value, date_format)) 151 155 else: 152 objs = EMPTY_ CHANGELIST_VALUE156 objs = EMPTY_VALUE 153 157 elif isinstance(self.field, models.BooleanField) or isinstance(self.field, models.NullBooleanField): 154 158 objs = {True: 'Yes', False: 'No', None: 'Unknown'}[self.raw_value] django/branches/boulder-oracle-sprint/django/contrib/localflavor/it/forms.py
r4935 r5019 6 6 from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 7 7 from django.utils.translation import gettext 8 from django.utils.encoding import smart_unicode 9 from django.contrib.localflavor.it.util import ssn_check_digit, vat_number_check_digit 8 10 import re 9 11 … … 12 14 super(ITZipCodeField, self).__init__(r'^\d{5}$', 13 15 max_length=None, min_length=None, 14 error_message=gettext(u'Enter a zip code in the format XXXXX.'),16 error_message=gettext(u'Enter a valid zip code.'), 15 17 *args, **kwargs) 16 18 … … 30 32 from it_province import PROVINCE_CHOICES # relative import 31 33 super(ITProvinceSelect, self).__init__(attrs, choices=PROVINCE_CHOICES) 34 35 class ITSocialSecurityNumberField(RegexField): 36 """ 37 A form field that validates Italian Social Security numbers (codice fiscale). 38 For reference see http://www.agenziaentrate.it/ and search for 39 'Informazioni sulla codificazione delle persone fisiche'. 40 """ 41 err_msg = gettext(u'Enter a valid Social Security number.') 42 def __init__(self, *args, **kwargs): 43 super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$', 44 max_length=None, min_length=None, error_message=self.err_msg, 45 *args, **kwargs) 46 47 def clean(self, value): 48 value = super(ITSocialSecurityNumberField, self).clean(value) 49 if value == u'': 50 return value 51 value = re.sub('\s', u'', value).upper() 52 try: 53 check_digit = ssn_check_digit(value) 54 except ValueError: 55 raise ValidationError(self.err_msg) 56 if not value[15] == check_digit: 57 raise ValidationError(self.err_msg) 58 return value 59 60 class ITVatNumberField(Field): 61 """ 62 A form field that validates Italian VAT numbers (partita IVA). 63 """ 64 def clean(self, value): 65 value = super(ITVatNumberField, self).clean(value) 66 if value == u'': 67 return value 68 err_msg = gettext(u'Enter a valid VAT number.') 69 try: 70 vat_number = int(value) 71 except ValueError: 72 raise ValidationError(err_msg) 73 vat_number = str(vat_number).zfill(11) 74 check_digit = vat_number_check_digit(vat_number[0:10]) 75 if not vat_number[10] == check_digit: 76 raise ValidationError(err_msg) 77 return smart_unicode(vat_number) django/branches/boulder-oracle-sprint/django/db/backends/postgresql/base.py
r4990 r5019 211 211 (style.SQL_KEYWORD('ALTER'), 212 212 style.SQL_KEYWORD('SEQUENCE'), 213 style.SQL_FIELD( '%s_%s_seq' % (table_name, column_name)),213 style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))), 214 214 style.SQL_KEYWORD('RESTART'), 215 215 style.SQL_KEYWORD('WITH'), … … 222 222 (style.SQL_KEYWORD('ALTER'), 223 223 style.SQL_KEYWORD('SEQUENCE'), 224 style.SQL_FIELD( '%s_id_seq' % table_name),224 style.SQL_FIELD(quote_name('%s_id_seq' % table_name)), 225 225 style.SQL_KEYWORD('RESTART'), 226 226 style.SQL_KEYWORD('WITH'), django/branches/boulder-oracle-sprint/django/db/backends/postgresql_psycopg2/base.py
r4990 r5019 168 168 (style.SQL_KEYWORD('ALTER'), 169 169 style.SQL_KEYWORD('SEQUENCE'), 170 style.SQL_FIELD( '%s_%s_seq' % (table_name, column_name)),170 style.SQL_FIELD(quote_name('%s_%s_seq' % (table_name, column_name))), 171 171 style.SQL_KEYWORD('RESTART'), 172 172 style.SQL_KEYWORD('WITH'), … … 179 179 (style.SQL_KEYWORD('ALTER'), 180 180 style.SQL_KEYWORD('SEQUENCE'), 181 style.SQL_FIELD( '%s_id_seq' % table_name),181 style.SQL_FIELD(quote_name('%s_id_seq' % table_name)), 182 182 style.SQL_KEYWORD('RESTART'), 183 183 style.SQL_KEYWORD('WITH'), django/branches/boulder-oracle-sprint/tests/regressiontests/fixtures_regress/models.py
r4990 r5019 7 7 def __str__(self): 8 8 return self.common_name 9 10 class Plant(models.Model): 11 name = models.CharField(maxlength=150) 12 13 class Meta: 14 # For testing when upper case letter in app name; regression for #4057 15 db_table = "Fixtures_regress_plant" 9 16 10 17 __test__ = {'API_TESTS':""" django/branches/boulder-oracle-sprint/tests/regressiontests/forms/localflavor.py
r5003 r5019 634 634 Traceback (most recent call last): 635 635 ... 636 ValidationError: [u'Enter a zip code in the format XXXXX.']636 ValidationError: [u'Enter a valid zip code.'] 637 637 638 638 # ITRegionSelect ############################################################# … … 642 642 >>> w.render('regions', 'PMN') 643 643 u'<select name="regions">\n<option value="ABR">Abruzzo</option>\n<option value="BAS">Basilicata</option>\n<option value="CAL">Calabria</option>\n<option value="CAM">Campania</option>\n<option value="EMR">Emilia-Romagna</option>\n<option value="FVG">Friuli-Venezia Giulia</option>\n<option value="LAZ">Lazio</option>\n<option value="LIG">Liguria</option>\n<option value="LOM">Lombardia</option>\n<option value="MAR">Marche</option>\n<option value="MOL">Molise</option>\n<option value="PMN" selected="selected">Piemonte</option>\n<option value="PUG">Puglia</option>\n<option value="SAR">Sardegna</option>\n<option value="SIC">Sicilia</option>\n<option value="TOS">Toscana</option>\n<option value="TAA">Trentino-Alto Adige</option>\n<option value="UMB">Umbria</option>\n<option value="VAO">Valle d\u2019Aosta</option>\n<option value="VEN">Veneto</option>\n</select>' 644 645 # ITSocialSecurityNumberField ################################################# 646 647 >>> from django.contrib.localflavor.it.forms import ITSocialSecurityNumberField 648 >>> f = ITSocialSecurityNumberField() 649 >>> f.clean('LVSGDU99T71H501L') 650 u'LVSGDU99T71H501L' 651 >>> f.clean('LBRRME11A01L736W') 652 u'LBRRME11A01L736W' 653 >>> f.clean('lbrrme11a01l736w') 654 u'LBRRME11A01L736W' 655 >>> f.clean('LBR RME 11A01 L736W') 656 u'LBRRME11A01L736W' 657 >>> f.clean('LBRRME11A01L736A') 658 Traceback (most recent call last): 659 ... 660 ValidationError: [u'Enter a valid Social Security number.'] 661 >>> f.clean('%BRRME11A01L736W') 662 Traceback (most recent call last): 663 ... 664 ValidationError: [u'Enter a valid Social Security number.'] 665 666 # ITVatNumberField ########################################################### 667 668 >>> from django.contrib.localflavor.it.forms import ITVatNumberField 669 >>> f = ITVatNumberField() 670 >>> f.clean('07973780013') 671 u'07973780013' 672 >>> f.clean('7973780013') 673 u'07973780013' 674 >>> f.clean(7973780013) 675 u'07973780013' 676 >>> f.clean('07973780014') 677 Traceback (most recent call last): 678 ... 679 ValidationError: [u'Enter a valid VAT number.'] 680 >>> f.clean('A7973780013') 681 Traceback (most recent call last): 682 ... 683 ValidationError: [u'Enter a valid VAT number.'] 644 684 645 685 # FIZipCodeField #############################################################
