ó
ø¢TQc           @@ sØ  d  Z  d d l m Z m Z d d l Z d d l Z d d l m Z m Z m	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z d d l m Z d d	 l m Z e j d
 d ƒ Z e j d ƒ Z e j d d ƒ Z e j d ƒ Z e j d ƒ Z e j d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d  e f d! „  ƒ  YZ% d" e f d# „  ƒ  YZ& d S($   u   
HR-specific Form helpers
i    (   t   absolute_importt   unicode_literalsN(   t   HR_LICENSE_PLATE_PREFIX_CHOICESt   HR_COUNTY_CHOICESt   HR_PHONE_NUMBER_PREFIX_CHOICES(   t   EMPTY_VALUES(   t   ValidationError(   t   Fieldt   Selectt
   RegexField(   t
   smart_text(   t   ugettext_lazyu)   ^(?P<dd>\d{2})(?P<mm>\d{2})(?P<yyy>\d{3})u(   (?P<rr>\d{2})(?P<bbb>\d{3})(?P<k>\d{1})$u   ^\d{11}$u   ^(?P<prefix>[A-ZÄŒÅ Å½]{2})u=   (?P<number>\d{3,4})(?P<suffix>[ABCDEFGHIJKLMNOPRSTUVZ]{1,2})$u   ^\d{5}$u5   ^(\+385|00385|0)(?P<prefix>\d{2})(?P<number>\d{6,7})$u5   ^601983(?P<copy>\d{1})1(?P<jmbag>\d{10})(?P<k>\d{1})$t   HRCountySelectc           B@ s   e  Z d  Z d d „ Z RS(   uQ   
    A Select widget that uses a list of counties of Croatia as its choices.
    c         C@ s    t  t |  ƒ j | d t ƒd  S(   Nt   choices(   t   superR   t   __init__R   (   t   selft   attrs(    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   #   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR      s   t   HRLicensePlatePrefixSelectc           B@ s   e  Z d  Z d d „ Z RS(   uk   
    A Select widget that uses a list of vehicle license plate prefixes of
    Croatia as its choices.
    c         C@ s    t  t |  ƒ j | d t ƒd  S(   NR   (   R   R   R   R   (   R   R   (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   -   s    N(   R   R   R   R   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   '   s   t   HRPhoneNumberPrefixSelectc           B@ s   e  Z d  Z d d „ Z RS(   ub   
    A Select widget that uses a list of phone number prefixes of Croatia as its
    choices.
    c         C@ s    t  t |  ƒ j | d t ƒd  S(   NR   (   R   R   R   R   (   R   R   (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   8   s    N(   R   R   R   R   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   2   s   t   HRJMBGFieldc           B@ s7   e  Z d  Z i e d ƒ d 6e d ƒ d 6Z d „  Z RS(   u$  
    Unique Master Citizen Number (JMBG) field.
    The number is still in use in Croatia, but it is being replaced by OIB.

    Source: http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number

    For who might be reimplementing:
    The "area" regular expression group is used to calculate the region where a
    person was registered. Additional validation can be implemented in
    accordance with it, however this could result in exclusion of legit
    immigrated citizens. Therefore, this field works for any ex-Yugoslavia
    country.
    u   Enter a valid 13 digit JMBGu   invalidu   Error in date segmentu   datec         C@ sâ  t  t |  ƒ j | ƒ | t k r& d S| j ƒ  } t j | ƒ } | d  k rc t |  j	 d ƒ ‚ n  t
 | j d ƒ ƒ } t
 | j d ƒ ƒ } t
 | j d ƒ ƒ } y t j | | | ƒ Wn$ t k
 rß t |  j	 d ƒ ‚ n X| j d ƒ } d } xY t t d	 d
 d ƒ t d ƒ ƒ D]6 \ } }	 | | t
 | |	 ƒ t
 | d | ƒ 7} qWd | d }
 |
 d k rt |  j	 d ƒ ‚ n  |
 d k r¯| d k r¯t |  j	 d ƒ ‚ n  t |
 ƒ | k s×t |  j	 d ƒ ‚ n  d | f S(   Nu    u   invalidu   ddu   mmu   yyyu   dateu   ki    i   i   iÿÿÿÿi   i   i   i
   u   0u   %s(   R   R   t   cleanR   t   stript   jmbg_ret   searchR   R   t   error_messagest   intt   groupt   datetimet   datet
   ValueErrort   zipt   ranget   str(   R   t   valuet   matchest   ddt   mmt   yyyt   kt   checksumt   it   jt   m(    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   P   s4    ..(   R   R   R   t   _t   default_error_messagesR   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   =   s
   t
   HROIBFieldc           B@ s9   e  Z d  Z i e d ƒ d 6Z d d d „ Z d „  Z RS(   uX   
    Personal Identification Number of Croatia (OIB) field.

    http://www.oib.hr/
    u   Enter a valid 11 digit OIBu   invalidi   c         O@ s&   t  t |  ƒ j d | | | | Ž d  S(   Nu   ^\d{11}$(   R   R2   R   (   R   t
   min_lengtht
   max_lengtht   argst   kwargs(    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   ~   s    c         C@ s1   t  t |  ƒ j | ƒ | t k r& d Sd | f S(   Nu    u   %s(   R   R2   R   R   (   R   R&   (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   ‚   s    (   R   R   R   R0   R1   R   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR2   t   s
   t   HRLicensePlateFieldc           B@ sD   e  Z d  Z i e d ƒ d 6e d ƒ d 6e d ƒ d 6Z d „  Z RS(   uM  
    Vehicle license plate of Croatia field. Normalizes to the specific format
    below. Suffix is constructed from the shared letters of the Croatian and
    English alphabets.

    Format examples:
        SB 123-A
        (but also supports more characters)
        ZG 1234-AA

    Used for standardized license plates only.
    u*   Enter a valid vehicle license plate numberu   invalidu   Enter a valid location codeu   areau   Number part cannot be zerou   numberc         C@ s  t  t |  ƒ j | ƒ | t k r& d St j d d t | j ƒ  ƒ ƒ j ƒ  } t	 j
 | ƒ } | d  k r~ t |  j d ƒ ‚ n  | j d ƒ } | g  t D] } | d ^ q— k rÆ t |  j d ƒ ‚ n  | j d ƒ } t | ƒ d k rý t |  j d ƒ ‚ n  d | | | j d	 ƒ f S(
   Nu    u   [\s\-]+u   invalidu   prefixi    u   areau   numberu   %s %s-%su   suffix(   R   R7   R   R   t   ret   subR
   R   t   uppert   plate_reR   R   R   R   R   R   R   (   R   R&   R'   t   prefixt   choicet   number(    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR      s    '#(   R   R   R   R0   R1   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR7   Š   s   t   HRPostalCodeFieldc           B@ s*   e  Z d  Z i e d ƒ d 6Z d „  Z RS(   u«   
    Postal code of Croatia field.
    It consists of exactly five digits ranging from 10000 to possibly less than
    60000.

    http://www.posta.hr/main.aspx?id=66
    u!   Enter a valid 5 digit postal codeu   invalidc         C@ sš   t  t |  ƒ j | ƒ | t k r& d S| j ƒ  } t j | ƒ sW t |  j d ƒ ‚ n  d t	 | ƒ k  ot d k  n s t |  j d ƒ ‚ n  d | f S(   Nu    u   invalidi'  i`ê  u   %s(
   R   R?   R   R   R   t   postal_code_reR   R   R   R   (   R   R&   (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   Á   s    "(   R   R   R   R0   R1   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR?   µ   s   t   HRPhoneNumberFieldc           B@ sD   e  Z d  Z i e d ƒ d 6e d ƒ d 6e d ƒ d 6Z d „  Z RS(   uõ   
    Phone number of Croatia field.
    Format: Complete country code or leading zero, area code prefix, 6 or 7
    digit number.
    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with
    country code (+385 prefix).
    u   Enter a valid phone numberu   invalidu)   Enter a valid area or mobile network codeu   areau   The phone nubmer is too longu   numberc         C@ s9  t  t |  ƒ j | ƒ | t k r& d St j d d t | ƒ ƒ } t j | ƒ } | d  k rr t
 |  j d ƒ ‚ n  | j d ƒ } | j d ƒ } | d d k r» | d | } | d } n  | g  t D] } | d ^ qÅ k rô t
 |  j d	 ƒ ‚ n  | d k r(t | ƒ d
 k r(t
 |  j d ƒ ‚ n  d d | | f S(   Nu    u
   [\-\s\(\)]u   invalidu   prefixu   numberi    u   1i   u   areai   u   %s%s%su   +385(   R   RA   R   R   R8   R9   R
   t   phone_reR   R   R   R   R   R   t   len(   R   R&   R'   R<   R>   R=   (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR   ß   s"    #(   R   R   R   R0   R1   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyRA   Ñ   s   t   HRJMBAGFieldc           B@ s7   e  Z d  Z i e d ƒ d 6e d ƒ d 6Z d „  Z RS(   u¹   
    Unique Master Academic Citizen Number of Croatia (JMBAG) field.
    This number is used by college students and professors in Croatia.

    http://www.cap.srce.hr/IzgledX.aspx
    u1   Enter a valid 19 digit JMBAG starting with 601983u   invalidu    Card issue number cannot be zerou   copyc         C@ s7  t  t |  ƒ j | ƒ | t k r& d St j d d | j ƒ  ƒ } t j | ƒ } | d  k rr t
 |  j d ƒ ‚ n  | j d ƒ d k r t
 |  j d ƒ ‚ n  g  | D] } t | ƒ ^ q¤ } t | d  d  d … g  | d d  d … D] } t t | d d ƒ ƒ ^ qã ƒ d d	 k s,t
 |  j d ƒ ‚ n  d
 | f S(   Nu    u   [\-\s]u   invalidu   copyu   0iþÿÿÿi   i
   i    u   %s(   R   RD   R   R   R8   R9   R   t   jmbag_reR   R   R   R   R   R   t   sumt   divmod(   R   R&   R'   t   xt   numt   d(    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyR     s    Z(   R   R   R   R0   R1   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyRD   ú   s
   ('   R   t
   __future__R    R   R    R8   t(   django.contrib.localflavor.hr.hr_choicesR   R   R   t   django.core.validatorsR   t   django.formsR   t   django.forms.fieldsR   R   R	   t   django.utils.encodingR
   t   django.utils.translationR   R0   t   compileR   t   oib_reR;   R@   RB   RE   R   R   R   R   R2   R7   R?   RA   RD   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/hr/forms.pyt   <module>   s4   	
	
	7+)