Opened 18 years ago
Closed 17 years ago
#3961 closed (fixed)
Add South African / za localflavor
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.localflavor | Version: | dev |
Severity: | Keywords: | localflavor, za | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The attached patch adds support for South African ID numbers and postal codes.
The patch also creates django.utils.checksums
(with only a luhn function for now), as suggested by Malcolm Tredinnick on django-developers
Attachments (2)
Change History (12)
by , 18 years ago
Attachment: | za-localflavor.diff added |
---|
comment:1 by , 18 years ago
Patch needs improvement: | set |
---|---|
Summary: | Add South African / za localflavor → [patch] Add South African / za localflavor |
I forgot to mention in the original submission ... the Luhn function currently returns False when it gets an input that isn't a string of digits (or an integer) -- it should perhaps raise a ValueError instead?
follow-up: 3 comment:2 by , 18 years ago
Yeah, I think the checksum function should raise an error on bad input, rather than pretending to work.
However, could you give the whole checksum function another swing? At the moment, you are converting integers to strings just so you can later convert them back to integers. How about letting integers be integers (and be careful because isintance(True, int) = True in Python, unfortunately) and converting string digits to digits. You could just do long(input_string) and anything that raises a value error is going to be wrong, for example. Check the input for leading zeros (assume leading zeros if it's too short).
I realise this sounds a bit non-specific, but I just get the feeling you're doing this in a slightly awkward fashion.
follow-up: 8 comment:3 by , 18 years ago
The function was initially created to accept string input -- I think this is probably the most common use case, since you're likely to store things like credit card numbers as a CharField in your database. The acceptance of integer types was tacked on, and yes, sits a bit uneasy with me too.
I'm not quite sure I get what you're saying -- should the function accept only integer input? In which case, there is going to be a long() outside the function for most use cases, and instead of a simple generator, the function needs to do %10, /10 work.
comment:4 by , 18 years ago
Component: | Contrib apps → django.contrib.localflavor |
---|
comment:5 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:6 by , 17 years ago
Hi, this patch doesnt seem to be in the SVN tree yet, or am I missing something?
comment:7 by , 17 years ago
You'll want to see here for an explanation of what the ticket stages mean. "Accepted" does not mean "patch has been committed" -- that's what "fixed" is for.
comment:8 by , 17 years ago
Replying to Russell Cloran <russell@rucus.net>:
In the checksum function surely this would suffice for the check:
s = str(s) if not s.isdigit(): raise ValueError, "'%s' needs to be a string of digits" % s
I don't see the need to check what type s is, rather just convert it to a string. Or is this against some django conventions?
by , 17 years ago
Attachment: | ticket_3961__rev_6223.diff added |
---|
Removed Luhn algorithm implementation, now covered separately in #5475
comment:9 by , 17 years ago
Patch needs improvement: | unset |
---|---|
Summary: | [patch] Add South African / za localflavor → Add South African / za localflavor |
Triage Stage: | Accepted → Ready for checkin |
comment:10 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch to add za localflavor