Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15705 -- Added Croatian (hr) localflavor. Thanks, Zlatko Mašek…

… and Julien Phalip.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16077 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7478aeb0a7f0726e7099586a30f980f369d676e6 1 parent e1f7bc0
Jannis Leidel authored
1  AUTHORS
@@ -531,6 +531,7 @@ answer newbie questions, and generally made Django that much better:
531 531
     Gasper Zejn <zejn@kiberpipa.org>
532 532
     Jarek Zgoda <jarek.zgoda@gmail.com>
533 533
     Cheng Zhang
  534
+    Zlatko Mašek <zlatko.masek@gmail.com>
534 535
 
535 536
 A big THANK YOU goes to:
536 537
 
281  django/contrib/localflavor/hr/forms.py
... ...
@@ -0,0 +1,281 @@
  1
+# -*- coding: utf-8 -*-
  2
+"""
  3
+HR-specific Form helpers
  4
+"""
  5
+import re
  6
+
  7
+from django.forms.fields import Field, Select, RegexField
  8
+from django.core.validators import EMPTY_VALUES
  9
+from django.forms import ValidationError
  10
+from django.utils.translation import ugettext_lazy as _
  11
+from django.utils.encoding import smart_unicode
  12
+
  13
+jmbg_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})$')
  15
+oib_re = re.compile(r'^\d{11}$')
  16
+plate_re = re.compile(ur'^(?P<prefix>[A-ZČŠŽ]{2})' + \
  17
+            ur'(?P<number>\d{3,4})(?P<suffix>[ABCDEFGHIJKLMNOPRSTUVZ]{1,2})$')
  18
+postal_code_re = re.compile(r'^\d{5}$')
  19
+phone_re = re.compile(r'^(\+385|00385|0)(?P<prefix>\d{2})(?P<number>\d{6,7})$')
  20
+jmbag_re = re.compile(r'^601983(?P<copy>\d{1})1(?P<jmbag>\d{10})(?P<k>\d{1})$')
  21
+
  22
+
  23
+class HRCountySelect(Select):
  24
+    """
  25
+    A Select widget that uses a list of counties of Croatia as its choices.
  26
+    """
  27
+
  28
+    def __init__(self, attrs=None):
  29
+        from hr_choices import HR_COUNTY_CHOICES
  30
+        super(HRCountySelect, self).__init__(attrs, choices=HR_COUNTY_CHOICES)
  31
+
  32
+
  33
+class HRLicensePlatePrefixSelect(Select):
  34
+    """
  35
+    A Select widget that uses a list of vehicle license plate prefixes of
  36
+    Croatia as its choices.
  37
+    """
  38
+
  39
+    def __init__(self, attrs=None):
  40
+        from hr_choices import HR_LICENSE_PLATE_PREFIX_CHOICES
  41
+        super(HRLicensePlatePrefixSelect, self).__init__(attrs,
  42
+            choices=HR_LICENSE_PLATE_PREFIX_CHOICES)
  43
+
  44
+
  45
+class HRPhoneNumberPrefixSelect(Select):
  46
+    """
  47
+    A Select widget that uses a list of phone number prefixes of Croatia as its
  48
+    choices.
  49
+    """
  50
+
  51
+    def __init__(self, attrs=None):
  52
+        from hr_choices import HR_PHONE_NUMBER_PREFIX_CHOICES
  53
+        super(HRPhoneNumberPrefixSelect, self).__init__(attrs,
  54
+            choices=HR_PHONE_NUMBER_PREFIX_CHOICES)
  55
+
  56
+
  57
+class HRJMBGField(Field):
  58
+    """
  59
+    Unique Master Citizen Number (JMBG) field.
  60
+    The number is still in use in Croatia, but it is being replaced by OIB.
  61
+
  62
+    Source: http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  63
+
  64
+    For who might be reimplementing:
  65
+    The "area" regular expression group is used to calculate the region where a
  66
+    person was registered. Additional validation can be implemented in
  67
+    accordance with it, however this could result in exclusion of legit
  68
+    immigrated citizens. Therefore, this field works for any ex-Yugoslavia
  69
+    country.
  70
+    """
  71
