Skip to main content

Easy timezones for Django (>=1.7) based on MaxMind GeoIP.

Project description

Timezones. Yuck.

Timezones. Yuck.

django-easy-timezones Build Status PyPI

Easy IP-based timezones for Django (>=1.7) based on MaxMind GeoIP, with IPv6 support.

Quick start

  1. Install django-easy-timezones

    pip install django-easy-timezones
  2. Add “easy-timezones” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
      ...
      'easy_timezones',
    )
  3. Add EasyTimezoneMiddleware to your MIDDLEWARE_CLASSES

    MIDDLEWARE_CLASSES = (
      ...
      'easy_timezones.middleware.EasyTimezoneMiddleware',
    )
  4. (Optionally) Add a path to the MaxMind GeoIP cities databases (direct link because I’m nice) in your settings file:

    GEOIP_DATABASE = '/path/to/your/geoip/database/GeoLiteCity.dat'
    GEOIPV6_DATABASE = '/path/to/your/geoip/database/GeoLiteCityv6.dat'
  5. Enable localtime in your templates.

    {% load tz %}
        The UTC time is {{ object.date }}
    {% localtime on %}
        The local time is {{ object.date }}
    {% endlocaltime %}
  6. Twist one up, cause you’re done, homie!

Signals

You can also use signals to perform actions based on the timezone detection.

  1. To hook into the Timezone detection event to, say, save it to the request’s user somewhere more permanent than a session, do something like this:

    from easy_timezones.signals import detected_timezone
    
    @receiver(detected_timezone, sender=MyUserModel)
    def process_timezone(sender, instance, timezone, **kwargs):
        if instance.timezone != timezone:
            instance.timezone = timezone
            instance.save()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-easy-timezones-0.7.0.tar.gz (24.0 MB view details)

Uploaded Source

Built Distribution

django_easy_timezones-0.7.0-py2-none-any.whl (9.4 kB view details)

Uploaded Python 2

File details

Details for the file django-easy-timezones-0.7.0.tar.gz.

File metadata

File hashes

Hashes for django-easy-timezones-0.7.0.tar.gz
Algorithm Hash digest
SHA256 2101cdda3528715e04410f8c45310e2acfbfe4a55dd642f0b66442f617f90e77
MD5 111c17406f91c3c4b8ce67139417a452
BLAKE2b-256 5fb77228faa680a26585e31e8642462bdd2086a253bf92a5c52dba9b25c7e31a

See more details on using hashes here.

Provenance

File details

Details for the file django_easy_timezones-0.7.0-py2-none-any.whl.

File metadata

File hashes

Hashes for django_easy_timezones-0.7.0-py2-none-any.whl
Algorithm Hash digest
SHA256 52e10ebdb769b3f31690d9715603c96f69b7b79fc174a41ede8f99360d957b0c
MD5 767b60e02efd7181e82a5d82d44cb93e
BLAKE2b-256 fa97209571be8db02e8b8e8e3ea69d88ccc7e2f5d5c21be7da21deeaa487c1d6

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page