Easy timezones for Django (>=1.11) based on MaxMind GeoIP2.
Project description
django-easy-timezones-redux
Easy IP-based timezones for Django (>=1.11) based on MaxMind GeoIP, with IPv6 support.
Updated fork of django-easy-timezones
that uses the new version of MaxMind's GeoIP2 database.
Quick start
-
Install django-easy-timezones-redux
pip install django-easy-timezones-redux
-
Add "easy-timezones" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'easy_timezones', )
-
Add EasyTimezoneMiddleware to your MIDDLEWARE
MIDDLEWARE = ( ... 'easy_timezones.middleware.EasyTimezoneMiddleware', )
-
Add a path to the MaxMind GeoLite2 cities databases in your settings file:
GEOIP2_DATABASE = '/path/to/your/geoip/database/GeoLite2-City.mmdb'
-
Enable localtime in your templates.
{% load tz %} The UTC time is {{ object.date }} {% localtime on %} The local time is {{ object.date }} {% endlocaltime %}
-
That's it!
Signals
You can also use signals to perform actions based on the timezone detection.
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-easy-timezones-redux-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ae590ba5a640219c989fadef14fb396ead0c46349601d0b248389b0744159fc |
|
MD5 | 65b7876fa0930fab68e32644e704a109 |
|
BLAKE2b-256 | d2d9ad922183eedf75ad468fd42acbf901cec61a0f074af49842f76a133a3799 |
Hashes for django_easy_timezones_redux-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b80e7cb2dca68c22b39c2abdadca2ffb1d0c20d1f2faf2190a5d1048a7d452 |
|
MD5 | 39617ab223480027ae66f42c0de609ca |
|
BLAKE2b-256 | ddf3cde4bf28203a85f92dc4e625b2bbe3acc28bb39c22ccbdbaa33900645b18 |