Opened 8 years ago

Closed 8 years ago

#3961 closed (fixed)

Add South African / za localflavor

Reported by: Russell Cloran <russell@…> Owned by: nobody
Component: contrib.localflavor Version: master
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: UI/UX:

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@…> 8 years ago.
Patch to add za localflavor
ticket_3961__rev_6223.diff (4.6 KB) - added by __hawkeye__ 8 years ago.
Removed Luhn algorithm implementation, now covered separately in #5475

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by Russell Cloran <russell@…>

Patch to add za localflavor

comment:1 Changed 8 years ago by Russell Cloran <russell@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Summary changed from Add South African / za localflavor to [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 follow-up: Changed 8 years ago by mtredinnick

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.

comment:3 in reply to: ↑ 2 ; follow-up: Changed 8 years ago by Russell Cloran <russell@…>

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 Changed 8 years ago by adrian

  • Component changed from Contrib apps to django.contrib.localflavor

comment:5 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:6 Changed 8 years ago by brad@…

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

comment:7 Changed 8 years ago by ubernostrum

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 in reply to: ↑ 3 Changed 8 years ago by keegan.csmith@…

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?

Changed 8 years ago by __hawkeye__

Removed Luhn algorithm implementation, now covered separately in #5475

comment:9 Changed 8 years ago by Simon G <dev@…>

  • Patch needs improvement unset
  • Summary changed from [patch] Add South African / za localflavor to Add South African / za localflavor
  • Triage Stage changed from Accepted to Ready for checkin

comment:10 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

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