Welcome to Awesome Django Timezones’s documentation!¶
Contents:
Awesome Django Timezones¶
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 yoursettings.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
Installation¶
At the command line:
$ pip install awesome-django-timezones
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv awesome-django-timezones
$ pip install awesome-django-timezones
Usage¶
To use Awesome Django Timezones in a project, 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 '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 %}
Configuration¶
- If using a purchased plan from https://ipapi.co, you can specify
DJANGO_IPAPI_KEY
in yoursettings.py
file to use your key.
awesome_django_timezones¶
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/wgordon17/awesome-django-timezones/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
Awesome Django Timezones could always use more documentation, whether as part of the official Awesome Django Timezones docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/wgordon17/awesome-django-timezones/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up awesome-django-timezones for local development.
Fork the awesome-django-timezones repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/awesome-django-timezones.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv awesome-django-timezones $ cd awesome-django-timezones/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 awesome_django_timezones tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 3.6+. Check https://travis-ci.org/wgordon17/awesome-django-timezones/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Will Gordon <will@gordoncode.com>
Contributors¶
None yet. Why not be the first?