django-tz-detect
================
.. image:: https://img.shields.io/pypi/v/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/
.. image:: https://img.shields.io/pypi/dm/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/
.. image:: https://img.shields.io/github/license/adamcharnock/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/
.. image:: https://coveralls.io/repos/adamcharnock/django-tz-detect/badge.svg?branch=develop
:target: https://coveralls.io/r/adamcharnock/django-tz-detect?branch=develop
This app will auto-detect a user's timezone using JavaScript, then
configure Django's timezone localization system accordingly. As a
result, dates shown to users will be in their local timezones.
Authored by `Adam Charnock <https://adamcharnock.com/>`_, and some great `contributors <https://github.com/adamcharnock/django-tz-detect/contributors>`_.
How it works
------------
On the first page view you should find that ``tz_detect`` places a
piece of asynchronous JavaScript code into your page using the
template tag you inserted. The script will obtain the user's GMT
offset using ``getTimezoneOffset``, and post it back to Django. The
offset is stored in the user's session and Django's timezone awareness
is configured in the middleware.
The JavaScript will not be displayed in future requests.
Installation
------------
1. Either checkout ``tz_detect`` from GitHub, or install using pip:
.. code-block:: bash
pip install django-tz-detect
2. Add ``tz_detect`` to your ``INSTALLED_APPS``:
.. code-block:: python
INSTALLED_APPS += (
'tz_detect',
)
3. Be sure you have the ``django.template.context_processors.request`` processor
.. code-block:: python
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'django.template.context_processors.request',
],
},
},
]
4. Update your ``urls.py`` file:
.. code-block:: python
urlpatterns += [
path('tz_detect/', include('tz_detect.urls')),
]
5. Add the detection template tag to your site, ideally in your base layout just before the ``</body>`` tag:
.. code-block:: html+django
{% load tz_detect %}
{% tz_detect %}
6. Add ``TimezoneMiddleware`` to ``MIDDLEWARE``:
.. code-block:: python
import django
MIDDLEWARE += (
'tz_detect.middleware.TimezoneMiddleware',
)
if django.VERSION < (1, 10):
MIDDLEWARE_CLASSES += (
'tz_detect.middleware.TimezoneMiddleware',
)
7. (Optional) Configure the countries in which your app will be most commonly used:
.. code-block:: python
# These countries will be prioritized in the search
# for a matching timezone. Consider putting your
# app's most popular countries first.
# Defaults to the top Internet using countries.
TZ_DETECT_COUNTRIES = ('CN', 'US', 'IN', 'JP', 'BR', 'RU', 'DE', 'FR', 'GB')
Please see ``example`` application. This application is used to manually
test the functionalities of this package. This also serves as a good
example.
You need only Django 1.8 or above to run that. It might run on older
versions but that is not tested.
Caveats
-------
- Django's timezone awareness will not be available on the first page view
- This method requires JavaScript
- Timezone detection is done entirely from the user's GMT offset, not from their location
Future expansion
----------------
- A hook to allow the timezone to be stored against a user
- Allow timezones to be manually specified
- Improve timezone detection
- Optionally using HTML5's location API for better timezone determination
Raw data
{
"_id": null,
"home_page": "http://github.com/adamcharnock/django-tz-detect",
"name": "django-tz-detect",
"maintainer": "Basil Shubin",
"docs_url": null,
"requires_python": "",
"maintainer_email": "basil.shubin@gmail.com",
"keywords": "",
"author": "Adam Charnock",
"author_email": "adam@adamcharnock.com",
"download_url": "https://files.pythonhosted.org/packages/75/66/03b36aa969d93330556a658f2bcca3511ab594f43ffedf672cc042cfd06d/django-tz-detect-0.4.0.tar.gz",
"platform": "",
"description": "django-tz-detect\n================\n\n.. image:: https://img.shields.io/pypi/v/django-tz-detect.svg\n :target: https://pypi.python.org/pypi/django-tz-detect/\n\n.. image:: https://img.shields.io/pypi/dm/django-tz-detect.svg\n :target: https://pypi.python.org/pypi/django-tz-detect/\n\n.. image:: https://img.shields.io/github/license/adamcharnock/django-tz-detect.svg\n :target: https://pypi.python.org/pypi/django-tz-detect/\n\n.. image:: https://coveralls.io/repos/adamcharnock/django-tz-detect/badge.svg?branch=develop\n :target: https://coveralls.io/r/adamcharnock/django-tz-detect?branch=develop\n\nThis app will auto-detect a user's timezone using JavaScript, then\nconfigure Django's timezone localization system accordingly. As a\nresult, dates shown to users will be in their local timezones.\n\nAuthored by `Adam Charnock <https://adamcharnock.com/>`_, and some great `contributors <https://github.com/adamcharnock/django-tz-detect/contributors>`_.\n\nHow it works\n------------\n\nOn the first page view you should find that ``tz_detect`` places a\npiece of asynchronous JavaScript code into your page using the\ntemplate tag you inserted. The script will obtain the user's GMT\noffset using ``getTimezoneOffset``, and post it back to Django. The\noffset is stored in the user's session and Django's timezone awareness\nis configured in the middleware.\n\nThe JavaScript will not be displayed in future requests.\n\nInstallation\n------------\n\n1. Either checkout ``tz_detect`` from GitHub, or install using pip:\n\n .. code-block:: bash\n\n pip install django-tz-detect\n\n2. Add ``tz_detect`` to your ``INSTALLED_APPS``:\n\n .. code-block:: python\n\n INSTALLED_APPS += (\n 'tz_detect',\n )\n\n3. Be sure you have the ``django.template.context_processors.request`` processor\n \n .. code-block:: python\n\n TEMPLATES = [\n {\n ...\n 'OPTIONS': {\n 'context_processors': [\n ...\n 'django.template.context_processors.request',\n ],\n },\n },\n ]\n\n4. Update your ``urls.py`` file:\n\n .. code-block:: python\n\n urlpatterns += [\n path('tz_detect/', include('tz_detect.urls')),\n ]\n\n5. Add the detection template tag to your site, ideally in your base layout just before the ``</body>`` tag:\n\n .. code-block:: html+django\n\n {% load tz_detect %}\n {% tz_detect %}\n\n6. Add ``TimezoneMiddleware`` to ``MIDDLEWARE``:\n\n .. code-block:: python\n\n import django\n\n MIDDLEWARE += (\n 'tz_detect.middleware.TimezoneMiddleware',\n )\n\n if django.VERSION < (1, 10):\n MIDDLEWARE_CLASSES += (\n 'tz_detect.middleware.TimezoneMiddleware',\n )\n\n7. (Optional) Configure the countries in which your app will be most commonly used:\n\n .. code-block:: python\n\n # These countries will be prioritized in the search\n # for a matching timezone. Consider putting your\n # app's most popular countries first.\n # Defaults to the top Internet using countries.\n TZ_DETECT_COUNTRIES = ('CN', 'US', 'IN', 'JP', 'BR', 'RU', 'DE', 'FR', 'GB')\n\nPlease see ``example`` application. This application is used to manually\ntest the functionalities of this package. This also serves as a good\nexample.\n\nYou need only Django 1.8 or above to run that. It might run on older\nversions but that is not tested.\n\nCaveats\n-------\n\n- Django's timezone awareness will not be available on the first page view\n- This method requires JavaScript\n- Timezone detection is done entirely from the user's GMT offset, not from their location\n\nFuture expansion\n----------------\n\n- A hook to allow the timezone to be stored against a user\n- Allow timezones to be manually specified\n- Improve timezone detection\n- Optionally using HTML5's location API for better timezone determination\n\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Automatic user timezone detection for django",
"version": "0.4.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "e82ac69e5dcb9bcfbda20d6de5797a3f",
"sha256": "ca3842b9d92ed3aff3c783430d79fd66785c722ca942fabeaf5f9008f35c8124"
},
"downloads": -1,
"filename": "django_tz_detect-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e82ac69e5dcb9bcfbda20d6de5797a3f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 11641,
"upload_time": "2022-02-12T18:21:41",
"upload_time_iso_8601": "2022-02-12T18:21:41.386292Z",
"url": "https://files.pythonhosted.org/packages/f5/e2/cc9bee78c8edde6fce8fd9ca60b1096d9b8797a11870420b8f9b89814077/django_tz_detect-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "9f620e3b24d5966301f3a16232f37adc",
"sha256": "ff3ceb2062a2dffaf7d5c20216761c7c4fbbee894c14906bdc93ec6e03e10ffa"
},
"downloads": -1,
"filename": "django-tz-detect-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "9f620e3b24d5966301f3a16232f37adc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11275,
"upload_time": "2022-02-12T18:21:43",
"upload_time_iso_8601": "2022-02-12T18:21:43.033581Z",
"url": "https://files.pythonhosted.org/packages/75/66/03b36aa969d93330556a658f2bcca3511ab594f43ffedf672cc042cfd06d/django-tz-detect-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-02-12 18:21:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "adamcharnock",
"github_project": "django-tz-detect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-tz-detect"
}