+    default_error_messages = {
  72
+        'invalid': _('Enter a valid 13 digit JMBG'),
  73
+        'date': _('Error in date segment'),
  74
+    }
  75
+
  76
+    def clean(self, value):
  77
+        super(HRJMBGField, self).clean(value)
  78
+        if value in EMPTY_VALUES:
  79
+            return u''
  80
+
  81
+        value = value.strip()
  82
+
  83
+        matches = jmbg_re.search(value)
  84
+        if matches is None:
  85
+            raise ValidationError(self.error_messages['invalid'])
  86
+
  87
+        # Make sure the date part is correct.
  88
+        dd = int(matches.group('dd'))
  89
+        mm = int(matches.group('mm'))
  90
+        yyy = int(matches.group('yyy'))
  91
+        import datetime
  92
+        try:
  93
+            datetime.date(yyy,mm,dd)
  94
+        except:
  95
+            raise ValidationError(self.error_messages['date'])
  96
+
  97
+        # Validate checksum.
  98
+        k = matches.group('k')
  99
+        checksum = 0
  100
+        for i,j in zip(range(7,1,-1),range(6)):
  101
+            checksum+=i*(int(value[j])+int(value[13-i]))
  102
+        m = 11 - checksum % 11
  103
+        if m == 10:
  104
+            raise ValidationError(self.error_messages['invalid'])
  105
+        if m == 11 and k != '0':
  106
+            raise ValidationError(self.error_messages['invalid'])
  107
+        if not str(m) == k:
  108
+            raise ValidationError(self.error_messages['invalid'])
  109
+
  110
+        return u'%s' % (value, )
  111
+
  112
+
  113
+class HROIBField(RegexField):
  114
+    """
  115
+    Personal Identification Number of Croatia (OIB) field.
  116
+
  117
+    http://www.oib.hr/
  118
+    """
  119
+    default_error_messages = {
  120
+        'invalid': _('Enter a valid 11 digit OIB'),
  121
+    }
  122
+
  123
+    def __init__(self, *args, **kwargs):
  124
+        super(HROIBField, self).__init__(r'^\d{11}$',
  125
+            min_length=11, max_length=11, *args, **kwargs)
  126
+
  127
+    def clean(self, value):
  128
+        super(HROIBField, self).clean(value)
  129
+        if value in EMPTY_VALUES:
  130
+            return u''
  131
+
  132
+        return '%s' % (value, )
  133
+
  134
+
  135
+class HRLicensePlateField(Field):
  136
+    """
  137
+    Vehicle license plate of Croatia field. Normalizes to the specific format
  138
+    below. Suffix is constructed from the shared letters of the Croatian and
  139
+    English alphabets.
  140
+
  141
+    Format examples:
  142
+        SB 123-A
  143
+        (but also supports more characters)
  144
+        ZG 1234-AA
  145
+
  146
+    Used for standardized license plates only.
  147
+    """
  148
+    default_error_messages = {
  149
+        'invalid': _('Enter a valid vehicle license plate number'),
  150
+        'area': _('Enter a valid location code'),
  151
+        'number': _('Number part cannot be zero'),
  152
+    }
  153
+
  154
+    def clean(self, value):
  155
+        super(HRLicensePlateField, self).clean(value)
  156
+        if value in EMPTY_VALUES:
  157
+            return u''
  158
+
  159
+        value = re.sub(r'[\s\-]+', '', smart_unicode(value.strip())).upper()
  160
+
  161
+        matches = plate_re.search(value)
  162
+        if matches is None:
  163
+            raise ValidationError(self.error_messages['invalid'])
  164
+
  165
+        # Make sure the prefix is in the list of known codes.
  166
+        from hr_choices import HR_LICENSE_PLATE_PREFIX_CHOICES
  167
+        prefix = matches.group('prefix')
  168
