Skip to content

Instantly share code, notes, and snippets.

@codeadict
Created June 24, 2013 13:55
Show Gist options
  • Save codeadict/5850228 to your computer and use it in GitHub Desktop.
Save codeadict/5850228 to your computer and use it in GitHub Desktop.
Validar cedula Ecuatoriana en un form de DJANGO
def clean_cedula(self):
"""
Valída que sea Correcta la Cédula
"""
ced = self.cleaned_data['cedula']
msg = "La Cédula introducida no es válida"
valores = [ int(ced[x]) * (2 - x % 2) for x in range(9) ]
suma = sum(map(lambda x: x > 9 and x - 9 or x, valores))
veri = 10 - (suma - (10 * (suma / 10)))
if int(ced[9]) == int(str(veri)[-1:]):
return ced
else:
raise forms.ValidationError(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment