Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3813 -- Added French package to django.contrib.localflavor. Th…

…anks, Fabrice Aneche

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4820 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 955f4db6f4e2047ef610230d22799171c335f1c0 1 parent 5d079ee
Adrian Holovaty authored March 25, 2007
1  AUTHORS
@@ -44,6 +44,7 @@ answer newbie questions, and generally made Django that much better:
44 44
     adurdin@gmail.com
45 45
     Andreas
46 46
     andy@jadedplanet.net
  47
+    Fabrice Aneche <akh@nobugware.com>
47 48
     ant9000@netwise.it
48 49
     David Ascher <http://ascher.ca/>
49 50
     Arthur <avandorp@gmail.com>
44  django/contrib/localflavor/fr/forms.py
... ...
@@ -0,0 +1,44 @@
  1
+"""
  2
+FR-specific Form helpers
  3
+"""
  4
+
  5
+from django.newforms import ValidationError
  6
+from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES
  7
+from django.newforms.util import smart_unicode
  8
+from django.utils.translation import gettext
  9
+import re
  10
+
  11
+phone_digits_re = re.compile(r'^0\d(\s|\.)?(\d{2}(\s|\.)?){3}\d{2}$')
  12
+
  13
+class FRZipCodeField(RegexField):
  14
+    def __init__(self, *args, **kwargs):
  15
+        super(FRZipCodeField, self).__init__(r'^\d{5}$',
  16
+            max_length=None, min_length=None,
  17
+            error_message=gettext(u'Enter a zip code in the format XXXXX.'),
  18
+            *args, **kwargs)
  19
+
  20
+class FRPhoneNumberField(Field):
  21
+    """
  22
+    Validate local French phone number (not international ones)
  23
+    The correct format is '0X XX XX XX XX'.
  24
+    '0X.XX.XX.XX.XX' and '0XXXXXXXXX' validate but are corrected to
  25
+    '0X XX XX XX XX'.
  26
+    """
  27
+    def clean(self, value):
  28
+        super(FRPhoneNumberField, self).clean(value)
  29
+        if value in EMPTY_VALUES:
  30
+            return u''
  31
+        value = re.sub('(\.|\s)', '', smart_unicode(value))
  32
+        m = phone_digits_re.search(value)
  33
+        if m:
  34
+            return u'%s %s %s %s %s' % (value[0:2], value[2:4], value[4:6], value[6:8], value[8:10])
  35
+        raise ValidationError(u'Phone numbers must be in 0X XX XX XX XX format.')
  36
+
  37
+class FRDepartmentSelect(Select):
  38
+    """
  39
+    A Select widget that uses a list of FR departments as its choices.
  40
+    """
  41
+    def __init__(self, attrs=None):
  42
+        from fr_department import DEPARTMENT_ASCII_CHOICES # relative import
  43
+        super(FRDepartmentSelect, self).__init__(attrs, choices=DEPARTMENT_ASCII_CHOICES)
  44
+
113  django/contrib/localflavor/fr/fr_department.py
... ...
@@ -0,0 +1,113 @@
  1
+# -*- coding: utf-8 -*-
  2
+
  3
+DEPARTMENT_ASCII_CHOICES = (
  4
+('01', '01 - Ain'),
  5
+('02', '02 - Aisne'),
  6
+('03', '03 - Allier'),
  7
+('04', '04 - Alpes-de-Haute-Provence'),
  8
+('05', '05 - Hautes-Alpes'),
  9
+('06', '06 - Alpes-Maritimes'),
  10
+('07', '07 - Ardeche'),
  11
+('08', '08 - Ardennes'),
  12
+('09', '09 - Ariege'),
  13
+('10', '10 - Aube'),
  14
+('11', '11 - Aude'),
  15
+('12', '12 - Aveyron'),
  16
+('13', '13 - Bouches-du-Rhone'),
  17
+('14', '14 - Calvados'),
  18
+('15', '15 - Cantal'),
  19
+('16', '16 - Charente'),
  20
+('17', '17 - Charente-Maritime'),
  21
+('18', '18 - Cher'),
  22
+('19', '19 - Correze'),
  23
+('21', '21 - Cote-d\'Or'),
  24
+('22', '22 - Cotes-d\'Armor'),
  25
+('23', '23 - Creuse'),
  26
+('24', '24 - Dordogne'),
  27
+('25', '25 - Doubs'),
  28
+('26', '26 - Drome'),
  29
+('27', '27 - Eure'),
  30
+('28', '28 - Eure-et-Loire'),
  31
+('29', '29 - Finistere'),
  32
+('2A', '2A - Corse-du-Sud'),
  33
+('2B', '2B - Haute-Corse'),
  34
+('30', '30 - Gard'),
  35
+('31', '31 - Haute-Garonne'),
  36
+('32', '32 - Gers'),
  37
+('33', '33 - Gironde'),
  38
+('34', '34 - Herault'),
  39
+('35', '35 - Ille-et-Vilaine'),
  40
+('36', '36 - Indre'),
  41
+('37', '37 - Indre-et-Loire'),
  42
+('38', '38 - Isere'),
  43
+('39', '39 - Jura'),
  44
+('40', '40 - Landes'),
  45
+('41', '41 - Loir-et-Cher'),
  46
+('42', '42 - Loire'),
  47
+('43', '43 - Haute-Loire'),
  48
+('44', '44 - Loire-Atlantique'),
  49
+('45', '45 - Loiret'),
  50
+('46', '46 - Lot'),
  51
+('47', '47 - Lot-et-Garonne'),
  52
+('48', '48 - Lozere'),
  53
+('49', '49 - Maine-et-Loire'),
  54
+('50', '50 - Manche'),
  55
+('51', '51 - Marne'),
  56
+('52', '52 - Haute-Marne'),
  57
+('53', '53 - Mayenne'),
  58
+('54', '54 - Meurthe-et-Moselle'),
  59
+('55', '55 - Meuse'),
  60
+('56', '56 - Morbihan'),
  61
+('57', '57 - Moselle'),
  62
+('58', '58 - Nievre'),
  63
+('59', '59 - Nord'),
  64
+('60', '60 - Oise'),
  65
+('61', '61 - Orne'),
  66
+('62', '62 - Pas-de-Calais'),
  67
+('63', '63 - Puy-de-Dome'),
  68
+('64', '64 - Pyrenees-Atlantiques'),
  69
+('65', '65 - Hautes-Pyrenees'),
  70
+('66', '66 - Pyrenees-Orientales'),
  71
+('67', '67 - Bas-Rhin'),
  72
+('68', '68 - Haut-Rhin'),
  73
+('69', '69 - Rhone'),
  74
+('70', '70 - Haute-Saone'),
  75
+('71', '71 - Saone-et-Loire'),
  76
+('72', '72 - Sarthe'),
  77
+('73', '73 - Savoie'),
  78
+('74', '74 - Haute-Savoie'),
  79
+('75', '75 - Paris'),
  80
+('76', '76 - Seine-Maritime'),
  81
+('77', '77 - Seine-et-Marne'),
  82
+('78', '78 - Yvelines'),
  83
+('79', '79 - Deux-Sevres'),
  84
+('80', '80 - Somme'),
  85
+('81', '81 - Tarn'),
  86
+('82', '82 - Tarn-et-Garonne'),
  87
+('83', '83 - Var'),
  88
+('84', '84 - Vaucluse'),
  89
+('85', '85 - Vendee'),
  90
+('86', '86 - Vienne'),
  91
+('87', '87 - Haute-Vienne'),
  92
+('88', '88 - Vosges'),
  93
+('89', '89 - Yonne'),
  94
+('90', '90 - Territoire de Belfort'),
  95
+('91', '91 - Essonne'),
  96
+('92', '92 - Hauts-de-Seine'),
  97
+('93', '93 - Seine-Saint-Denis'),
  98
+('94', '94 - Val-de-Marne'),
  99
+('95', '95 - Val-d\'Oise'),
  100
+('2A', '2A - Corse du sud'),
  101
+('2B', '2B - Haute Corse'),
  102
+('971', '971 - Guadeloupe'),
  103
+('972', '972 - Martinique'),
  104
+('973', '973 - Guyane'),
  105
+('974', '974 - La Reunion'),
  106
+('975', '975 - Saint-Pierre-et-Miquelon'),
  107
+('976', '976 - Mayotte'),
  108
+('984', '984 - Terres Australes et Antarctiques'),
  109
+('986', '986 - Wallis et Futuna'),
  110
+('987', '987 - Polynesie Francaise'),
  111
+('988', '988 - Nouvelle-Caledonie'),
  112
+)
  113
