Django

Code

Ticket #5446 (reopened)

Opened 10 months ago

Last modified 4 months ago

New model fields for languages and countries at least

Reported by: Raphaël Hertzog <raphael@ouaza.com> Assigned to: marinho
Milestone: Component: Database wrapper
Version: SVN Keywords: feature_request
Cc: chris@moffitts.net, semente@taurinus.org Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I think that many applications have to deal either with language specific content and/or countries. It would be nice if Django provided ready to use fields for languages and countries instead of asking every user to handle the list and its full translation by himself (it could be a contrib package though). IMO this is best done by creating some glue on one of the available open-source reference lists. At Debian, we use a package called iso-codes that is very well-translated and kept up-to-date as it's used by our installer.

http://svn.debian.org/wsvn/pkg-isocodes/trunk/iso-codes/?rev=0&sc=0

I can also mention the django-countries project created by Chris Moffitt (who created Satchmo, a Django-powered e-commerce framework). Its extent is somewhat more limited but it's already developed specifically for Django.

http://code.google.com/p/django-countries/

And then, of course, there's Babel: http://babel.edgewall.org

The idea is to have something like:

country = models.CountryField()
language = models.LanguageField()

Instead of:

COUNTRIES = (
    ('fr', _('France')),
    ('de', _('Germany')),
    ...
)
country = models.CharField(max_length=10, choices=COUNTRIES)

which requires redoing the translation work and which is tedious to manually maintain.

Attachments

country_and_language_fields.diff (11.7 kB) - added by marinho on 12/01/07 11:01:12.
fixed
country_and_language_fields_maxlength.diff (12.8 kB) - added by Martin Conte Mac Donell <Reflejo@gmail.com> on 12/12/07 14:57:28.
Just changed maxlength (deprecated) to max_length
country_and_language_fields_maxlength_2.diff (11.7 kB) - added by Martin Conte Mac Donell <Reflejo@gmail.com> on 12/12/07 14:59:31.
Just changed maxlength (deprecated) to max_length (Sorry about the last patch, it was merged with other one, please delete it.)
country_codes.py (9.7 kB) - added by lcordier on 12/19/07 07:02:54.
Example program to maintain & sort counties.
country_and_language_fields_trunk.patch (11.7 kB) - added by Martín Conte Mac Donell <Reflejo@gmail.com> on 04/05/08 12:43:44.
Patch against trunk
country_and_language_fields_trunk.2.patch (11.8 kB) - added by Martín Conte Mac Donell <Reflejo@gmail.com> on 04/05/08 13:01:27.
This ticket is cursed. There is the patch against trunk

Change History

09/14/07 03:25:00 changed by mtredinnick

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Generally a good idea. The only requirement is that the list has to be something we can ship in Django. The standard Django installation should have essentially no external dependencies, apart from the db wrapper.

Definitely agree about the idea of creating a list for this.

09/14/07 11:06:16 changed by chris@moffitts.net

I think it would be possible to include the Satchmo models and intial_data.xml as something like django.contrib.iso_codes

All of the info is BSD licensed through Satchmo so I have no issue including in Django.

You can see the models here- http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/l10n/models.py

It uses the initial_data from here- http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/l10n/fixtures

Let me know if you'd be interested in using this.

Also, just for the record, I did not create django-countries ;)

09/15/07 14:47:10 changed by PhiR

  • keywords set to feature_request.

09/21/07 19:48:48 changed by mir

  • component changed from Database wrapper to Contrib apps.
  • stage changed from Unreviewed to Accepted.

The positive reaction of Malcolm looks like it should be Accepted (though the solution isn't clear).

Raphaël or Chris: Can you please bring this up on the developer list? It would be nice to introduce this to more people and see what they think.

09/22/07 12:18:20 changed by chris.moffitt@gmail.com

11/04/07 12:35:28 changed by zeke

Django-countries is based in another project, WebDa. And looks that Chris Moffitt was not accomplishing with the license of its author. And it's very possible than django-countries is being a derivated work of WebDa (but it isn't beind credited), because the definition of AREAS is exactly equal than the one original.

I'll try to contact with its original author.

11/04/07 20:47:05 changed by chris.moffitt@gmail.com

Originally satchmo was using Webda. There were some licensing concerns about the data but not the models. The current satchmo implementation is fully BSD licensed. As I mentioned on the developer thread, I'm willing to help someone get this into Django but I don't have the bandwidth to spin this off into another project.

12/01/07 07:58:58 changed by marinho

I wrote the following snippets who does exactly what you want.

http://www.djangosnippets.org/snippets/493/ http://www.djangosnippets.org/snippets/494/

Can I wrote these as patch fix for this task?

12/01/07 08:21:40 changed by marinho

  • owner changed from nobody to marinho.
  • status changed from new to assigned.

12/01/07 10:29:52 changed by marinho

  • status changed from assigned to closed.
  • resolution set to fixed.
  • has_patch set to 1.
  • component changed from Contrib apps to Database wrapper.

Fixings. I did it at db wrapper componente because was I understood of following Malcolm's sentence:

"The standard Django installation should have essentially no external dependencies, apart from the db wrapper."

12/01/07 10:36:27 changed by jacob

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

12/01/07 10:41:29 changed by jacob

I really don't like sticking all the countries in global settings; that's the wrong place for it. I think that the right place would be in django.contrib.localflavor.generic. Otherwise, though, a very good patch.

12/01/07 11:01:12 changed by marinho

  • attachment country_and_language_fields.diff added.

fixed

12/02/07 18:02:58 changed by marinho

Patch updated with validators and COUNTRIES settings moved to localflavor.generic package.

12/12/07 14:57:28 changed by Martin Conte Mac Donell <Reflejo@gmail.com>

  • attachment country_and_language_fields_maxlength.diff added.

Just changed maxlength (deprecated) to max_length

12/12/07 14:59:31 changed by Martin Conte Mac Donell <Reflejo@gmail.com>

  • attachment country_and_language_fields_maxlength_2.diff added.

Just changed maxlength (deprecated) to max_length (Sorry about the last patch, it was merged with other one, please delete it.)

12/19/07 05:55:59 changed by lcordier

The source of the country_codes, http://xml.coverpages.org/country3166.html, is a bit outdated,

  • Yugoslavia and Zaire should be removed
  • Ivory Coast should be renamed to Côte d'Ivoire (some ascii codec have problems with the ô) so use Cote d'Ivoire instead.
  • Add ('CD', _('Democratic Republic of the Congo')),.

I would also suggest that the country list be sorted alphabetically by the country name as to appear more sensible in the select box (widget).

http://www.iso.org/iso/iso3166_en_code_lists.txt, http://en.wikipedia.org/wiki/ISO_3166-1

12/19/07 07:02:54 changed by lcordier

  • attachment country_codes.py added.

Example program to maintain & sort counties.

04/02/08 17:27:39 changed by Guilherme M. Gondim <semente@taurinus.org>

  • cc changed from chris@moffitts.net to chris@moffitts.net, semente@taurinus.org.

04/05/08 12:43:44 changed by Martín Conte Mac Donell <Reflejo@gmail.com>

  • attachment country_and_language_fields_trunk.patch added.

Patch against trunk

04/05/08 13:01:27 changed by Martín Conte Mac Donell <Reflejo@gmail.com>

  • attachment country_and_language_fields_trunk.2.patch added.

This ticket is cursed. There is the patch against trunk


Add/Change #5446 (New model fields for languages and countries at least)




Change Properties
Action