Skip to content

Instantly share code, notes, and snippets.

@marlncpe
Forked from codeadict/Valida Cedula
Last active August 29, 2015 14:13
Show Gist options
  • Save marlncpe/bd29d3851635bd99e1b8 to your computer and use it in GitHub Desktop.
Save marlncpe/bd29d3851635bd99e1b8 to your computer and use it in GitHub Desktop.
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