Django User g11n
=========================================================================================
[![CircleCI](https://circleci.com/gh/salexkidd/django-user-g11n/tree/master.svg?style=svg)](https://circleci.com/gh/salexkidd/django-user-g11n/tree/master)
Django supports *i18n* and *l10n*. However, there is no item to set the user's time zone and region as a default feature.
Django User g11n (*globalization*) provides fields for users to set time zones and regions, as well as middleware to handle them properly.
<img src="https://raw.githubusercontent.com/wiki/salexkidd/django-user-g11n/imgs/example.gif" width="800px">
Core idea is [See the Django documentation for more information](https://stackoverflow.com/questions/10235956/django-1-4-how-to-automatically-get-users-timezone-from-client)
- Support 3
- Support 3.10.x or later
# Usage
Install the package from pypi
```
$ pip install django-user-g11n
```
Next, choose one of the following two implementation methods
- Using a profile model
- Using a custom user model
The profile model refers to a model that handles information about a user that is connected to the Django user model by a *OneToOneField*. If you are already recommending this method of implementation, see *If you are using a profile model*.
A custom user model is a way of extending the Django user model itself to contain data. To get users to take advantage of the custom model, you create an application and customize the model. [See the Django documentation for more information](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/)
## Using a profile model
Create an application that handles the profile model.
```
$ manage.py startapp accounts
Add the following to your application's models.py
```python
from django.db import models
from user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin
class UserProfile(UserTimeZoneSupportMixin,
UserLanguageSupportMixin,
models.Model):
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="profile",
)
```
## Using a custom user model
Create an application for custom users. Please refer to the Django documentation for more information.
[See the Django documentation for more information](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/)
```
$ manage.py startapp accounts
```
Add the following to your application's models.py
```
from django.contrib.auth import models as auth_models
from user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin
class User(UserTimeZoneSupportMixin,
UserLanguageSupportMixin,
auth_models.AbstractUser):
pass
```
## modifying to settings.py
### INSTALLED_APPS
Add a user-extended application and user_g11n to INSTALLED_APPS.
```
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
.
.
.
'accounts', # Your Custom user model application
'user_g11n', # Add
)
```
### MIDDLEWARE
Added two middleware provided by django_user_g11n.
```
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
.
.
.
'user_g11n.middleware.UserLanguageMiddleware', # Add
'user_g11n.middleware.UserTimeZoneMiddleware', # Add
]
```
### AUTH_USER_MODEL
Change or add the AUTH_USER_MODEL.
```
AUTH_USER_MODEL = 'accounts.User'
```
### I18N, L10N & TIME_ZONE setting
Change the I18N, L10N, and TZ settings.
```
USE_I18N = True
USE_L10N = True
USE_TZ = True
TIME_ZONE = "Asia/Tokyo" # Change to your local timezone
```
## When a profile model is used (specification of profile attributes)
Set the attribute name of the profile model associated with the user model.
```
USER_G11N_USERPROFILE_ATTRIBUTE_NAME = "profile"
```
If the related_name is "foobar" in the OneToOneField to the user model specified in the profile model, change the value here to the following
```
USER_G11N_USERPROFILE_ATTRIBUTE_NAME = "foobar"
```
## migrate
Migration to adapt the changes.
```
$ ./manage.py makemigrations
$ ./manage.py migrate
```
# Demo
The Docker configuration is provided. Please use the following command to start it. Go to [http://localhost:8000](http://localhost:8000) when the launch is complete.
```
$ docker-compose up
```
# AUTHORS
[See this](https://github.com/salexkidd/django-user-g11n/blob/master/AUTHORS.md)
# Release note
- 2024/06/06: Remove Django2 and 3 support and Python 3.9
Raw data
{
"_id": null,
"home_page": "https://github.com/salexkidd/django-user-g11n",
"name": "django-user-g11n",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "django, i18n, l10n, g11n, timezone",
"author": "salexkidd",
"author_email": "salexkidd@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/82/c2/4b95cdc118a13ee5262fee9bd8b8262f9feebdaabd3f97b7f96f4a06d27f/django-user-g11n-0.4.4.tar.gz",
"platform": null,
"description": "Django User g11n\n=========================================================================================\n\n[![CircleCI](https://circleci.com/gh/salexkidd/django-user-g11n/tree/master.svg?style=svg)](https://circleci.com/gh/salexkidd/django-user-g11n/tree/master)\n\nDjango supports *i18n* and *l10n*. However, there is no item to set the user's time zone and region as a default feature.\n\nDjango User g11n (*globalization*) provides fields for users to set time zones and regions, as well as middleware to handle them properly.\n\n<img src=\"https://raw.githubusercontent.com/wiki/salexkidd/django-user-g11n/imgs/example.gif\" width=\"800px\">\n\nCore idea is [See the Django documentation for more information](https://stackoverflow.com/questions/10235956/django-1-4-how-to-automatically-get-users-timezone-from-client)\n\n- Support 3\n- Support 3.10.x or later\n\n\n# Usage\n\nInstall the package from pypi\n\n```\n$ pip install django-user-g11n\n```\n\nNext, choose one of the following two implementation methods\n\n- Using a profile model\n- Using a custom user model\n\nThe profile model refers to a model that handles information about a user that is connected to the Django user model by a *OneToOneField*. If you are already recommending this method of implementation, see *If you are using a profile model*.\n\nA custom user model is a way of extending the Django user model itself to contain data. To get users to take advantage of the custom model, you create an application and customize the model. [See the Django documentation for more information](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/)\n\n\n## Using a profile model\n\nCreate an application that handles the profile model.\n\n```\n$ manage.py startapp accounts\n\nAdd the following to your application's models.py\n\n```python\nfrom django.db import models\nfrom user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin\n\n\nclass UserProfile(UserTimeZoneSupportMixin,\n UserLanguageSupportMixin,\n models.Model):\n\n user = models.OneToOneField(\n settings.AUTH_USER_MODEL,\n on_delete=models.CASCADE,\n related_name=\"profile\",\n )\n```\n\n\n## Using a custom user model\n\nCreate an application for custom users. Please refer to the Django documentation for more information.\n[See the Django documentation for more information](https://docs.djangoproject.com/en/3.0/topics/auth/customizing/)\n\n```\n$ manage.py startapp accounts\n```\n\nAdd the following to your application's models.py\n\n```\nfrom django.contrib.auth import models as auth_models\nfrom user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin\n\n\nclass User(UserTimeZoneSupportMixin,\n UserLanguageSupportMixin,\n auth_models.AbstractUser):\n pass\n```\n\n## modifying to settings.py\n\n### INSTALLED_APPS\n\nAdd a user-extended application and user_g11n to INSTALLED_APPS.\n\n```\nINSTALLED_APPS = (\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n .\n .\n .\n 'accounts', # Your Custom user model application\n 'user_g11n', # Add\n)\n```\n\n### MIDDLEWARE\n\nAdded two middleware provided by django_user_g11n.\n\n```\nMIDDLEWARE = [\n 'django.middleware.security.SecurityMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\n .\n .\n .\n 'user_g11n.middleware.UserLanguageMiddleware', # Add\n 'user_g11n.middleware.UserTimeZoneMiddleware', # Add\n]\n```\n\n### AUTH_USER_MODEL\n\nChange or add the AUTH_USER_MODEL.\n\n```\nAUTH_USER_MODEL = 'accounts.User'\n```\n\n### I18N, L10N & TIME_ZONE setting\n\nChange the I18N, L10N, and TZ settings.\n\n```\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = True\n\nTIME_ZONE = \"Asia/Tokyo\" # Change to your local timezone\n```\n\n## When a profile model is used (specification of profile attributes)\n\nSet the attribute name of the profile model associated with the user model.\n\n```\nUSER_G11N_USERPROFILE_ATTRIBUTE_NAME = \"profile\"\n```\n\nIf the related_name is \"foobar\" in the OneToOneField to the user model specified in the profile model, change the value here to the following\n\n```\nUSER_G11N_USERPROFILE_ATTRIBUTE_NAME = \"foobar\"\n```\n\n\n## migrate\n\nMigration to adapt the changes.\n\n```\n$ ./manage.py makemigrations\n$ ./manage.py migrate\n```\n\n# Demo\n\nThe Docker configuration is provided. Please use the following command to start it. Go to [http://localhost:8000](http://localhost:8000) when the launch is complete.\n\n```\n$ docker-compose up\n```\n\n\n# AUTHORS\n\n[See this](https://github.com/salexkidd/django-user-g11n/blob/master/AUTHORS.md)\n\n\n# Release note\n\n- 2024/06/06: Remove Django2 and 3 support and Python 3.9\n",
"bugtrack_url": null,
"license": null,
"summary": "User g11n extension for Django",
"version": "0.4.4",
"project_urls": {
"Homepage": "https://github.com/salexkidd/django-user-g11n"
},
"split_keywords": [
"django",
" i18n",
" l10n",
" g11n",
" timezone"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d1436b303e6a608b13508a017bc7266f085c96182a80a16eed9cb5e690f2c257",
"md5": "36c8793cdb8342dec0665bdf34dabf82",
"sha256": "541283489ba2bc896f3e1fbf2731bacd2bd0937945705f8cd2b5679eaf77eb38"
},
"downloads": -1,
"filename": "django_user_g11n-0.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "36c8793cdb8342dec0665bdf34dabf82",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7138,
"upload_time": "2024-06-06T05:28:02",
"upload_time_iso_8601": "2024-06-06T05:28:02.695870Z",
"url": "https://files.pythonhosted.org/packages/d1/43/6b303e6a608b13508a017bc7266f085c96182a80a16eed9cb5e690f2c257/django_user_g11n-0.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82c24b95cdc118a13ee5262fee9bd8b8262f9feebdaabd3f97b7f96f4a06d27f",
"md5": "91ca6fab6705aa3af11b9c7201013ab7",
"sha256": "b9a0427e9bb34714f914972fffda06b813a95e07d8ccb950854c267381b29ccf"
},
"downloads": -1,
"filename": "django-user-g11n-0.4.4.tar.gz",
"has_sig": false,
"md5_digest": "91ca6fab6705aa3af11b9c7201013ab7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6992,
"upload_time": "2024-06-06T05:28:04",
"upload_time_iso_8601": "2024-06-06T05:28:04.891714Z",
"url": "https://files.pythonhosted.org/packages/82/c2/4b95cdc118a13ee5262fee9bd8b8262f9feebdaabd3f97b7f96f4a06d27f/django-user-g11n-0.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-06 05:28:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "salexkidd",
"github_project": "django-user-g11n",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"tox": true,
"lcname": "django-user-g11n"
}