A project for timezone handling.
Project description
Django Sage Timezone Management
Django Sage Timezone Management is a Django package that allows administrators to easily select and apply a timezone for their session directly from the Django Admin interface. Once set, the timezone is automatically applied to all datetime displays during the session.
Features
- Adds a "Select Timezone" option in the Django Admin navigation bar.
- Automatically applies the selected timezone to the user's session using middleware.
- Supports all timezones available through
pytz
. - Simple integration with existing Django projects.
Installation
Using pip
with virtualenv
-
Create a Virtual Environment:
python -m venv .venv
-
Activate the Virtual Environment:
-
On Windows:
.venv\Scripts\activate
-
On macOS/Linux:
source .venv/bin/activate
-
-
Install
django-sage-timezone
:pip install django-sage-timezone
Using poetry
-
Initialize Poetry (if not already initialized):
poetry init
-
Install
django-sage-timezone
:poetry add django-sage-timezone
-
Apply Migrations:
After installation, ensure to run the following commands to apply necessary migrations:
python manage.py makemigrations python manage.py migrate
Configuration
Django Settings
Add django-sage-timezone
to your INSTALLED_APPS
in the Django settings:
INSTALLED_APPS = [
...
"sage_timezone",
"django.contrib.admin"
]
Also, add the TimezoneMiddleware
to your middleware settings:
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"sage_timezone.middleware.TimezoneMiddleware",
...
]
Important Note:
The sage_timezone.middleware.timezone.TimezoneMiddleware
must be placed after the django.contrib.sessions.middleware.SessionMiddleware
in your MIDDLEWARE
setting. This order is crucial to ensure that the session data is available when the timezone is set.
Note:
You can set a custom session name in your Django settings using the TIME_ZONE_SESSION_NAME
setting. For example:
TIME_ZONE_SESSION_NAME = 'your_custom_session_name'
Usage
Once configured, the Django Admin will include a "Select Timezone" option in the navigation bar. Administrators can choose their preferred timezone, which will be applied to their session.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_sage_timezone-0.1.2.tar.gz
.
File metadata
- Download URL: django_sage_timezone-0.1.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ef6fa48904925d8a7d62fa3b1ecbfbd38c6746474942c4483a999970eb22c7 |
|
MD5 | d1f8db370f112670e8d535ba92cb5ac1 |
|
BLAKE2b-256 | ac898d45027ef4eb97fcae06046d18afa5c3a5869f8d4fb9cef190a4fe0b6971 |
File details
Details for the file django_sage_timezone-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: django_sage_timezone-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd8587eeb47c0a38cd646635e8fdaedbf5f62d8936c97602c8214e204afee580 |
|
MD5 | 290b99a02e720578dbce13c3926c8bb1 |
|
BLAKE2b-256 | ff99906ad18b9023ed370456199f1eefc69024b9f1dcd875ebe02916a4153568 |