Ticket #15705: 15705.localflavor-hr.diff

File 15705.localflavor-hr.diff, 24.9 KB (added by Julien Phalip, 14 years ago)
  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index a19e49b..ab9f572 100644
    a b answer newbie questions, and generally made Django that much better:  
    528528    Gasper Zejn <zejn@kiberpipa.org>
    529529    Jarek Zgoda <jarek.zgoda@gmail.com>
    530530    Cheng Zhang
     531    Zlatko Mašek <zlatko.masek@gmail.com>
    531532
    532533A big THANK YOU goes to:
    533534
  • new file django/contrib/localflavor/hr/forms.py

    diff --git a/django/contrib/localflavor/hr/__init__.py b/django/contrib/localflavor/hr/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/localflavor/hr/forms.py b/django/contrib/localflavor/hr/forms.py
    new file mode 100644
    index 0000000..9304d80
    - +  
     1# -*- coding: utf-8 -*-
     2"""
     3HR-specific Form helpers
     4"""
     5import re
     6
     7from django.forms.fields import Field, Select, RegexField
     8from django.core.validators import EMPTY_VALUES
     9from django.forms import ValidationError
     10from django.utils.translation import ugettext_lazy as _
     11from django.utils.encoding import smart_unicode
     12
     13jmbg_re = re.compile(r'^(?P<dd>\d{2})(?P<mm>\d{2})(?P<yyy>\d{3})' + \
     14            r'(?P<rr>\d{2})(?P<bbb>\d{3})(?P<k>\d{1})$')
     15oib_re = re.compile(r'^\d{11}$')
     16plate_re = re.compile(ur'^(?P<prefix>[A-ZČŠŽ]{2})' + \
     17            ur'(?P<number>\d{3,4})(?P<suffix>[ABCDEFGHIJKLMNOPRSTUVZ]{1,2})$')
     18postal_code_re = re.compile(r'^\d{5}$')
     19phone_re = re.compile(r'^(\+385|00385|0)(?P<prefix>\d{2})(?P<number>\d{6,7})$')
     20jmbag_re = re.compile(r'^601983(?P<copy>\d{1})1(?P<jmbag>\d{10})(?P<k>\d{1})$')
     21
     22class HRCountySelect(Select):
     23    """
     24    A Select widget that uses a list of counties of Croatia as its choices.
     25    """
     26
     27    def __init__(self, attrs=None):
     28        from hr_choices import HR_COUNTY_CHOICES
     29        super(HRCountySelect, self).__init__(attrs, choices=HR_COUNTY_CHOICES)
     30
     31class HRLicensePlatePrefixSelect(Select):
     32    """
     33    A Select widget that uses a list of vehicle license plate prefixes of
     34    Croatia as its choices.
     35    """
     36
     37    def __init__(self, attrs=None):
     38        from hr_choices import HR_LICENSE_PLATE_PREFIX_CHOICES
     39        super(HRLicensePlatePrefixSelect, self).__init__(attrs,
     40            choices=HR_LICENSE_PLATE_PREFIX_CHOICES)
     41
     42class HRPhoneNumberPrefixSelect(Select):
     43    """
     44    A Select widget that uses a list of phone number prefixes of Croatia as its
     45    choices.
     46    """
     47
     48    def __init__(self, attrs=None):
     49        from hr_choices import HR_PHONE_NUMBER_PREFIX_CHOICES
     50        super(HRPhoneNumberPrefixSelect, self).__init__(attrs,
     51            choices=HR_PHONE_NUMBER_PREFIX_CHOICES)
     52
     53class HRJMBGField(Field):
     54    """
     55    Unique Master Citizen Number (JMBG) field.
     56    The number is still in use in Croatia, but it is being replaced by OIB.
     57
     58    Source: http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
     59
     60    For who might be reimplementing:
     61    The "area" regular expression group is used to calculate the region where a
     62    person was registered. Additional validation can be implemented in
     63    accordance with it, however this could result in exclusion of legit
     64    immigrated citizens. Therefore, this field works for any ex-Yugoslavia
     65    country.
     66    """
     67    default_error_messages = {
     68        'invalid': _('Enter a valid 13 digit JMBG'),
     69        'date': _('Error in date segment'),
     70    }
     71
     72    def clean(self, value):
     73        super(HRJMBGField, self).clean(value)
     74        if value in EMPTY_VALUES:
     75            return u''
     76
     77        value = value.strip()
     78
     79        matches = jmbg_re.search(value)
     80        if matches is None:
     81            raise ValidationError(self.error_messages['invalid'])
     82
     83        # Make sure the date part is correct.
     84        dd = int(matches.group('dd'))
     85        mm = int(matches.group('mm'))
     86        yyy = int(matches.group('yyy'))
     87        import datetime
     88        try:
     89            datetime.date(yyy,mm,dd)
     90        except:
     91            raise ValidationError(self.error_messages['date'])
     92
     93        # Validate checksum.
     94        k = matches.group('k')
     95        checksum = 0
     96        for i,j in zip(range(7,1,-1),range(6)):
     97            checksum+=i*(int(value[j])+int(value[13-i]))
     98        m = 11 - checksum % 11
     99        if m == 10:
     100            raise ValidationError(self.error_messages['invalid'])
     101        if m == 11 and k != '0':
     102            raise ValidationError(self.error_messages['invalid'])
     103        if not str(m) == k:
     104            raise ValidationError(self.error_messages['invalid'])
     105
     106        return u'%s' % (value, )
     107
     108class HROIBField(RegexField):
     109    """
     110    Personal Identification Number of Croatia (OIB) field.
     111
     112    http://www.oib.hr/
     113    """
     114    default_error_messages = {
     115        'invalid': _('Enter a valid 11 digit OIB'),
     116    }
     117
     118    def __init__(self, *args, **kwargs):
     119        super(HROIBField, self).__init__(r'^\d{11}$',
     120            min_length=11, max_length=11, *args, **kwargs)
     121
     122    def clean(self, value):
     123        super(HROIBField, self).clean(value)
     124        if value in EMPTY_VALUES:
     125            return u''
     126
     127        return '%s' % (value, )
     128
     129class HRLicensePlateField(Field):
     130    """
     131    Vehicle license plate of Croatia field. Normalizes to the specific format
     132    below. Suffix is constructed from the shared letters of the Croatian and
     133    English alphabets.
     134
     135    Format examples:
     136        SB 123-A
     137        (but also supports more characters)
     138        ZG 1234-AA
     139
     140    Used for standardized license plates only.
     141    """
     142    default_error_messages = {
     143        'invalid': _('Enter a valid vehicle license plate number'),
     144        'area': _('Enter a valid location code'),
     145        'number': _('Number part cannot be zero'),
     146    }
     147
     148    def clean(self, value):
     149        super(HRLicensePlateField, self).clean(value)
     150        if value in EMPTY_VALUES:
     151            return u''
     152
     153        value = re.sub(r'[\s\-]+', '', smart_unicode(value.strip())).upper()
     154
     155        matches = plate_re.search(value)
     156        if matches is None:
     157            raise ValidationError(self.error_messages['invalid'])
     158
     159        # Make sure the prefix is in the list of known codes.
     160        from hr_choices import HR_LICENSE_PLATE_PREFIX_CHOICES
     161        prefix = matches.group('prefix')
     162        if prefix not in [choice[0] for choice in HR_LICENSE_PLATE_PREFIX_CHOICES]:
     163            raise ValidationError(self.error_messages['area'])
     164
     165        # Make sure the number portion is not zero.
     166        number = matches.group('number')
     167        if int(number) == 0:
     168            raise ValidationError(self.error_messages['number'])
     169
     170        return u'%s %s-%s' % (prefix,number,matches.group('suffix'), )
     171
     172class HRPostalCodeField(Field):
     173    """
     174    Postal code of Croatia field.
     175    It consists of exactly five digits ranging from 10000 to possibly less than
     176    60000.
     177
     178    http://www.posta.hr/main.aspx?id=66
     179    """
     180    default_error_messages = {
     181        'invalid': _('Enter a valid 5 digit postal code'),
     182    }
     183
     184    def clean(self, value):
     185        super(HRPostalCodeField, self).clean(value)
     186        if value in EMPTY_VALUES:
     187            return u''
     188
     189        value = value.strip()
     190        if not postal_code_re.search(value):
     191            raise ValidationError(self.error_messages['invalid'])
     192
     193        # Make sure the number is in valid range.
     194        if not 9999<int(value)<60000:
     195            raise ValidationError(self.error_messages['invalid'])
     196
     197        return '%s' % (value, )
     198
     199class HRPhoneNumberField(Field):
     200    """
     201    Phone number of Croatia field.
     202    Format: Complete country code or leading zero, area code prefix, 6 or 7
     203    digit number.
     204    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with
     205    country code (+385 prefix).
     206    """
     207    default_error_messages = {
     208        'invalid': _('Enter a valid phone number'),
     209        'area': _('Enter a valid area or mobile network code'),
     210        'number': _('The phone nubmer is too long'),
     211    }
     212
     213    def clean(self, value):
     214        super(HRPhoneNumberField, self).clean(value)
     215        if value in EMPTY_VALUES:
     216            return u''
     217
     218        value = re.sub(r'[\-\s\(\)]', '', smart_unicode(value))
     219
     220        matches = phone_re.search(value)
     221        if matches is None:
     222            raise ValidationError(self.error_messages['invalid'])
     223
     224        # Make sure the prefix is in the list of known codes.
     225        from hr_choices import HR_PHONE_NUMBER_PREFIX_CHOICES
     226        prefix = matches.group('prefix')
     227        number = matches.group('number')
     228        if prefix[0] == '1':
     229            number = prefix[1] + number
     230            prefix = prefix[0]
     231        if prefix not in [choice[0] for choice in HR_PHONE_NUMBER_PREFIX_CHOICES]:
     232            raise ValidationError(self.error_messages['area'])
     233
     234        # Make sure the number is of adequate length.
     235        if prefix=='1' and len(number)!=7:
     236            raise ValidationError(self.error_messages['number'])
     237
     238        return '%s%s%s' % ('+385',prefix,number)
     239
     240class HRJMBAGField(Field):
     241    """
     242    Unique Master Academic Citizen Number of Croatia (JMBAG) field.
     243    This number is used by college students and professors in Croatia.
     244
     245    http://www.cap.srce.hr/IzgledX.aspx
     246    """
     247    default_error_messages = {
     248        'invalid': _('Enter a valid 19 digit JMBAG starting with 601983'),
     249        'copy': _('Card issue number cannot be zero'),
     250    }
     251
     252    def clean(self, value):
     253        super(HRJMBAGField, self).clean(value)
     254        if value in EMPTY_VALUES:
     255            return u''
     256
     257        value = re.sub(r'[\-\s]', '', value.strip())
     258
     259        matches = jmbag_re.search(value)
     260        if matches is None:
     261            raise ValidationError(self.error_messages['invalid'])
     262
     263        # Make sure the issue number is not zero.
     264        if matches.group('copy')=='0':
     265            raise ValidationError(self.error_messages['copy'])
     266
     267        # Validate checksum using Luhn algorithm.
     268        num = [int(x) for x in value]
     269        if not sum(num[::-2] + [sum(divmod(d * 2, 10)) for d in num[-2::-2]]) % 10 == 0:
     270            raise ValidationError(self.error_messages['invalid'])
     271
     272        return '%s' % (value, )
  • new file django/contrib/localflavor/hr/hr_choices.py

    diff --git a/django/contrib/localflavor/hr/hr_choices.py b/django/contrib/localflavor/hr/hr_choices.py
    new file mode 100644
    index 0000000..888ec51
    - +  
     1# -*- coding: utf-8 -*-
     2
     3from django.utils.translation import ugettext_lazy as _
     4
     5"""
     6Sources:
     7    Croatian Counties: http://en.wikipedia.org/wiki/ISO_3166-2:HR
     8
     9    Croatia doesn't have official abbreviations for counties. The ones provided
     10    are in common use.
     11"""
     12
     13HR_COUNTY_CHOICES = (
     14    ('GZG', _('Grad Zagreb')),
     15    (u'BBŽ', _(u'Bjelovarsko-bilogorska županija')),
     16    (u'BPŽ', _(u'Brodsko-posavska županija')),
     17    (u'DNŽ', _(u'Dubrovačko-neretvanska županija')),
     18    (u'IŽ', _(u'Istarska županija')),
     19    (u'KŽ', _(u'Karlovačka županija')),
     20    (u'KKŽ', _(u'Koprivničko-križevačka županija')),
     21    (u'KZŽ', _(u'Krapinsko-zagorska županija')),
     22    (u'LSŽ', _(u'Ličko-senjska županija')),
     23    (u'MŽ', _(u'Međimurska županija')),
     24    (u'OBŽ', _(u'Osječko-baranjska županija')),
     25    (u'PSŽ', _(u'Požeško-slavonska županija')),
     26    (u'PGŽ', _(u'Primorsko-goranska županija')),
     27    (u'SMŽ', _(u'Sisačko-moslavačka županija')),
     28    (u'SDŽ', _(u'Splitsko-dalmatinska županija')),
     29    (u'ŠKŽ', _(u'Šibensko-kninska županija')),
     30    (u'VŽ', _(u'Varaždinska županija')),
     31    (u'VPŽ', _(u'Virovitičko-podravska županija')),
     32    (u'VSŽ', _(u'Vukovarsko-srijemska županija')),
     33    (u'ZDŽ', _(u'Zadarska županija')),
     34    (u'ZGŽ', _(u'Zagrebačka županija')),
     35)
     36
     37"""
     38Sources:
     39    http://hr.wikipedia.org/wiki/Dodatak:Popis_registracijskih_oznaka_za_cestovna_vozila_u_Hrvatskoj
     40
     41    Only common license plate prefixes are provided. Special cases and obsolete prefixes are omitted.
     42"""
     43
     44HR_LICENSE_PLATE_PREFIX_CHOICES = (
     45    ('BJ', 'BJ'),
     46    ('BM', 'BM'),
     47    (u'ČK', u'ČK'),
     48    ('DA', 'DA'),
     49    ('DE', 'DE'),
     50    ('DJ', 'DJ'),
     51    ('DU', 'DU'),
     52    ('GS', 'GS'),
     53    ('IM', 'IM'),
     54    ('KA', 'KA'),
     55    ('KC', 'KC'),
     56    ('KR', 'KR'),
     57    ('KT', 'KT'),
     58    (u'KŽ', u'KŽ'),
     59    ('MA', 'MA'),
     60    ('NA', 'NA'),
     61    ('NG', 'NG'),
     62    ('OG', 'OG'),
     63    ('OS', 'OS'),
     64    ('PU', 'PU'),
     65    (u'PŽ', u'PŽ'),
     66    ('RI', 'RI'),
     67    ('SB', 'SB'),
     68    ('SK', 'SK'),
     69    ('SL', 'SL'),
     70    ('ST', 'ST'),
     71    (u'ŠI', u'ŠI'),
     72    ('VK', 'VK'),
     73    ('VT', 'VT'),
     74    ('VU', 'VU'),
     75    (u'VŽ', u'VŽ'),
     76    ('ZD', 'ZD'),
     77    ('ZG', 'ZG'),
     78    (u'ŽU', u'ŽU'),
     79)
     80
     81"""
     82    The list includes county and cellular network phone number prefixes.
     83"""
     84
     85HR_PHONE_NUMBER_PREFIX_CHOICES = (
     86    ('1', '01'),
     87    ('20', '020'),
     88    ('21', '021'),
     89    ('22', '022'),
     90    ('23', '023'),
     91    ('31', '031'),
     92    ('32', '032'),
     93    ('33', '033'),
     94    ('34', '034'),
     95    ('35', '035'),
     96    ('40', '040'),
     97    ('42', '042'),
     98    ('43', '043'),
     99    ('44', '044'),
     100    ('47', '047'),
     101    ('48', '048'),
     102    ('49', '049'),
     103    ('51', '051'),
     104    ('52', '052'),
     105    ('53', '053'),
     106    ('91', '091'),
     107    ('92', '092'),
     108    ('95', '095'),
     109    ('97', '097'),
     110    ('98', '098'),
     111    ('99', '099'),
     112)
  • docs/ref/contrib/localflavor.txt

    diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt
    index f54341e..ef686c4 100644
    a b Countries currently supported by :mod:`~django.contrib.localflavor` are:  
    4343    * Brazil_
    4444    * Canada_
    4545    * Chile_
     46    * Croatia_
    4647    * Czech_
    4748    * Finland_
    4849    * France_
    Here's an example of how to use them::  
    9293.. _Brazil: `Brazil (br)`_
    9394.. _Canada: `Canada (ca)`_
    9495.. _Chile: `Chile (cl)`_
     96.. _Croatia: `Croatia (hr)`_
    9597.. _Czech: `Czech (cz)`_
    9698.. _Finland: `Finland (fi)`_
    9799.. _France: `France (fr)`_
    Chile (``cl``)  
    322324    A ``Select`` widget that uses a list of Chilean regions (Regiones) as its
    323325    choices.
    324326
     327Croatia (``hr``)
     328==============
     329
     330.. class:: hr.forms.HRCountySelect
     331
     332    A ``Select`` widget that uses a list of counties of Croatia as its choices.
     333
     334.. class:: hr.forms.HRPhoneNumberPrefixSelect
     335
     336    A ``Select`` widget that uses a list of phone number prefixes of Croatia as
     337    its choices.
     338
     339.. class:: hr.forms.HRLicensePlatePrefixSelect
     340
     341    A ``Select`` widget that uses a list of vehicle license plate prefixes of
     342    Croatia as its choices.
     343
     344.. class:: hr.forms.HRPhoneNumberField
     345
     346    A form field that validates input as a phone number of Croatia.
     347    A valid format is a country code or a leading zero, area code prefix, 6 or 7
     348    digit number; e.g. +385XXXXXXXX or 0XXXXXXXX
     349    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with
     350    country code (+385 prefix).
     351
     352.. class:: hr.forms.HRLicensePlateField
     353
     354    A form field that validates input as a vehicle license plate of Croatia.
     355    Normalizes to the specific format XX YYYY-XX where X is a letter and Y a
     356    digit. There can be three or four digits.
     357    Suffix is constructed from the shared letters of the Croatian and English
     358    alphabets.
     359    It is used for standardized license plates only. Special cases like license
     360    plates for oldtimers, temporary license plates, government institution
     361    license plates and customized license plates are not covered by this field.
     362
     363.. class:: hr.forms.HRPostalCodeField
     364
     365    A form field that validates input as a postal code of Croatia.
     366    It consists of exactly five digits ranging from 10000 to 59999 inclusive.
     367
     368.. class:: hr.forms.HROIBField
     369
     370    A form field that validates input as a Personal Identification Number (OIB)
     371    of Croatia.
     372    It consists of exactly eleven digits.
     373
     374.. class:: hr.forms.HRJMBGField
     375
     376    A form field that validates input as a Unique Master Citizen Number (JMBG).
     377    The number is still in use in Croatia, but it is being replaced by OIB.
     378    This field works for other ex-Yugoslavia countries as well where the JMBG is
     379    still in use.
     380    The area segment of the JMBG is not validated because the citizens might
     381    have emigrated to another ex-Yugoslavia country.
     382    The number consists of exactly thirteen digits.
     383
     384.. class:: hr.forms.HRJMBAGField
     385
     386    A form field that validates input as a Unique Master Academic Citizen Number
     387    (JMBAG) of Croatia.
     388    This number is used by college students and professors in Croatia.
     389    The number consists of exactly nineteen digits.
     390
    325391Czech (``cz``)
    326392==============
    327393
  • new file tests/regressiontests/forms/localflavor/hr.py

    diff --git a/tests/regressiontests/forms/localflavor/hr.py b/tests/regressiontests/forms/localflavor/hr.py
    new file mode 100644
    index 0000000..5a7a6b1
    - +  
     1# -*- coding: utf-8 -*-
     2from django.contrib.localflavor.hr.forms import (HRCountySelect,
     3    HRPhoneNumberPrefixSelect, HRLicensePlatePrefixSelect, HRPhoneNumberField,
     4    HRLicensePlateField, HRPostalCodeField, HROIBField, HRJMBGField,
     5    HRJMBAGField)
     6
     7from utils import LocalFlavorTestCase
     8
     9class HRLocalFlavorTests(LocalFlavorTestCase):
     10    def test_HRCountySelect(self):
     11        f = HRCountySelect()
     12        out = u'''<select name="county">
     13<option value="GZG" selected="selected">Grad Zagreb</option>
     14<option value="BBŽ">Bjelovarsko-bilogorska županija</option>
     15<option value="BPŽ">Brodsko-posavska županija</option>
     16<option value="DNŽ">Dubrovačko-neretvanska županija</option>
     17<option value="IŽ">Istarska županija</option>
     18<option value="KŽ">Karlovačka županija</option>
     19<option value="KKŽ">Koprivničko-križevačka županija</option>
     20<option value="KZŽ">Krapinsko-zagorska županija</option>
     21<option value="LSŽ">Ličko-senjska županija</option>
     22<option value="MŽ">Međimurska županija</option>
     23<option value="OBŽ">Osječko-baranjska županija</option>
     24<option value="PSŽ">Požeško-slavonska županija</option>
     25<option value="PGŽ">Primorsko-goranska županija</option>
     26<option value="SMŽ">Sisačko-moslavačka županija</option>
     27<option value="SDŽ">Splitsko-dalmatinska županija</option>
     28<option value="ŠKŽ">Šibensko-kninska županija</option>
     29<option value="VŽ">Varaždinska županija</option>
     30<option value="VPŽ">Virovitičko-podravska županija</option>
     31<option value="VSŽ">Vukovarsko-srijemska županija</option>
     32<option value="ZDŽ">Zadarska županija</option>
     33<option value="ZGŽ">Zagrebačka županija</option>
     34</select>'''
     35        self.assertEqual(f.render('county', 'GZG'), out)
     36
     37    def test_HRPhoneNumberPrefixSelect(self):
     38        f = HRPhoneNumberPrefixSelect()
     39        out = u'''<select name="phone">
     40<option value="1" selected="selected">01</option>
     41<option value="20">020</option>
     42<option value="21">021</option>
     43<option value="22">022</option>
     44<option value="23">023</option>
     45<option value="31">031</option>
     46<option value="32">032</option>
     47<option value="33">033</option>
     48<option value="34">034</option>
     49<option value="35">035</option>
     50<option value="40">040</option>
     51<option value="42">042</option>
     52<option value="43">043</option>
     53<option value="44">044</option>
     54<option value="47">047</option>
     55<option value="48">048</option>
     56<option value="49">049</option>
     57<option value="51">051</option>
     58<option value="52">052</option>
     59<option value="53">053</option>
     60<option value="91">091</option>
     61<option value="92">092</option>
     62<option value="95">095</option>
     63<option value="97">097</option>
     64<option value="98">098</option>
     65<option value="99">099</option>
     66</select>'''
     67        self.assertEqual(f.render('phone', '1'), out)
     68
     69    def test_HRLicensePlatePrefixSelect(self):
     70        f = HRLicensePlatePrefixSelect()
     71        out = u'''<select name="license">
     72<option value="BJ" selected="selected">BJ</option>
     73<option value="BM">BM</option>
     74<option value="ČK">ČK</option>
     75<option value="DA">DA</option>
     76<option value="DE">DE</option>
     77<option value="DJ">DJ</option>
     78<option value="DU">DU</option>
     79<option value="GS">GS</option>
     80<option value="IM">IM</option>
     81<option value="KA">KA</option>
     82<option value="KC">KC</option>
     83<option value="KR">KR</option>
     84<option value="KT">KT</option>
     85<option value="KŽ">KŽ</option>
     86<option value="MA">MA</option>
     87<option value="NA">NA</option>
     88<option value="NG">NG</option>
     89<option value="OG">OG</option>
     90<option value="OS">OS</option>
     91<option value="PU">PU</option>
     92<option value="PŽ">PŽ</option>
     93<option value="RI">RI</option>
     94<option value="SB">SB</option>
     95<option value="SK">SK</option>
     96<option value="SL">SL</option>
     97<option value="ST">ST</option>
     98<option value="ŠI">ŠI</option>
     99<option value="VK">VK</option>
     100<option value="VT">VT</option>
     101<option value="VU">VU</option>
     102<option value="VŽ">VŽ</option>
     103<option value="ZD">ZD</option>
     104<option value="ZG">ZG</option>
     105<option value="ŽU">ŽU</option>
     106</select>'''
     107        self.assertEqual(f.render('license', 'BJ'), out)
     108
     109    def test_HRPhoneNumberField(self):
     110        error_invalid = [u'Enter a valid phone number']
     111        error_area = [u'Enter a valid area or mobile network code']
     112        error_number = [u'The phone nubmer is too long']
     113        valid = {
     114            '+38511234567': '+38511234567',
     115            '0038511234567': '+38511234567',
     116            '011234567': '+38511234567',
     117            '+38521123456': '+38521123456',
     118            '0038521123456': '+38521123456',
     119            '021123456': '+38521123456',
     120        }
     121        invalid = {
     122            '123456789': error_invalid,
     123            '0811234567': error_area,
     124            '0111234567': error_number,
     125        }
     126        self.assertFieldOutput(HRPhoneNumberField, valid, invalid)
     127
     128    def test_HRLicensePlateField(self):
     129        error_invalid = [u'Enter a valid vehicle license plate number']
     130        error_area = [u'Enter a valid location code']
     131        error_number = [u'Number part cannot be zero']
     132        valid = {
     133            'ZG 1234-AA': u'ZG 1234-AA',
     134            'ZG 123-A': u'ZG 123-A',
     135        }
     136        invalid = {
     137            'PV12345': error_invalid,
     138            'PV1234AA': error_area,
     139            'ZG0000CC': error_number,
     140        }
     141        self.assertFieldOutput(HRLicensePlateField, valid, invalid)
     142
     143    def test_HRPostalCodeField(self):
     144        error_invalid = [u'Enter a valid 5 digit postal code']
     145        valid = {
     146            '10000': '10000',
     147            '35410': '35410',
     148        }
     149        invalid = {
     150            'ABCD': error_invalid,
     151            '99999': error_invalid,
     152        }
     153        self.assertFieldOutput(HRPostalCodeField, valid, invalid)
     154
     155    def test_HROIBField(self):
     156        error_invalid = [u'Enter a valid 11 digit OIB']
     157        valid = {
     158            '12345678901': '12345678901',
     159        }
     160        invalid = {
     161            '1234567890': error_invalid,
     162            'ABCDEFGHIJK': error_invalid,
     163        }
     164        self.assertFieldOutput(HROIBField, valid, invalid)
     165
     166    def test_HRJMBGField(self):
     167        error_invalid = [u'Enter a valid 13 digit JMBG']
     168        error_date = [u'Error in date segment']
     169        valid = {
     170            '1211984302155': '1211984302155',
     171            '2701984307107': '2701984307107',
     172        }
     173        invalid = {
     174            '1211984302156': error_invalid,
     175            'ABCDEFG': error_invalid,
     176            '9999999123456': error_date,
     177        }
     178        self.assertFieldOutput(HRJMBGField, valid, invalid)
     179
     180    def test_HRJMBAGField(self):
     181        error_invalid = [u'Enter a valid 19 digit JMBAG starting with 601983']
     182        error_copy = [u'Card issue number cannot be zero']
     183        valid = {
     184            '601983 11 0130185856 4': '6019831101301858564',
     185        }
     186        invalid = {
     187            '601983 11 0130185856 5': error_invalid,
     188            '601983 01 0130185856 4': error_copy,
     189        }
     190        self.assertFieldOutput(HRJMBAGField, valid, invalid)
  • tests/regressiontests/forms/localflavortests.py

    diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py
    index 5ee1c32..c13a904 100644
    a b from localflavor.es import ESLocalFlavorTests  
    1212from localflavor.fi import FILocalFlavorTests
    1313from localflavor.fr import FRLocalFlavorTests
    1414from localflavor.generic import GenericLocalFlavorTests
     15from localflavor.hr import HRLocalFlavorTests
    1516from localflavor.id import IDLocalFlavorTests
    1617from localflavor.ie import IELocalFlavorTests
    1718from localflavor.il import ILLocalFlavorTests
  • tests/regressiontests/forms/tests/__init__.py

    diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py
    index 2d96b2f..325bdc3 100644
    a b from regressiontests.forms.localflavortests import (  
    1616    BELocalFlavorTests, BRLocalFlavorTests, CALocalFlavorTests,
    1717    CHLocalFlavorTests, CLLocalFlavorTests, CZLocalFlavorTests,
    1818    DELocalFlavorTests, ESLocalFlavorTests, FILocalFlavorTests,
    19     FRLocalFlavorTests, GenericLocalFlavorTests, IDLocalFlavorTests,
     19    FRLocalFlavorTests, GenericLocalFlavorTests, HRLocalFlavorTests,
     20    IDLocalFlavorTests,
    2021    IELocalFlavorTests, ILLocalFlavorTests, ISLocalFlavorTests,
    2122    ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests,
    2223    NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests,
Back to Top