Skip to content

Commit

Permalink
Documentation cleanup, minor code streamlining
Browse files Browse the repository at this point in the history
No functional changes intended.
  • Loading branch information
mfogel committed Oct 13, 2015
1 parent 71f107e commit ba48155
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
19 changes: 7 additions & 12 deletions README.rst
Expand Up @@ -7,12 +7,6 @@ django-timezone-field
.. image:: https://coveralls.io/repos/mfogel/django-timezone-field/badge.png?branch=develop
:target: https://coveralls.io/r/mfogel/django-timezone-field

.. image:: https://pypip.in/v/django-timezone-field/badge.png
:target: https://crate.io/packages/django-timezone-field/

.. image:: https://pypip.in/d/django-timezone-field/badge.png
:target: https://crate.io/packages/django-timezone-field/

A Django app providing database and form fields for `pytz`__ timezone objects.

Examples
Expand Down Expand Up @@ -88,7 +82,8 @@ Changelog

* 1.3

* Drop support for django 1.6
* Drop support for django 1.6, add support for django 1.8
* Various `bug fixes`__

* 1.2 (2015-02-05)

Expand All @@ -99,10 +94,8 @@ Changelog
* 1.1 (2014-10-05)

* Django 1.7 compatibility
* Changed format of `choices` kwarg to `[[<str>, <str>], ...]`,
was previously `[[<pytz timezone>, <str>], ...]`.
Old format is still deprecated but still accepted for now; support
will be removed in a future release.
* Added support for formating `choices` kwarg as `[[<str>, <str>], ...]`,
in addition to previous format of `[[<pytz.timezone>, <str>], ...]`.
* Changed default list of accepted timezones from `pytz.all_timezones` to
`pytz.common_timezones`. If you have timezones in your DB that are in
`pytz.all_timezones` but not in `pytz.common_timezones`, this is a
Expand All @@ -126,7 +119,8 @@ Running the Tests
tox
It's that simple.
Postgres will need to be running locally, and sqlite will need to be
installed in order for tox to do its job.

Found a Bug?
------------
Expand All @@ -143,6 +137,7 @@ __ http://pypi.python.org/pypi/pytz/
__ http://pypi.python.org/pypi/django-timezone-field/
__ http://www.pip-installer.org/
__ https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
__ https://github.com/mfogel/django-timezone-field/issues?q=milestone%3A1.3
__ https://tox.readthedocs.org/
__ https://github.com/mfogel/django-timezone-field/
__ https://github.com/brosner/django-timezones/
Expand Down
19 changes: 12 additions & 7 deletions timezone_field/fields.py
Expand Up @@ -23,10 +23,12 @@ class TimeZoneFieldBase(models.Field):
* instances of pytz.tzinfo.DstTzInfo and pytz.tzinfo.StaticTzInfo
* the pytz.UTC singleton
Blank values are stored in the DB as the empty string.
Blank values are stored in the DB as the empty string. Timezones are stored
in their string representation.
The `choices` kwarg can be specified as a list of either
[<pytz.timezone>, <str>] or [<str>, <str>].
[<pytz.timezone>, <str>] or [<str>, <str>]. Internally, it is stored as
[<pytz.timezone>, <str>].
"""

description = "A pytz timezone object"
Expand All @@ -37,8 +39,9 @@ class TimeZoneFieldBase(models.Field):
MAX_LENGTH = 63

def __init__(self, choices=None, max_length=None, **kwargs):
if choices is not None:

if choices is None:
choices = self.CHOICES
else:
# Choices can be specified in two forms: either
# [<pytz.timezone>, <str>] or [<str>, <str>]
#
Expand All @@ -53,10 +56,12 @@ def __init__(self, choices=None, max_length=None, **kwargs):
if isinstance(choices[0][0], six.string_types):
choices = [(pytz.timezone(n1), n2) for n1, n2 in choices]

kwargs['choices'] = choices or self.CHOICES
kwargs['max_length'] = max_length or self.MAX_LENGTH
if max_length is None:
max_length = self.MAX_LENGTH

super(TimeZoneFieldBase, self).__init__(**kwargs)
super(TimeZoneFieldBase, self).__init__(choices=choices,
max_length=max_length,
**kwargs)

def validate(self, value, model_instance):
if not is_pytz_instance(value):
Expand Down

0 comments on commit ba48155

Please sign in to comment.