+        if prefix not in [choice[0] for choice in HR_LICENSE_PLATE_PREFIX_CHOICES]:
  169
+            raise ValidationError(self.error_messages['area'])
  170
+
  171
+        # Make sure the number portion is not zero.
  172
+        number = matches.group('number')
  173
+        if int(number) == 0:
  174
+            raise ValidationError(self.error_messages['number'])
  175
+
  176
+        return u'%s %s-%s' % (prefix,number,matches.group('suffix'), )
  177
+
  178
+
  179
+class HRPostalCodeField(Field):
  180
+    """
  181
+    Postal code of Croatia field.
  182
+    It consists of exactly five digits ranging from 10000 to possibly less than
  183
+    60000.
  184
+
  185
+    http://www.posta.hr/main.aspx?id=66
  186
+    """
  187
+    default_error_messages = {
  188
+        'invalid': _('Enter a valid 5 digit postal code'),
  189
+    }
  190
+
  191
+    def clean(self, value):
  192
+        super(HRPostalCodeField, self).clean(value)
  193
+        if value in EMPTY_VALUES:
  194
+            return u''
  195
+
  196
+        value = value.strip()
  197
+        if not postal_code_re.search(value):
  198
+            raise ValidationError(self.error_messages['invalid'])
  199
+
  200
+        # Make sure the number is in valid range.
  201
+        if not 9999<int(value)<60000:
  202
+            raise ValidationError(self.error_messages['invalid'])
  203
+
  204
+        return '%s' % (value, )
  205
+
  206
+
  207
+class HRPhoneNumberField(Field):
  208
+    """
  209
+    Phone number of Croatia field.
  210
+    Format: Complete country code or leading zero, area code prefix, 6 or 7
  211
+    digit number.
  212
+    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with
  213
+    country code (+385 prefix).
  214
+    """
  215
+    default_error_messages = {
  216
+        'invalid': _('Enter a valid phone number'),
  217
+        'area': _('Enter a valid area or mobile network code'),
  218
+        'number': _('The phone nubmer is too long'),
  219
+    }
  220
+
  221
+    def clean(self, value):
  222
+        super(HRPhoneNumberField, self).clean(value)
  223
+        if value in EMPTY_VALUES:
  224
+            return u''
  225
+
  226
+        value = re.sub(r'[\-\s\(\)]', '', smart_unicode(value))
  227
+
  228
+        matches = phone_re.search(value)
  229
+        if matches is None:
  230
+            raise ValidationError(self.error_messages['invalid'])
  231
+
  232
+        # Make sure the prefix is in the list of known codes.
  233
+        from hr_choices import HR_PHONE_NUMBER_PREFIX_CHOICES
  234
+        prefix = matches.group('prefix')
  235
+        number = matches.group('number')
  236
+        if prefix[0] == '1':
  237
+            number = prefix[1] + number
  238
+            prefix = prefix[0]
  239
+        if prefix not in [choice[0] for choice in HR_PHONE_NUMBER_PREFIX_CHOICES]:
  240
+            raise ValidationError(self.error_messages['area'])
  241
+
  242
+        # Make sure the number is of adequate length.
  243
+        if prefix=='1' and len(number)!=7:
  244
+            raise ValidationError(self.error_messages['number'])
  245
+
  246
+        return '%s%s%s' % ('+385',prefix,number)
  247
+
  248
+
  249
+class HRJMBAGField(Field):
  250
+    """
  251
+    Unique Master Academic Citizen Number of Croatia (JMBAG) field.
  252
+    This number is used by college students and professors in Croatia.
  253
+
  254
+    http://www.cap.srce.hr/IzgledX.aspx
  255
+    """
  256
+    default_error_messages = {
  257
+        'invalid': _('Enter a valid 19 digit JMBAG starting with 601983'),
  258
+        'copy': _('Card issue number cannot be zero'),
  259
+    }
  260
+
  261
+    def clean(self, value):
  262
+        super(HRJMBAGField, self).clean(value)
  263
+        if value in EMPTY_VALUES:
  264
