Opened 17 years ago

Closed 16 years ago

#3961 closed (fixed)

Add South African / za localflavor

Reported by: Russell Cloran <russell@…> 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)

za-localflavor.diff (5.3 KB ) - added by Russell Cloran <russell@…> 17 years ago.
Patch to add za localflavor
ticket_3961__rev_6223.diff (4.6 KB ) - added by Ben Slavin 17 years ago.
Removed Luhn algorithm implementation, now covered separately in #5475

Download all attachments as: .zip

Change History (12)

by Russell Cloran <russell@…>, 17 years ago

Attachment: za-localflavor.diff added

Patch to add za localflavor

comment:1 by Russell Cloran <russell@…>, 17 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?

comment:2 by Malcolm Tredinnick, 17 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.

in reply to:  2 ; comment:3 by Russell Cloran <russell@…>, 17 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 Adrian Holovaty, 17 years ago

Component: Contrib appsdjango.contrib.localflavor

comment:5 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:6 by brad@…, 17 years ago

Hi, this patch doesnt seem to be in the SVN tree yet, or am I missing something?

comment:7 by James Bennett, 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.

in reply to:  3 comment:8 by keegan.csmith@…, 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 Ben Slavin, 17 years ago

Attachment: ticket_3961__rev_6223.diff added

Removed Luhn algorithm implementation, now covered separately in #5475

comment:9 by Simon G <dev@…>, 16 years ago

Patch needs improvement: unset
Summary: [patch] Add South African / za localflavorAdd South African / za localflavor
Triage Stage: AcceptedReady for checkin

comment:10 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [6843]) Fixed #3961 -- Added South African localflavor. Thanks, Russell Cloran.

Note: See TracTickets for help on using tickets.
Back to Top