-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from djangoindia/staging
Staging to Production - Jan 10, 2025
- Loading branch information
Showing
7 changed files
with
880 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
770 changes: 770 additions & 0 deletions
770
backend/djangoindia/db/migrations/0014_remove_update_created_by_user.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Python imports | ||
import uuid | ||
|
||
import pytz | ||
|
||
from django.contrib.auth.models import ( | ||
AbstractBaseUser, | ||
Group, | ||
Permission, | ||
PermissionsMixin, | ||
UserManager, | ||
) | ||
|
||
# Django imports | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class User(AbstractBaseUser, PermissionsMixin): | ||
class GENDER: | ||
CHOICES = ( | ||
("male", "male"), | ||
("female", "female"), | ||
("non-binary", "non-binary"), | ||
("not_to_specify", "not_to_specify"), | ||
) | ||
|
||
USER_TIMEZONE_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones)) | ||
|
||
username = models.CharField(max_length=128, unique=True) | ||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) | ||
|
||
# user fields | ||
mobile_number = models.CharField(max_length=255, blank=True, null=True) | ||
email = models.CharField(max_length=255, null=True, blank=True, unique=True) | ||
first_name = models.CharField(max_length=255, blank=True) | ||
last_name = models.CharField(max_length=255, blank=True) | ||
avatar = models.CharField(max_length=255, blank=True) | ||
organization = models.CharField(max_length=500, blank=True, null=True) | ||
gender = models.CharField(choices=GENDER.CHOICES, max_length=50) | ||
|
||
# tracking metrics | ||
created_at = models.DateTimeField(auto_now_add=True, verbose_name="Created At") | ||
updated_at = models.DateTimeField(auto_now=True, verbose_name="Last Modified At") | ||
|
||
# the is' es | ||
is_superuser = models.BooleanField(default=False) | ||
is_password_expired = models.BooleanField(default=False) | ||
is_active = models.BooleanField(default=True) | ||
is_staff = models.BooleanField(default=False) | ||
is_email_verified = models.BooleanField(default=False) | ||
is_password_autoset = models.BooleanField(default=False) | ||
is_onboarded = models.BooleanField(default=False) | ||
|
||
user_timezone = models.CharField( | ||
max_length=255, default="Asia/Kolkata", choices=USER_TIMEZONE_CHOICES | ||
) | ||
|
||
groups = models.ManyToManyField( | ||
Group, | ||
verbose_name=_("groups"), | ||
blank=True, | ||
help_text=_( | ||
"The groups this user belongs to. A user will get all permissions " | ||
"granted to each of their groups." | ||
), | ||
related_name="user_account_set", | ||
related_query_name="user_account", | ||
) | ||
user_permissions = models.ManyToManyField( | ||
Permission, | ||
verbose_name=_("user permissions"), | ||
blank=True, | ||
help_text=_("Specific permissions for this user."), | ||
related_name="user_account_set", | ||
related_query_name="user_account", | ||
) | ||
|
||
USERNAME_FIELD = "email" | ||
|
||
REQUIRED_FIELDS = ["username"] | ||
|
||
objects = UserManager() | ||
|
||
class Meta: | ||
verbose_name = "User" | ||
verbose_name_plural = "Users" | ||
db_table = "users" | ||
ordering = ("-created_at",) | ||
|
||
def __str__(self): | ||
return f"{self.username} <{self.email}>" | ||
|
||
def save(self, *args, **kwargs): | ||
self.email = self.email.lower().strip() | ||
|
||
if self.is_superuser: | ||
self.is_staff = True | ||
|
||
super().save(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters