Easy timezones for Django (>=1.7) based on MaxMind GeoIP.
Project description
django-easy-timezones
Easy timezones for Django (>=1.7) based on MaxMind GeoIP.
Quick start
Install django-easy-timezones
pip install django-easy-timezones
Add “easy-timezones” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'easy_timezones', )
Add EasyTimezoneMiddleware to your MIDDLEWARE_CLASSES
MIDDLEWARE_CLASSES = ( ... 'easy_timezones.middleware.EasyTimezoneMiddleware', )
Add a path to the MaxMind GeoIP cities database (direct link because I’m nice) in your settings file:
GEOIP_DATABASE = '/path/to/your/geoip/database/GeoLiteCity.dat'
Enable localtime in your templates.
{% load tz %} The UTC time is {{ object.date }} {% localtime on %} The local time is {{ object.date }} {% endlocaltime %}
Twist one up, cause you’re done, homie!
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
Hashes for django-easy-timezones-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | deb3ac2e3212f46ad82332b97e47fc853bc4079a1cd92e7d611ea2b62ec113cd |
|
MD5 | 927736f597d9df287c0020b395a96df0 |
|
BLAKE2b-256 | dfe541de82a31c5493bcc97c1fdd90051b531ebe213865b7d97a764a428f94a8 |