Django

Code

Ticket #5475 (closed: fixed)

Opened 10 months ago

Last modified 9 months ago

[patch] Luhn algorithm implementation should be added to Django

Reported by: __hawkeye__ Assigned to: __hawkeye__
Milestone: Component: Internationalization
Version: SVN Keywords: sprintsept14
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The Luhn algorithm is used for validating credit cards and numerous national ID numbers. Django should have a built-in implementation to enable localflavors to add functionality.

Factored out of #3961 to separate additions. Slight implementation details have been changed.

Re: discussion there, the Luhn algorithm works from right to left, so strings are used for processing. Quick (non-scientific) benchmarking shows this string-based method to be faster than other Python implementations available online.

Note: filed under 'internationalization', but arguments could be made for other categorizations.

Attachments

ticket_5475__revision_6218.diff (2.4 kB) - added by __hawkeye__ on 09/14/07 16:36:48.
Added django.utils.checksums, which contains an implementation of the Luhn algorithm. Tests included.

Change History

09/14/07 16:36:48 changed by __hawkeye__

  • attachment ticket_5475__revision_6218.diff added.

Added django.utils.checksums, which contains an implementation of the Luhn algorithm. Tests included.

09/14/07 16:38:13 changed by __hawkeye__

  • status changed from new to assigned.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

Accepting based on status of #3961.

09/14/07 16:54:35 changed by adrian

  • status changed from assigned to closed.
  • resolution set to wontfix.

This belongs in something like Satchmo -- not in Django itself.

09/14/07 17:30:44 changed by russell@rucus.net

Adrian, how do you propose we implement validation for identity numbers (akin to social security numbers) in za localflavour?

09/14/07 21:54:39 changed by __hawkeye__

  • status changed from closed to reopened.
  • resolution deleted.

Adrian, I appreciate your rejection of this based on the credit card aspect, but as Russell mentions, you neglect to consider the other applications.

Both Canada and South Africa use the Luhn algorithm for their national identification numbers. I'm fairly certain that other countries do as well. If the US localflavor gets a USSocialSecurityNumberField, I think it's fair to provide this functionality.

I'm reopening because:

  1. This implementation was suggested by Malcolm (not trying to drag him into a debate here).
  2. I don't think you understood the reason for the patch before closing it.
  3. #3961 (za localflavor) depends on this patch.

I won't reopen again if you still feel it should be closed, but I want to make sure appropriate attention is given.

09/14/07 23:20:42 changed by adrian

Ah, good point -- I was wrong in closing this. My apologies!

09/15/07 11:05:31 changed by Fredrik Lundh <fredrik@pythonware.com>

  • stage changed from Accepted to Ready for checkin.

For the record, this is used for lots of stuff in Sweden, including "person numbers" (SSN), postgiro/bankgiro codes, OCR payment codes, etc.

(But I have to admit that I've never heard it called "Luhn" before -- the formal name here is "the modulus-10 method with weights 1 and 2". You'll learn something every day ;-)

Anyway, check it in already!

10/20/07 08:40:20 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [6569]) Fixed #5475 -- Added the Luhn check algorithm to django.utils.checksums so that localflavors don't have to reimplement it each time. Thanks, hawkeye.


Add/Change #5475 ([patch] Luhn algorithm implementation should be added to Django)




Change Properties
Action