+            return u''
  265
+
  266
+        value = re.sub(r'[\-\s]', '', value.strip())
  267
+
  268
+        matches = jmbag_re.search(value)
  269
+        if matches is None:
  270
+            raise ValidationError(self.error_messages['invalid'])
  271
+
  272
+        # Make sure the issue number is not zero.
  273
+        if matches.group('copy')=='0':
  274
+            raise ValidationError(self.error_messages['copy'])
  275
+
  276
+        # Validate checksum using Luhn algorithm.
  277
+        num = [int(x) for x in value]
  278
+        if not sum(num[::-2] + [sum(divmod(d * 2, 10)) for d in num[-2::-2]]) % 10 == 0:
  279
+            raise ValidationError(self.error_messages['invalid'])
  280
+
  281
+        return '%s' % (value, )
110  django/contrib/localflavor/hr/hr_choices.py
... ...
@@ -0,0 +1,110 @@
  1
+# -*- coding: utf-8 -*-
  2
+"""
  3
+Sources:
  4
+    Croatian Counties: http://en.wikipedia.org/wiki/ISO_3166-2:HR
  5
+
  6
+    Croatia doesn't have official abbreviations for counties.
  7
+    The ones provided are in common use.
  8
+"""
  9
+from django.utils.translation import ugettext_lazy as _
  10
+
  11
+HR_COUNTY_CHOICES = (
  12
+    ('GZG', _('Grad Zagreb')),
  13
+    (u'BBŽ', _(u'Bjelovarsko-bilogorska županija')),
  14
+    (u'BPŽ', _(u'Brodsko-posavska županija')),
  15
+    (u'DNŽ', _(u'Dubrovačko-neretvanska županija')),
  16
+    (u'IŽ', _(u'Istarska županija')),
  17
+    (u'KŽ', _(u'Karlovačka županija')),
  18
+    (u'KKŽ', _(u'Koprivničko-križevačka županija')),
  19
+    (u'KZŽ', _(u'Krapinsko-zagorska županija')),
  20
+    (u'LSŽ', _(u'Ličko-senjska županija')),
  21
+    (u'MŽ', _(u'Međimurska županija')),
  22
+    (u'OBŽ', _(u'Osječko-baranjska županija')),
  23
+    (u'PSŽ', _(u'Požeško-slavonska županija')),
  24
+    (u'PGŽ', _(u'Primorsko-goranska županija')),
  25
+    (u'SMŽ', _(u'Sisačko-moslavačka županija')),
  26
+    (u'SDŽ', _(u'Splitsko-dalmatinska županija')),
  27
+    (u'ŠKŽ', _(u'Šibensko-kninska županija')),
  28
+    (u'VŽ', _(u'Varaždinska županija')),
  29
+    (u'VPŽ', _(u'Virovitičko-podravska županija')),
  30
+    (u'VSŽ', _(u'Vukovarsko-srijemska županija')),
  31
+    (u'ZDŽ', _(u'Zadarska županija')),
  32
+    (u'ZGŽ', _(u'Zagrebačka županija')),
  33
+)
  34
+
  35
+"""
  36
+Sources:
  37
+http://hr.wikipedia.org/wiki/Dodatak:Popis_registracijskih_oznaka_za_cestovna_vozila_u_Hrvatskoj
  38
+
  39
+Only common license plate prefixes are provided. Special cases and obsolete prefixes are omitted.
  40
+"""
  41
+
  42
