
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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.
Core idea is See the Django documentation for more information
Install the package from pypi
$ pip install django-user-g11n
Next, choose one of the following two implementation methods
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
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",
)
Create an application for custom users. Please refer to the Django documentation for more information. See the Django documentation for more information
$ 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
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
)
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
]
Change or add the AUTH_USER_MODEL.
AUTH_USER_MODEL = 'accounts.User'
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
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"
Migration to adapt the changes.
$ ./manage.py makemigrations
$ ./manage.py migrate
The Docker configuration is provided. Please use the following command to start it. Go to http://localhost:8000 when the launch is complete.
$ docker-compose up
FAQs
User g11n extension for Django
We found that django-user-g11n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.