#16202: Localflavor support for Slovenia (si)
-------------------------------------+-------------------------------------
               Reporter:  Jure       |          Owner:  nobody
  Cuhalev <gandalf@…>                |         Status:  new
                   Type:  New        |      Component:  contrib.localflavor
  feature                            |       Severity:  Normal
              Milestone:             |       Keywords:
                Version:  1.3        |      Has patch:  1
             Resolution:             |    Needs tests:  0
           Triage Stage:  Accepted   |  Easy pickings:  0
    Needs documentation:  0          |
Patch needs improvement:  0          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------

Comment (by vasiliyeah):

 This work looks good.

 I would just comment on the SIEMSOField as it's often a cause for problems
 in practice. I gather this is a unique master citizen number. This was
 introduced around 1977, and is applied to citizens  born since then or
 alive at the time. The implementation here assumes the year part 7xx
 translates to 17xx instead of 27xx, which I'm not too sure is the correct
 way to treat it. Also it's not checking if the date part of the UMCN is in
 the past which should be part of the validation IMO, because an imaginary
 UMCN that passes a checksum but has a date part in the future doesn't make
 sense.

 I'd also want to caution the authors to lookup current laws regarding
 UMCNs given to people with a temporary residence in Slovenia and test this
 implementation with some real examples if they can.

 Technically, when throwing ValidationErrors it would be better to throw
 more specific errors to notify the user which part of the field didn't
 pass validation.
 For a reference this UMCNField implementation is taken from the Macedonian
 localflavor:


 {{{#!python
 class UMCNField(RegexField):
     """
     A form field that validates input as a unique master citizen
     number.

     The format of the unique master citizen number has been kept the same
 from
     Yugoslavia. It is still in use in other countries as well, it is not
 applicable
     solely in Macedonia. For more information see:
 https://secure.wikimedia.org/wikipedia/en/wiki/Unique_Master_Citizen_Number

     A value will pass validation if it complies to the following rules:

     * Consists of exactly 13 digits
     * The first 7 digits represent a valid past date in the format DDMMYYY
     * The last digit of the UMCN passes a checksum test
     """
     default_error_messages = {
         'invalid': _(u'This field should contain exactly 13 digits.'),
         'date': _(u'The first 7 digits of the UMCN must represent a valid
 past date.'),
         'checksum': _(u'The UMCN is not valid.'),
     }

     def __init__(self, *args, **kwargs):
         kwargs['min_length'] = None
         kwargs['max_length'] = 13
         super(UMCNField, self).__init__(r'^\d{13}$', *args, **kwargs)

     def clean(self, value):
         value = super(UMCNField, self).clean(value)

         if value in EMPTY_VALUES:
             return u''

         if not self._validate_date_part(value):
             raise ValidationError(self.error_messages['date'])
         if self._validate_checksum(value):
             return value
         else:
             raise ValidationError(self.error_messages['checksum'])

     def _validate_checksum(self, value):
         a,b,c,d,e,f,g,h,i,j,k,l,K = [int(digit) for digit in  value]
         m = 11 - (( 7*(a+g) + 6*(b+h) + 5*(c+i) + 4*(d+j) + 3*(e+k) +
 2*(f+l)) % 11)
         if (m >= 1 and m <= 9) and K == m:
             return True
         elif m == 11 and K == 0:
             return True
         else:
             return False

     def _validate_date_part(self, value):
         daypart, monthpart, yearpart = int(value[:2]), int(value[2:4]),
 int(value[4:7])
         if yearpart >= 800:
             yearpart += 1000
         else:
             yearpart += 2000
         try:
             date = datetime.datetime(year = yearpart, month = monthpart,
 day = daypart).date()
         except ValueError:
             return False
         if date >= datetime.datetime.now().date():
             return False
         return True
 }}}


 Regarding taking the birth date and gender from the entered value. In
 practice we have found that the best way to use this feature of the UMCN
 is to calculate the values with JavaScript and offer them as a choice but
 still allow users to change them. This is because there have been cases
 where a person has been given a UMCN with a wrong gender or birth date
 indication at birth. Another solution I would propose is to have a model
 field which populates other two fields on the model object for gender and
 birth date in a similar fashion as the ImageField populates fields for
 height and width. IMO this is better as it's a technique used in the core
 of Django.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16202#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to