+
0  localflavor/fr/__init__.py b/django/contrib/localflavor/fr/__init__.py
No changes.
220  tests/regressiontests/forms/tests.py
@@ -3556,6 +3556,226 @@
3556 3556
 >>> f.clean('')
3557 3557
 u''
3558 3558
 
  3559
+# FRZipCodeField #############################################################
  3560
+
  3561
+FRZipCodeField validates that the data is a valid FR zipcode.
  3562
+>>> from django.contrib.localflavor.fr.forms import FRZipCodeField
  3563
+>>> f = FRZipCodeField()
  3564
+>>> f.clean('75001')
  3565
+u'75001'
  3566
+>>> f.clean('93200')
  3567
+u'93200'
  3568
+>>> f.clean('2A200')
  3569
+Traceback (most recent call last):
  3570
+...
  3571
+ValidationError: [u'Enter a zip code in the format XXXXX.']
  3572
+>>> f.clean('980001')
  3573
+Traceback (most recent call last):
  3574
+...
  3575
+ValidationError: [u'Enter a zip code in the format XXXXX.']
  3576
+>>> f.clean(None)
  3577
+Traceback (most recent call last):
  3578
+...
  3579
+ValidationError: [u'This field is required.']
  3580
+>>> f.clean('')
  3581
+Traceback (most recent call last):
  3582
+...
  3583
+ValidationError: [u'This field is required.']
  3584
+
  3585
+>>> f = FRZipCodeField(required=False)
  3586
+>>> f.clean('75001')
  3587
+u'75001'
  3588
+>>> f.clean('93200')
  3589
+u'93200'
  3590
+>>> f.clean('2A200')
  3591
+Traceback (most recent call last):
  3592
+...
  3593
+ValidationError: [u'Enter a zip code in the format XXXXX.']
  3594
+>>> f.clean('980001')
  3595
+Traceback (most recent call last):
  3596
+...
  3597
+ValidationError: [u'Enter a zip code in the format XXXXX.']
  3598
+>>> f.clean(None)
  3599
+u''
  3600
+>>> f.clean('')
  3601
+u''
  3602
+
  3603
+
  3604
+# FRPhoneNumberField ##########################################################
  3605
+
  3606
+FRPhoneNumberField validates that the data is a valid french phone number.
  3607
+It's normalized to 0X XX XX XX XX format. Dots are valid too.
  3608
+>>> from django.contrib.localflavor.fr.forms import FRPhoneNumberField
  3609
+>>> f = FRPhoneNumberField()
  3610
+>>> f.clean('01 55 44 58 64')
  3611
+u'01 55 44 58 64'
  3612
+>>> f.clean('0155445864')
  3613
+u'01 55 44 58 64'
  3614
+>>> f.clean('01 5544 5864')
  3615
+u'01 55 44 58 64'
  3616
+>>> f.clean('01 55.44.58.64')
  3617
+u'01 55 44 58 64'
  3618
+>>> f.clean('01.55.44.58.64')
  3619
+u'01 55 44 58 64'
  3620
+>>> f.clean('01,55,44,58,64')
  3621
+Traceback (most recent call last):
  3622
+...
  3623
+ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
  3624
+>>> f.clean('555 015 544')
  3625
+Traceback (most recent call last):
  3626
+...
  3627
+ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
  3628
+>>> f.clean(None)
  3629
+Traceback (most recent call last):
  3630
+...
  3631
+ValidationError: [u'This field is required.']
  3632
+>>> f.clean('')
  3633
+Traceback (most recent call last):
  3634
+...
  3635
+ValidationError: [u'This field is required.']
  3636