+HR_LICENSE_PLATE_PREFIX_CHOICES = (
  43
+    ('BJ', 'BJ'),
  44
+    ('BM', 'BM'),
  45
+    (u'ČK', u'ČK'),
  46
+    ('DA', 'DA'),
  47
+    ('DE', 'DE'),
  48
+    ('DJ', 'DJ'),
  49
+    ('DU', 'DU'),
  50
+    ('GS', 'GS'),
  51
+    ('IM', 'IM'),
  52
+    ('KA', 'KA'),
  53
+    ('KC', 'KC'),
  54
+    ('KR', 'KR'),
  55
+    ('KT', 'KT'),
  56
+    (u'KŽ', u'KŽ'),
  57
+    ('MA', 'MA'),
  58
+    ('NA', 'NA'),
  59
+    ('NG', 'NG'),
  60
+    ('OG', 'OG'),
  61
+    ('OS', 'OS'),
  62
+    ('PU', 'PU'),
  63
+    (u'PŽ', u'PŽ'),
  64
+    ('RI', 'RI'),
  65
+    ('SB', 'SB'),
  66
+    ('SK', 'SK'),
  67
+    ('SL', 'SL'),
  68
+    ('ST', 'ST'),
  69
+    (u'ŠI', u'ŠI'),
  70
+    ('VK', 'VK'),
  71
+    ('VT', 'VT'),
  72
+    ('VU', 'VU'),
  73
+    (u'VŽ', u'VŽ'),
  74
+    ('ZD', 'ZD'),
  75
+    ('ZG', 'ZG'),
  76
+    (u'ŽU', u'ŽU'),
  77
+)
  78
+
  79
+"""
  80
+The list includes county and cellular network phone number prefixes.
  81
+"""
  82
+
  83
+HR_PHONE_NUMBER_PREFIX_CHOICES = (
  84
+    ('1', '01'),
  85
+    ('20', '020'),
  86
+    ('21', '021'),
  87
+    ('22', '022'),
  88
+    ('23', '023'),
  89
+    ('31', '031'),
  90
+    ('32', '032'),
  91
+    ('33', '033'),
  92
+    ('34', '034'),
  93
+    ('35', '035'),
  94
+    ('40', '040'),
  95
+    ('42', '042'),
  96
+    ('43', '043'),
  97
+    ('44', '044'),
  98
+    ('47', '047'),
  99
+    ('48', '048'),
  100
+    ('49', '049'),
  101
+    ('51', '051'),
  102
+    ('52', '052'),
  103
+    ('53', '053'),
  104
+    ('91', '091'),
  105
+    ('92', '092'),
  106
+    ('95', '095'),
  107
+    ('97', '097'),
  108
+    ('98', '098'),
  109
+    ('99', '099'),
  110
+)
68  docs/ref/contrib/localflavor.txt
@@ -44,6 +44,7 @@ Countries currently supported by :mod:`~django.contrib.localflavor` are:
44 44
     * Canada_
45 45
     * Chile_
46 46
     * China_
  47
+    * Croatia_
47 48
     * Czech_
48 49
     * Finland_
49 50
     * France_
@@ -95,6 +96,7 @@ Here's an example of how to use them::
95 96
 .. _Canada: `Canada (ca)`_
96 97
 .. _Chile: `Chile (cl)`_
97 98
 .. _China: `China (cn)`_
  99
+.. _Croatia: `Croatia (hr)`_
98 100
 .. _Czech: `Czech (cz)`_
99 101
 .. _Finland: `Finland (fi)`_
100 102
 .. _France: `France (fr)`_
@@ -374,6 +376,72 @@ China (``cn``)
374 376
     Valid formats are like 1XXXXXXXXXX, where X is digit.
375 377
     The second digit could only be 3, 5 and 8.
376 378
 
  379
+Croatia (``hr``)
  380
+==============
  381
+
  382
+.. versionadded:: 1.4
  383
+
  384
+.. class:: hr.forms.HRCountySelect
  385
+
  386
+    A ``Select`` widget that uses a list of counties of Croatia as its choices.
  387
+
  388
+.. class:: hr.forms.HRPhoneNumberPrefixSelect
  389
+
  390
+    A ``Select`` widget that uses a list of phone number prefixes of Croatia as
  391
+    its choices.
  392
+
  393
+.. class:: hr.forms.HRLicensePlatePrefixSelect
  394
+
  395
+    A ``Select`` widget that uses a list of vehicle license plate prefixes of
  396
+    Croatia as its choices.
  397
+
  398
+.. class:: hr.forms.HRPhoneNumberField
  399
