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 timezones for Django (>=1.7) based on MaxMind GeoIP.

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. 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'
  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.5.1.tar.gz (11.5 MB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-easy-timezones-0.5.1.tar.gz
Algorithm Hash digest
SHA256 0fd935d0f6598bc5e71cc5c562dda383d129669000b4a4b57ce38d3002f3708b
MD5 cc3f73b4d85941aadc336ab4ef0b2842
BLAKE2b-256 75055ea6d9eb5e41911fc53b3b2ef391fe73f163347b6900c9f7deba53202f75

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