Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix localflavor deprecation warning in django 1.5?

I've migrated an existing django 1.3 to django 1.5. everything seems ok. However, I have a deprecation warning due to localflavor when i lauch python manage.py runserver

...\env\lib\site-packages\django\contrib\loca lflavor__init__.py:2: DeprecationWarning: django.contrib.localflavor is deprecated. Use the separate django-localflavor-* packages instead.
warnings.warn("django.contrib.localflavor is deprecated. Use the separate djan go-localflavor-* packages instead.", DeprecationWarning)

I've read the django 1.5 release note and I understand that this app is now deprecated. My problem is that I don't use the localflavor app in my project.

I imagine that another app is loading it somehow (maybe localeurl or modeltranslation?) but I don't ho wto fix this warning.

  • How to know why this warning is shown?
  • How to fix it in a clean way?
like image 412
luc Avatar asked Mar 07 '13 17:03

luc


3 Answers

This is a bug in django 1.5. Django itself is triggering the warning.

The culprit is django/contrib/gis/utils/layermapping.py#L19

This is fixed in django master (via removing localflavor altogether).

You can silence the warning by adding an ignore to your logging config:

import warnings
warnings.filterwarnings('ignore', r"django.contrib.localflavor is deprecated")
like image 154
craigds Avatar answered Nov 12 '22 02:11

craigds


Update:

Django now have a single localflavors package: https://pypi.python.org/pypi/django-localflavor

here is the documentation: http://django-localflavor.readthedocs.org/en/latest/

I let the rest of the response but it is obsolete now.

You have to download ALL local flavors you use ( https://github.com/django/ ), for now only 3 are on pypi.

Then, you can use them with the new

from django_localflavor_XX import forms as XX_forms

(where xx is your favorite country code)

They choosed to put aside all those libs because a lot of commits (in foreign languages) cames in django and the releases cycles was a bit long.

Django had natively mexican social security number validation widget!

So it's a good move but all those packages need to be managed by local communities as soon as possible to be usable.

this is trigered when an import is done, you may want to log a stack trace of the import or to look if you depends on a django app who uses it.

So open your django sources, go to your contrib.localflavor __init__.py file. print a stacktrace to know where is the bad import.

http://docs.python.org/2/library/traceback.html

Hope it helps

like image 23
christophe31 Avatar answered Nov 12 '22 02:11

christophe31


Just dealt with the same issue. I installed the new package (example for US package):

pip install https://github.com/django/django-localflavor-us/zipball/master

then I commented out the old code and changed to the new package:

# from django.contrib.localflavor.us.us_states import STATE_CHOICES  <= old
from django_localflavor_us.us_states import STATE_CHOICES
# from django.contrib.localflavor.us.models import USStateField  <= old
from django_localflavor_us.models import USStateField

Seems to have fixed the issue. The other language packages are listed here: https://github.com/django

like image 2
eezis Avatar answered Nov 12 '22 03:11

eezis