Skip to content

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

License

Notifications You must be signed in to change notification settings

charettes/django-sundial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-sundial

License Latest Version Build Status Coverage Status Supported Python Versions Wheel Status

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

Installation

pip install django-sundial

Usage

# settings.py
TIME_ZONE = 'America/Chicago'
AUTH_USER_MODEL = 'app.User'
MIDDLEWARE = [
    ...,
    'django.contrib.sessions.middleware.SessionMiddleware',
    ...,
    'sundial.middleware.TimezoneMiddleware',
    ...,
]
# 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)

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages