Skip to main content

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

Project description

![Timezones. Yuck.](http://i.imgur.com/Qc2W47H.gif)

django-easy-timezones
=====================

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

Quick start
-----------

1. Install django-easy-timezones

```python
pip install django-easy-timezones
```

1. Add "easy-timezones" to your INSTALLED_APPS setting like this:

```python
INSTALLED_APPS = (
...
'easy_timezones',
)
```

1. Add EasyTimezoneMiddleware to your MIDDLEWARE_CLASSES

```python
MIDDLEWARE_CLASSES = (
...
'easy_timezones.middleware.EasyTimezoneMiddleware',
)
```

1. Add a path to the [MaxMind GeoIP cities database](http://dev.maxmind.com/geoip/legacy/geolite/) ([direct
link](http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz) because I'm nice) in your settings file:

```python
GEOIP_DATABASE = '/path/to/your/geoip/database/GeoLiteCity.dat'
```

1. Enable localtime in your templates.

```python
{% load tz %}
The UTC time is {{ object.date }}
{% localtime on %}
The local time is {{ object.date }}
{% endlocaltime %}
```
1. 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:

```python
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.3.0.tar.gz (7.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-easy-timezones-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d3ef42ee254b0cbc7821026c190c2dce23130d322a4f4ffa04a497c93f836481
MD5 d1743b59268bdd9a6f36f06d31895b43
BLAKE2b-256 2e32adeb2d0d2c54710236aa2ca0a112c2376d5899a2d474fc581c362d9c78fd

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