Metadata-Version: 2.1
Name: django-sundial
Version: 1.1.1
Summary: Django application providing database, form fields and middleware for timezone support.
Home-page: https://github.com/charettes/django-sundial
Author: Simon Charette.
Author-email: charette.s+sundial@gmail.com
License: MIT
Keywords: django timezone
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
License-File: LICENSE
Requires-Dist: Django>=2.2
Requires-Dist: pytz
Provides-Extra: tests
Requires-Dist: tox; extra == "tests"

django-sundial
==============

.. image:: https://img.shields.io/pypi/l/django-sundial.svg?style=flat
    :target: https://pypi.python.org/pypi/django-sundial/
    :alt: License

.. image:: https://img.shields.io/pypi/v/django-sundial.svg?style=flat
    :target: https://pypi.python.org/pypi/django-sundial/
    :alt: Latest Version

.. image:: https://travis-ci.org/charettes/django-sundial.svg?branch=master
    :target: https://travis-ci.org/charettes/django-sundial
    :alt: Build Status

.. image:: https://coveralls.io/repos/charettes/django-sundial/badge.svg?branch=master
    :target: https://coveralls.io/r/charettes/django-sundial?branch=master
    :alt: Coverage Status

.. image:: https://img.shields.io/pypi/pyversions/django-sundial.svg?style=flat
    :target: https://pypi.python.org/pypi/django-sundial/
    :alt: Supported Python Versions

.. image:: https://img.shields.io/pypi/wheel/django-sundial.svg?style=flat
    :target: https://pypi.python.org/pypi/django-sundial/
    :alt: Wheel Status

Django application providing database, form fields and middleware for timezone support.

Installation
------------

.. code:: sh

    pip install django-sundial

Usage
-----

.. code:: python

    # settings.py
    TIME_ZONE = 'America/Chicago'
    AUTH_USER_MODEL = 'app.User'
    MIDDLEWARE = [
        ...,
        'django.contrib.sessions.middleware.SessionMiddleware',
        ...,
        'sundial.middleware.TimezoneMiddleware',
        ...,
    ]

.. code:: python

    # app/models.py
    from django.conf import settings
    from django.contrib.auth.models import AbstractUser
    from django.contrib.auth.signals import user_logged_in
    from django.dispatch.dispatcher import receiver

    from sundial.fields import TimezoneField
    from sundial.utils import set_session_timezone
    from sundial.zones import COMMON_GROUPED_CHOICES

    class User(AbstractUser):
        timezone = TimezoneField(
            default=settings.TIME_ZONE, choices=COMMON_GROUPED_CHOICES
        )

    @receiver(user_logged_in)
    def assign_user_timezone(request, user, **kwargs):
        set_session_timezone(request.session, user.timezone)
