ó
ø¢TQc           @@ sÖ   d  Z  d d l m Z m Z d d l Z d d l Z d d l 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	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   u!   
Norwegian-specific Form helpers
i    (   t   absolute_importt   unicode_literalsN(   t   MUNICIPALITY_CHOICES(   t   EMPTY_VALUES(   t   ValidationError(   t   Fieldt
   RegexFieldt   Select(   t   ugettext_lazyt   NOZipCodeFieldc           B@ s*   e  Z i e d  ƒ d 6Z d d d „ Z RS(   u$   Enter a zip code in the format XXXX.u   invalidc         O@ s&   t  t |  ƒ j d | | | | Ž d  S(   Nu   ^\d{4}$(   t   superR	   t   __init__(   t   selft
   max_lengtht
   min_lengtht   argst   kwargs(    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR      s    N(   t   __name__t
   __module__t   _t   default_error_messagest   NoneR   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR	      s   t   NOMunicipalitySelectc           B@ s   e  Z d  Z d d „ Z RS(   uc   
    A Select widget that uses a list of Norwegian municipalities (fylker)
    as its choices.
    c         C@ s    t  t |  ƒ j | d t ƒd  S(   Nt   choices(   R
   R   R   R   (   R   t   attrs(    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR      s    N(   R   R   t   __doc__R   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR      s   t   NOSocialSecurityNumberc           B@ s*   e  Z d  Z i e d ƒ d 6Z d „  Z RS(   uN   
    Algorithm is documented at http://no.wikipedia.org/wiki/Personnummer
    u/   Enter a valid Norwegian social security number.u   invalidc         C@ sÞ  t  t |  ƒ j | ƒ | t k r& d St j d | ƒ sN t |  j d ƒ ‚ n  t | d  ƒ } t | d d !ƒ } t | d d !ƒ } t | d d !ƒ } d  |  _
 yd | k oº d	 k  n rÞ t j d
 | | | ƒ |  _
 n  d	 | k oõ d k  n r%| d k r%t j d | | | ƒ |  _
 n  d	 | k o<d k  n rl| d k  rlt j d | | | ƒ |  _
 n  d | k oƒd k  n r³| d k r³t j d
 | | | ƒ |  _
 n  Wn$ t k
 rÚt |  j d ƒ ‚ n Xt | d ƒ } | d d k rd |  _ n	 d |  _ t t t | ƒ ƒ } d d d d d d d d d d d g } d d d d d d d d d d d g }	 d „  }
 |
 | | ƒ d d k r«t |  j d ƒ ‚ n  |
 | |	 ƒ d d k rÚt |  j d ƒ ‚ n  | S(   Nu    u   ^\d{11}$u   invalidi   i   i   i	   i    iô  il  iî  i6   i  iè  i(   iÐ  i„  i'   i   u   Fu   Mi   i   i   i   c         S@ s0   t  g  t |  | ƒ D] \ } } | | ^ q ƒ S(   N(   t   sumt   zip(   t   avalt   bvalt   at   b(    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyt   multiply_reduceN   s    i   (   R
   R   t   cleanR   t   ret   matchR   t   error_messagest   intR   t   birthdayt   datetimet   datet
   ValueErrort   gendert   mapt   list(   R   t   valuet   dayt   montht   year2t   inumt   sexnumt   digitst   weight_1t   weight_2R!   (    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR"   *   sD    	(((#	''	(   R   R   R   R   R   R"   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyR   "   s   (   R   t
   __future__R    R   R#   R(   t/   django.contrib.localflavor.no.no_municipalitiesR   t   django.core.validatorsR   t   django.formsR   t   django.forms.fieldsR   R   R   t   django.utils.translationR   R   R	   R   R   (    (    (    s<   ../Django//lib/python/django/contrib/localflavor/no/forms.pyt   <module>   s   	