2011/9/6 Paul McMillan <[email protected]>:
>> I'm going to use the same trick used by USE_L10N and explained by Anssi: set
>> USE_TZ to False in global_settings.py and to True in the template of
>> settings.py. This preserves backwards compatibility but the new code is the
>> default for new projects.
>
> This isn't gonna work because your new code will have a hard dependency on
> pytz.
Django uses PIL for ImageField, but it isn't a hard dependency because
it's only imported within functions that actually use it. We can do
the same for pytz if it's only used in a few places.
If a module uses pytz in many functions, I suggest this pattern:
from django.conf import settings
if settings.USE_TZ:
import pytz
And it's a bug to hit code that depends on pytz when USE_TZ is False.
If we want to make some functions (like timezone conversion helpers)
available to anyone who has pytz, regardless of the value of USE_TZ,
we could use this pattern:
try:
import pytz
except ImportError:
if settings.USE_TZ:
raise
--
Aymeric Augustin.
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.