<s> """<STR_LIT>""" <EOL> from django . forms import ValidationError <EOL> from django . forms . fields import Select , RegexField , Field , EMPTY_VALUES <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> import re <EOL> birth_number = re . compile ( r'<STR_LIT>' ) <EOL> ic_number = re . compile ( r'<STR_LIT>' ) <EOL> class CZRegionSelect ( Select ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> from cz_regions import REGION_CHOICES <EOL> super ( CZRegionSelect , self ) . __init__ ( attrs , choices = REGION_CHOICES ) <EOL> class CZPostalCodeField ( RegexField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CZPostalCodeField , self ) . __init__ ( r'<STR_LIT>' , <EOL> max_length = None , min_length = None , * args , ** kwargs ) <EOL> def clean ( self , value ) : <EOL> """<STR_LIT>""" <EOL> v = super ( CZPostalCodeField , self ) . clean ( value ) <EOL> return v . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> class CZBirthNumberField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value , gender = None ) : <EOL> super ( CZBirthNumberField , self ) . __init__ ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return u'<STR_LIT>' <EOL> match = re . match ( birth_number , value ) <EOL> if not match : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> birth , id = match . groupdict ( ) [ '<STR_LIT>' ] , match . groupdict ( ) [ '<STR_LIT:id>' ] <EOL> if len ( id ) == <NUM_LIT:3> : <EOL> return u'<STR_LIT:%s>' % value <EOL> if gender is not None : <EOL> if gender == '<STR_LIT:f>' : <EOL> female_const = <NUM_LIT:50> <EOL> elif gender == '<STR_LIT:m>' : <EOL> female_const = <NUM_LIT:0> <EOL> else : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> month = int ( birth [ <NUM_LIT:2> : <NUM_LIT:4> ] ) - female_const <EOL> if ( not <NUM_LIT:1> <= month <= <NUM_LIT:12> ) : <EOL> if ( not <NUM_LIT:1> <= ( month - <NUM_LIT:20> ) <= <NUM_LIT:12> ) : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> day = int ( birth [ <NUM_LIT:4> : <NUM_LIT:6> ] ) <EOL> if not ( <NUM_LIT:1> <= day <= <NUM_LIT> ) : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> modulo = int ( birth + id [ : <NUM_LIT:3> ] ) % <NUM_LIT:11> <EOL> if ( modulo == int ( id [ - <NUM_LIT:1> ] ) ) or ( modulo == <NUM_LIT:10> and id [ - <NUM_LIT:1> ] == '<STR_LIT:0>' ) : <EOL> return u'<STR_LIT:%s>' % value <EOL> else : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> class CZICNumberField ( Field ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( u'<STR_LIT>' ) , <EOL> } <EOL> def clean ( self , value ) : <EOL> super ( CZICNumberField , self ) . __init__ ( value ) <EOL> if value in EMPTY_VALUES : <EOL> return u'<STR_LIT>' <EOL> match = re . match ( ic_number , value ) <EOL> if not match : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> number , check = match . groupdict ( ) [ '<STR_LIT>' ] , int ( match . groupdict ( ) [ '<STR_LIT>' ] ) <EOL> sum = <NUM_LIT:0> <EOL> weight = <NUM_LIT:8> <EOL> for digit in number : <EOL> sum += int ( digit ) * weight <EOL> weight -= <NUM_LIT:1> <EOL> remainder = sum % <NUM_LIT:11> <EOL> if ( not remainder % <NUM_LIT:10> and check == <NUM_LIT:1> ) or ( remainder == <NUM_LIT:1> and check == <NUM_LIT:0> ) or ( check == ( <NUM_LIT:11> - remainder ) ) : <EOL> return u'<STR_LIT:%s>' % value <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) </s>
