mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
Having this as a model field is "annoying" because each added language will trigger a (potentially costly) migration even though no real database work is actually done for it. Also implements a selector that shows languages in both their own language and the currently activated language. Correct spelling to "zh-hans" (lowercase); see https://stackoverflow.com/a/7729311 See #161
52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
import secrets
|
||
|
||
from django.db import models
|
||
from django.contrib.auth.models import AbstractUser
|
||
from django.conf import settings
|
||
from django.utils.translation import gettext_lazy as _
|
||
|
||
class User(AbstractUser):
|
||
# > If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the default
|
||
# > User model is sufficient for you. This model behaves identically to the default user model, but you’ll be able
|
||
# > to customize it in the future if the need arises
|
||
|
||
# (The above is no longer the only reason for a custom User model, since we started introducing custom fields.
|
||
# Regarding those fields, there is some pressure in the docs to put UserProfile fields in a separate model, but
|
||
# as long as the number of fields is small I think the User model makes more sense. We can always push them out
|
||
# later)
|
||
|
||
send_email_alerts = models.BooleanField(default=True, blank=True)
|
||
|
||
THEME_CHOICES = [
|
||
("system", _("System Default")),
|
||
("light", _("Light")),
|
||
("dark", _("Dark")),
|
||
]
|
||
theme_preference = models.CharField(
|
||
max_length=10,
|
||
choices=THEME_CHOICES,
|
||
default="system",
|
||
blank=False,
|
||
)
|
||
language = models.CharField(
|
||
max_length=10,
|
||
# choices intentionally not set, we don't want changes to trigger migrations; the actual choices are set in
|
||
# forms.py; in Django 5.0 and up we can instead used a callable here
|
||
# choices=...
|
||
default="auto",
|
||
blank=False,
|
||
)
|
||
|
||
class Meta:
|
||
db_table = 'auth_user'
|
||
|
||
|
||
class EmailVerification(models.Model):
|
||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||
email = models.EmailField() # redundant, but future-proof for when we allow multiple emails per user
|
||
token = models.CharField(max_length=64, default=secrets.token_urlsafe, blank=False, null=False)
|
||
created_at = models.DateTimeField(auto_now_add=True)
|
||
|
||
def __str__(self):
|
||
return f"{self.user} ({self.email})"
|