Coder Social home page Coder Social logo

awesome-django-timezones's Introduction

Awesome Django Timezones

https://travis-ci.org/wgordon17/awesome-django-timezones.svg?branch=master

Easily set a localized timezone for users

Documentation

The full documentation is at https://awesome-django-timezones.readthedocs.io.

Quickstart

Install Awesome Django Timezones:

pip install awesome-django-timezones

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'awesome_django_timezones',
    ...
)

Add DjangoTimezonesMiddleware to your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    ...
    'awesome_django_timezones.middleware.TimezonesMiddleware',
    ...
)

Add js/awesome_django_timezones.js to your base template

<script src="{% static 'awesome_django_timezones/js/awesome_django_timezones.js' %}"></script>

(Optional) If you need Django to be timezone aware on the Admin page, you will have to extend the Admin base.html in your_project/templates/admin/base.html

{% extends 'admin/base.html' %}
{% load static %}

{% block footer %}
  {{ block.super }}

  <script src="{% static 'js/awesome_django_timezones.js' %}"></script>

{% endblock %}

Features

  • Provides an accurate method of determining the an end user's timezone and activating that timezone in Django.
  • Uses client side, JavaScript detection for the most accurate method of determining a timezone.
    • Uses the widely supported, native Intl JavaScript library to detect the client's timezone. This library is not currently implemented for IE11.
  • Falls back to server side timezone detection via an IP API.
    • Fall back is provided for IE11 clients or clients with JavaScript disabled.
    • Relies on third-party IP API lookups by https://ipapi.co. Consider purchasing a plan if you need more than 30k IP lookups/month or if you need support (no affiliation).
  • Set a fallback timezone to always use in case a timezone can't be found with AWESOME_TZ_DEFAULT_TZ in your settings.py. (Be sure to use the "TZ database name" column from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements_test.txt
(myenv) $ tox

Credits

Tools used in rendering this package:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.