Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renamed TIMEZONE_CHOICES to ALL_TIMEZONE_CHOICES and added COMMON_TIM…

…EZONE_CHOICES and PRETTY_TIMEZONE_CHOICES (shows the GMT offset in the label).

This commit preserves backward compatibility of imports which will be removed shortly.

This changes the default choices for the TimeZoneField to
PRETTY_TIMEZONE_CHOICES since this would seem to be the most common among
users.

Fixes issue #8. Thanks Leah Culver for the idea.

git-svn-id: https://django-timezones.googlecode.com/svn/trunk@36 86ebb30f-654e-0410-bc0d-7bf82786d749
  • Loading branch information...
commit d702f9a3d17af9100ba6cf202433302929bd1155 1 parent 7cac697
@brosner authored
Showing with 10 additions and 3 deletions.
  1. +2 −1  timezones/__init__.py
  2. +8 −2 timezones/forms.py
View
3  timezones/__init__.py
@@ -1,2 +1,3 @@
# for backwards compatability
-from timezones.forms import TIMEZONE_CHOICES
+from timezones.forms import ALL_TIMEZONE_CHOICES
+TIMEZONE_CHOICES = ALL_TIMEZONE_CHOICES
View
10 timezones/forms.py
@@ -1,12 +1,18 @@
import pytz
+import datetime
from django.conf import settings
from django import forms
from timezones.utils import adjust_datetime_to_timezone
-TIMEZONE_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones))
+ALL_TIMEZONE_CHOICES = TIMEZONE_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones))
+COMMON_TIMEZONE_CHOICES = tuple(zip(pytz.common_timezones, pytz.common_timezones))
+PRETTY_TIMEZONE_CHOICES = []
+for tz in pytz.common_timezones:
+ now = datetime.datetime.now(pytz.timezone(tz))
+ PRETTY_TIMEZONE_CHOICES.append((tz, "(GMT%s) %s" % (now.strftime("%z"), tz)))
class TimeZoneField(forms.ChoiceField):
def __init__(self, choices=None, max_length=None, min_length=None,
@@ -15,7 +21,7 @@ def __init__(self, choices=None, max_length=None, min_length=None,
if choices is not None:
kwargs["choices"] = choices
else:
- kwargs["choices"] = TIMEZONE_CHOICES
+ kwargs["choices"] = PRETTY_TIMEZONE_CHOICES
super(TimeZoneField, self).__init__(*args, **kwargs)
def clean(self, value):
Please sign in to comment.
Something went wrong with that request. Please try again.