+
  400
+    A form field that validates input as a phone number of Croatia.
  401
+    A valid format is a country code or a leading zero, area code prefix, 6 or 7
  402
+    digit number; e.g. +385XXXXXXXX or 0XXXXXXXX
  403
+    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with
  404
+    country code (+385 prefix).
  405
+
  406
+.. class:: hr.forms.HRLicensePlateField
  407
+
  408
+    A form field that validates input as a vehicle license plate of Croatia.
  409
+    Normalizes to the specific format XX YYYY-XX where X is a letter and Y a
  410
+    digit. There can be three or four digits.
  411
+    Suffix is constructed from the shared letters of the Croatian and English
  412
+    alphabets.
  413
+    It is used for standardized license plates only. Special cases like license
  414
+    plates for oldtimers, temporary license plates, government institution
  415
+    license plates and customized license plates are not covered by this field.
  416
+
  417
+.. class:: hr.forms.HRPostalCodeField
  418
+
  419
+    A form field that validates input as a postal code of Croatia.
  420
+    It consists of exactly five digits ranging from 10000 to 59999 inclusive.
  421
+
  422
+.. class:: hr.forms.HROIBField
  423
+
  424
+    A form field that validates input as a Personal Identification Number (OIB)
  425
+    of Croatia.
  426
+    It consists of exactly eleven digits.
  427
+
  428
+.. class:: hr.forms.HRJMBGField
  429
+
  430
+    A form field that validates input as a Unique Master Citizen Number (JMBG).
  431
+    The number is still in use in Croatia, but it is being replaced by OIB.
  432
+    This field works for other ex-Yugoslavia countries as well where the JMBG is
  433
+    still in use.
  434
+    The area segment of the JMBG is not validated because the citizens might
  435
+    have emigrated to another ex-Yugoslavia country.
  436
+    The number consists of exactly thirteen digits.
  437
+
  438
+.. class:: hr.forms.HRJMBAGField
  439
+
  440
+    A form field that validates input as a Unique Master Academic Citizen Number
  441
+    (JMBAG) of Croatia.
  442
+    This number is used by college students and professors in Croatia.
  443
+    The number consists of exactly nineteen digits.
  444
+
377 445
 Czech (``cz``)
378 446
 ==============
379 447
 
0  localflavor/hr/__init__.py b/django/contrib/localflavor/hr/__init__.py
No changes.
190  tests/regressiontests/forms/localflavor/hr.py
... ...
@@ -0,0 +1,190 @@
  1
+# -*- coding: utf-8 -*-
  2
+from django.contrib.localflavor.hr.forms import (HRCountySelect,
  3
+    HRPhoneNumberPrefixSelect, HRLicensePlatePrefixSelect, HRPhoneNumberField,
  4
+    HRLicensePlateField, HRPostalCodeField, HROIBField, HRJMBGField,
  5
+    HRJMBAGField)
  6
+
  7
+from utils import LocalFlavorTestCase
  8
+
  9
+class 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)
1  tests/regressiontests/forms/localflavortests.py
@@ -13,6 +13,7 @@
13 13
 from localflavor.fi import FILocalFlavorTests
14 14
 from localflavor.fr import FRLocalFlavorTests
15 15
 from localflavor.generic import GenericLocalFlavorTests
  16
+from localflavor.hr import HRLocalFlavorTests
16 17
 from localflavor.id import IDLocalFlavorTests
17 18
 from localflavor.ie import IELocalFlavorTests
18 19
 from localflavor.il import ILLocalFlavorTests
1  tests/regressiontests/forms/tests/__init__.py
@@ -27,6 +27,7 @@
27 27
     FILocalFlavorTests,
28 28
     FRLocalFlavorTests,
29 29
     GenericLocalFlavorTests,
  30
+    HRLocalFlavorTests,
30 31
     IDLocalFlavorTests,
31 32
     IELocalFlavorTests,
32 33
     ILLocalFlavorTests,

0 notes on commit 7478aeb

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