+
  3637
+>>> f = FRPhoneNumberField(required=False)
  3638
+>>> f.clean('01 55 44 58 64')
  3639
+u'01 55 44 58 64'
  3640
+>>> f.clean('0155445864')
  3641
+u'01 55 44 58 64'
  3642
+>>> f.clean('01 5544 5864')
  3643
+u'01 55 44 58 64'
  3644
+>>> f.clean('01 55.44.58.64')
  3645
+u'01 55 44 58 64'
  3646
+>>> f.clean('01.55.44.58.64')
  3647
+u'01 55 44 58 64'
  3648
+>>> f.clean('01,55,44,58,64')
  3649
+Traceback (most recent call last):
  3650
+...
  3651
+ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
  3652
+>>> f.clean('555 015 544')
  3653
+Traceback (most recent call last):
  3654
+...
  3655
+ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.']
  3656
+>>> f.clean(None)
  3657
+u''
  3658
+>>> f.clean('')
  3659
+u''
  3660
+
  3661
+# FRDepartmentSelect ###############################################################
  3662
+
  3663
+FRDepartmentSelect is a Select widget that uses a list of french departments 
  3664
+including DOM TOM
  3665
+>>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect
  3666
+>>> w = FRDepartmentSelect()
  3667
+>>> print w.render('dep', 'Paris')
  3668
+<select name="dep">
  3669
+<option value="01">01 - Ain</option>
  3670
+<option value="02">02 - Aisne</option>
  3671
+<option value="03">03 - Allier</option>
  3672
+<option value="04">04 - Alpes-de-Haute-Provence</option>
  3673
+<option value="05">05 - Hautes-Alpes</option>
  3674
+<option value="06">06 - Alpes-Maritimes</option>
  3675
+<option value="07">07 - Ardeche</option>
  3676
+<option value="08">08 - Ardennes</option>
  3677
+<option value="09">09 - Ariege</option>
  3678
+<option value="10">10 - Aube</option>
  3679
+<option value="11">11 - Aude</option>
  3680
+<option value="12">12 - Aveyron</option>
  3681
+<option value="13">13 - Bouches-du-Rhone</option>
  3682
+<option value="14">14 - Calvados</option>
  3683
+<option value="15">15 - Cantal</option>
  3684
+<option value="16">16 - Charente</option>
  3685
+<option value="17">17 - Charente-Maritime</option>
  3686
+<option value="18">18 - Cher</option>
  3687
+<option value="19">19 - Correze</option>
  3688
+<option value="21">21 - Cote-d&#39;Or</option>
  3689
+<option value="22">22 - Cotes-d&#39;Armor</option>
  3690
+<option value="23">23 - Creuse</option>
  3691
+<option value="24">24 - Dordogne</option>
  3692
+<option value="25">25 - Doubs</option>
  3693
+<option value="26">26 - Drome</option>
  3694
+<option value="27">27 - Eure</option>
  3695
+<option value="28">28 - Eure-et-Loire</option>
  3696
+<option value="29">29 - Finistere</option>
  3697
+<option value="2A">2A - Corse-du-Sud</option>
  3698
+<option value="2B">2B - Haute-Corse</option>
  3699
+<option value="30">30 - Gard</option>
  3700
+<option value="31">31 - Haute-Garonne</option>
  3701
+<option value="32">32 - Gers</option>
  3702
+<option value="33">33 - Gironde</option>
  3703
+<option value="34">34 - Herault</option>
  3704
+<option value="35">35 - Ille-et-Vilaine</option>
  3705
+<option value="36">36 - Indre</option>
  3706
+<option value="37">37 - Indre-et-Loire</option>
  3707
+<option value="38">38 - Isere</option>
  3708
+<option value="39">39 - Jura</option>
  3709
+<option value="40">40 - Landes</option>
  3710
+<option value="41">41 - Loir-et-Cher</option>
  3711
+<option value="42">42 - Loire</option>
  3712
+<option value="43">43 - Haute-Loire</option>
  3713
+<option value="44">44 - Loire-Atlantique</option>
  3714
+<option value="45">45 - Loiret</option>
  3715
+<option value="46">46 - Lot</option>
  3716
+<option value="47">47 - Lot-et-Garonne</option>
  3717
+<option value="48">48 - Lozere</option>
  3718
+<option value="49">49 - Maine-et-Loire</option>
  3719
+<option value="50">50 - Manche</option>
  3720
+<option value="51">51 - Marne</option>
  3721
+<option value="52">52 - Haute-Marne</option>
  3722
+<option value="53">53 - Mayenne</option>
  3723
+<option value="54">54 - Meurthe-et-Moselle</option>
  3724
+<option value="55">55 - Meuse</option>
  3725
+<option value="56">56 - Morbihan</option>
  3726
+<option value="57">57 - Moselle</option>
  3727
+<option value="58">58 - Nievre</option>
  3728
+<option value="59">59 - Nord</option>
  3729
+<option value="60">60 - Oise</option>
  3730
+<option value="61">61 - Orne</option>
  3731
+<option value="62">62 - Pas-de-Calais</option>
  3732
+<option value="63">63 - Puy-de-Dome</option>
  3733
+<option value="64">64 - Pyrenees-Atlantiques</option>
  3734
+<option value="65">65 - Hautes-Pyrenees</option>
  3735
+<option value="66">66 - Pyrenees-Orientales</option>
  3736
+<option value="67">67 - Bas-Rhin</option>
  3737
+<option value="68">68 - Haut-Rhin</option>
  3738
+<option value="69">69 - Rhone</option>
  3739
+<option value="70">70 - Haute-Saone</option>
  3740
+<option value="71">71 - Saone-et-Loire</option>
  3741
+<option value="72">72 - Sarthe</option>
  3742
+<option value="73">73 - Savoie</option>
  3743
+<option value="74">74 - Haute-Savoie</option>
  3744
+<option value="75">75 - Paris</option>
  3745
+<option value="76">76 - Seine-Maritime</option>
  3746
+<option value="77">77 - Seine-et-Marne</option>
  3747
+<option value="78">78 - Yvelines</option>
  3748
+<option value="79">79 - Deux-Sevres</option>
  3749
+<option value="80">80 - Somme</option>
  3750
+<option value="81">81 - Tarn</option>
  3751
+<option value="82">82 - Tarn-et-Garonne</option>
  3752
+<option value="83">83 - Var</option>
  3753
+<option value="84">84 - Vaucluse</option>
  3754
+<option value="85">85 - Vendee</option>
  3755
+<option value="86">86 - Vienne</option>
  3756
+<option value="87">87 - Haute-Vienne</option>
  3757
+<option value="88">88 - Vosges</option>
  3758
+<option value="89">89 - Yonne</option>
  3759
+<option value="90">90 - Territoire de Belfort</option>
  3760
+<option value="91">91 - Essonne</option>
  3761
+<option value="92">92 - Hauts-de-Seine</option>
  3762
+<option value="93">93 - Seine-Saint-Denis</option>
  3763
+<option value="94">94 - Val-de-Marne</option>
  3764
+<option value="95">95 - Val-d&#39;Oise</option>
  3765
+<option value="2A">2A - Corse du sud</option>
  3766
+<option value="2B">2B - Haute Corse</option>
  3767
+<option value="971">971 - Guadeloupe</option>
  3768
+<option value="972">972 - Martinique</option>
  3769
+<option value="973">973 - Guyane</option>
  3770
+<option value="974">974 - La Reunion</option>
  3771
+<option value="975">975 - Saint-Pierre-et-Miquelon</option>
  3772
+<option value="976">976 - Mayotte</option>
  3773
+<option value="984">984 - Terres Australes et Antarctiques</option>
  3774
+<option value="986">986 - Wallis et Futuna</option>
  3775
+<option value="987">987 - Polynesie Francaise</option>
  3776
+<option value="988">988 - Nouvelle-Caledonie</option>
  3777
+</select>
  3778
+
3559 3779
 #################################
3560 3780
 # Tests of underlying functions #
3561 3781
 #################################

0 notes on commit 955f4db

Please sign in to comment.
Something went wrong with that request. Please try again.