From 73344af48499f29bcb49e9fedf78dc396976b4b0 Mon Sep 17 00:00:00 2001 From: Riad Elimemmedov Date: Thu, 15 Feb 2024 10:29:37 +0400 Subject: [PATCH] Changes some migration --- .vscode/settings.json | 6 + backend/abstract/constants.py | 9 ++ .../user_profile/migrations/0001_initial.py | 120 ++++++++++++++++++ .../user_profile/migrations/0002_initial.py | 28 ++++ .../user_profile}/migrations/__init__.py | 0 backend/apps/users/admin.py | 6 +- backend/apps/users/migrations/0001_initial.py | 106 ++++++++++++++++ backend/apps/users/migrations/__init__.py | 0 backend/apps/users/models.py | 25 +++- backend/poetry.lock | 16 ++- backend/pyproject.toml | 1 + commands.md | 2 +- 12 files changed, 312 insertions(+), 7 deletions(-) create mode 100644 backend/apps/user_profile/migrations/0001_initial.py create mode 100644 backend/apps/user_profile/migrations/0002_initial.py rename backend/{abstract => apps/user_profile}/migrations/__init__.py (100%) create mode 100644 backend/apps/users/migrations/0001_initial.py create mode 100644 backend/apps/users/migrations/__init__.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 0a016c7..d6c8e57 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,10 @@ "--line-length",//how long to be each line our code,well know we limited our code length each line when formatting code using black "120",//length each line ], + "[javascript]": { + "editor.formatOnSave": false + }, + "[javascriptreact]": { + "editor.formatOnSave": false + } } diff --git a/backend/abstract/constants.py b/backend/abstract/constants.py index 64a4dd6..4bdbede 100644 --- a/backend/abstract/constants.py +++ b/backend/abstract/constants.py @@ -17,3 +17,12 @@ class AppName(Enum): # !Genders Genders = [("MALE", _("male")), ("FEMALE", _("female"))] + +# !Genders Pet +GendersPet = [ + ("MALE", _("male")), + ("FEMALE", _("female")), + ("Neutered ", _("neutered ")), + ("Spayed", _("spayed")), + ("Other", _("other")), +] diff --git a/backend/apps/user_profile/migrations/0001_initial.py b/backend/apps/user_profile/migrations/0001_initial.py new file mode 100644 index 0000000..adf8d47 --- /dev/null +++ b/backend/apps/user_profile/migrations/0001_initial.py @@ -0,0 +1,120 @@ +# Generated by Django 5.0.1 on 2024-02-15 05:18 + +import django_extensions.db.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Profile", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "slug", + models.SlugField( + blank=True, editable=False, unique=True, verbose_name="Slug" + ), + ), + ( + "first_name", + models.CharField( + blank=True, max_length=150, null=True, verbose_name="First name" + ), + ), + ( + "last_name", + models.CharField( + blank=True, max_length=150, null=True, verbose_name="Last name" + ), + ), + ( + "full_name", + models.CharField( + blank=True, max_length=150, verbose_name="Full name" + ), + ), + ( + "profile_key", + django_extensions.db.fields.RandomCharField( + blank=True, + editable=False, + length=12, + unique=True, + verbose_name="Profile key", + ), + ), + ( + "country", + models.CharField(blank=True, max_length=50, verbose_name="Country"), + ), + ( + "city", + models.CharField( + blank=True, max_length=50, null=True, verbose_name="City" + ), + ), + ( + "adress", + models.CharField( + blank=True, max_length=50, null=True, verbose_name="Adress" + ), + ), + ( + "additional_information", + models.TextField(blank=True, verbose_name="Additional Information"), + ), + ( + "is_active", + models.BooleanField(default=False, verbose_name="Is active"), + ), + ( + "account_type", + models.CharField( + choices=[("ADMIN", "admin"), ("GENERAL", "general")], + default="GENERAL", + max_length=20, + null=True, + verbose_name="Account type", + ), + ), + ( + "status", + models.CharField( + choices=[("ACTIVE", "active"), ("INACTIVE", "inactive")], + default="INACTIVE", + max_length=20, + null=True, + verbose_name="Status", + ), + ), + ( + "gender", + models.CharField( + blank=True, + choices=[("MALE", "male"), ("FEMALE", "female")], + max_length=20, + null=True, + verbose_name="Gender", + ), + ), + ], + options={ + "verbose_name": "Profile", + "verbose_name_plural": "Profiles", + }, + ), + ] diff --git a/backend/apps/user_profile/migrations/0002_initial.py b/backend/apps/user_profile/migrations/0002_initial.py new file mode 100644 index 0000000..e7fa4b5 --- /dev/null +++ b/backend/apps/user_profile/migrations/0002_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.1 on 2024-02-15 05:18 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("user_profile", "0001_initial"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name="profile", + name="user", + field=models.OneToOneField( + null=True, + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + verbose_name="User", + ), + ), + ] diff --git a/backend/abstract/migrations/__init__.py b/backend/apps/user_profile/migrations/__init__.py similarity index 100% rename from backend/abstract/migrations/__init__.py rename to backend/apps/user_profile/migrations/__init__.py diff --git a/backend/apps/users/admin.py b/backend/apps/users/admin.py index 826f7f0..4b9df0a 100644 --- a/backend/apps/users/admin.py +++ b/backend/apps/users/admin.py @@ -12,18 +12,22 @@ class CustomUserAdmin(UserAdmin): add_form = CustomUserCreationForm form = CustomUserChangeForm model = CustomUser + list_display_links = ["id", "email", "wallet_address"] list_display = ( + "id", "email", + "wallet_address", "is_staff", "is_active", ) list_filter = ( "email", + "wallet_address", "is_staff", "is_active", ) fieldsets = ( - (None, {"fields": ("email", "password")}), + (None, {"fields": ("email", "wallet_address", "password")}), ( "Permissions", {"fields": ("is_staff", "is_active", "groups", "user_permissions")}, diff --git a/backend/apps/users/migrations/0001_initial.py b/backend/apps/users/migrations/0001_initial.py new file mode 100644 index 0000000..3da6508 --- /dev/null +++ b/backend/apps/users/migrations/0001_initial.py @@ -0,0 +1,106 @@ +# Generated by Django 5.0.1 on 2024-02-15 05:29 + +import django.utils.timezone +from django.db import migrations, models + +import config.helpers + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("auth", "0012_alter_user_first_name_max_length"), + ] + + operations = [ + migrations.CreateModel( + name="CustomUser", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("password", models.CharField(max_length=128, verbose_name="password")), + ( + "last_login", + models.DateTimeField( + blank=True, null=True, verbose_name="last login" + ), + ), + ( + "is_superuser", + models.BooleanField( + default=False, + help_text="Designates that this user has all permissions without explicitly assigning them.", + verbose_name="superuser status", + ), + ), + ( + "email", + models.EmailField( + max_length=254, unique=True, verbose_name="Email address" + ), + ), + ( + "wallet_address", + models.CharField( + blank=True, + db_index=True, + max_length=100, + null=True, + unique=True, + validators=[config.helpers.is_valid_wallet_address], + verbose_name="Wallet address", + ), + ), + ( + "is_staff", + models.BooleanField(default=False, verbose_name="Is staff"), + ), + ( + "is_active", + models.BooleanField(default=True, verbose_name="Is active"), + ), + ( + "date_joined", + models.DateTimeField( + default=django.utils.timezone.now, verbose_name="Date joined" + ), + ), + ( + "groups", + models.ManyToManyField( + 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_set", + related_query_name="user", + to="auth.group", + verbose_name="groups", + ), + ), + ( + "user_permissions", + models.ManyToManyField( + blank=True, + help_text="Specific permissions for this user.", + related_name="user_set", + related_query_name="user", + to="auth.permission", + verbose_name="user permissions", + ), + ), + ], + options={ + "verbose_name": "Custom user", + "verbose_name_plural": "Custom users", + "ordering": ["-date_joined"], + }, + ), + ] diff --git a/backend/apps/users/migrations/__init__.py b/backend/apps/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/apps/users/models.py b/backend/apps/users/models.py index da5bbf0..5ec9bfc 100644 --- a/backend/apps/users/models.py +++ b/backend/apps/users/models.py @@ -1,8 +1,11 @@ from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin +from django.core.validators import RegexValidator from django.db import models from django.utils import timezone from django.utils.translation import gettext_lazy as _ +from config.helpers import is_valid_wallet_address + from .managers import CustomUserManager # Create your models here. @@ -11,15 +14,29 @@ # !CustomUser class CustomUser(AbstractBaseUser, PermissionsMixin): username = None - email = models.EmailField(_("email address"), unique=True) - is_staff = models.BooleanField(default=False) - is_active = models.BooleanField(default=True) - date_joined = models.DateTimeField(default=timezone.now) + email = models.EmailField(_("Email address"), unique=True) + wallet_address = models.CharField( + _("Wallet address"), + unique=True, + db_index=True, + max_length=100, + blank=True, + null=True, + validators=[is_valid_wallet_address], + ) + is_staff = models.BooleanField(_("Is staff"), default=False) + is_active = models.BooleanField(_("Is active"), default=True) + date_joined = models.DateTimeField(_("Date joined"), default=timezone.now) USERNAME_FIELD = "email" REQUIRED_FIELDS = [] objects = CustomUserManager() + class Meta: + verbose_name = _("Custom user") + verbose_name_plural = _("Custom users") + ordering = ["-date_joined"] + def __str__(self): return self.email diff --git a/backend/poetry.lock b/backend/poetry.lock index 285e056..20d35f1 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -335,6 +335,20 @@ files = [ {file = "django_cleanup-8.1.0-py2.py3-none-any.whl", hash = "sha256:7903873ea73b3f7e61e055340d27dba49b70634f60c87a573ad748e172836458"}, ] +[[package]] +name = "django-colorfield" +version = "0.11.0" +description = "color field for django models with a nice color-picker in the admin." +optional = false +python-versions = "*" +files = [ + {file = "django-colorfield-0.11.0.tar.gz", hash = "sha256:05c38c8eb2a94938b810a19b2011846391a4ce71d1c92e88a35974fbcc8fc62e"}, + {file = "django_colorfield-0.11.0-py3-none-any.whl", hash = "sha256:460f40e6123b6ae0fb51a4eb86fc258fcdc0ea28f75102b685e8209b1eae9ec3"}, +] + +[package.dependencies] +Pillow = ">=9.0.0" + [[package]] name = "django-extensions" version = "3.2.3" @@ -1481,4 +1495,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "3.10" -content-hash = "2d66f9effe2ebd02884c70bc1c377526e7181963c7c0382d9b51b4cf0d2337f7" +content-hash = "880b2879df382b0ebda72ce72e3dfb5edc235466e40b2632f26b7c2a771a8696" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index bc6ad27..62e37b0 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -26,6 +26,7 @@ feedparser = "^6.0.11" pre-commit = "^3.6.0" pytest-factoryboy = "^2.6.0" pytest-django = "^4.8.0" +django-colorfield = "^0.11.0" [tool.poetry.group.dev.dependencies] diff --git a/commands.md b/commands.md index 9b0c6ca..ecf4c12 100644 --- a/commands.md +++ b/commands.md @@ -39,7 +39,7 @@ Backend - `poetry run pytest --cov=./ --cov-report=html` - Check code formatting is needed or not: - `poetry run black . --check` -- Sort imports using isort with Black profile: +- Sor t imports using isort with Black profile: - `poetry run isort . --profile black` - Check code style with Flake8: - `poetry run flake8 .`