Skip to content

Commit

Permalink
Merge pull request #13 from ryaustin/dir-structure-redo
Browse files Browse the repository at this point in the history
Dir structure redo
  • Loading branch information
gm3dmo authored Sep 20, 2023
2 parents c510079 + 48df3d2 commit 2ca7e7c
Show file tree
Hide file tree
Showing 42 changed files with 380 additions and 539 deletions.
File renamed without changes.
50 changes: 50 additions & 0 deletions cmp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser


class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
list_display = (
"email",
"is_staff",
"is_active",
)
list_filter = (
"email",
"is_staff",
"is_active",
)
fieldsets = (
(None, {"fields": ("email", "password")}),
(
"Permissions",
{"fields": ("is_staff", "is_active", "groups", "user_permissions")},
),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": (
"email",
"password1",
"password2",
"is_staff",
"is_active",
"groups",
"user_permissions",
),
},
),
)
search_fields = ("email",)
ordering = ("email",)


admin.site.register(CustomUser, CustomUserAdmin)
6 changes: 6 additions & 0 deletions cmp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CmpConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "cmp"
15 changes: 15 additions & 0 deletions cmp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib.auth.forms import UserCreationForm, UserChangeForm

from .models import CustomUser


class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
fields = ("email",)


class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
fields = ("email",)
2 changes: 1 addition & 1 deletion cmpm__/core/managers.py → cmp/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CustomUserManager(BaseUserManager):
Custom user model manager where email is the unique identifiers
for authentication instead of usernames.
"""

def create_user(self, email, password, **extra_fields):
"""
Create and save a user with the given email and password.
Expand All @@ -19,7 +20,6 @@ def create_user(self, email, password, **extra_fields):
user.save()
return user


def create_superuser(self, email, password, **extra_fields):
"""
Create and save a SuperUser with the given email and password.
Expand Down
111 changes: 111 additions & 0 deletions cmp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Generated by Django 4.2.5 on 2023-09-20 13:51

from django.db import migrations, models
import django.utils.timezone


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",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
),
(
"is_staff",
models.BooleanField(
default=False,
help_text="Designates whether the user can log into this admin site.",
verbose_name="staff status",
),
),
(
"is_active",
models.BooleanField(
default=True,
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
verbose_name="active",
),
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
),
(
"email",
models.EmailField(
max_length=254, unique=True, verbose_name="email address"
),
),
(
"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": "user",
"verbose_name_plural": "users",
"abstract": False,
},
),
]
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions core/tests/test_users.py → cmp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class UsersManagersTests(TestCase):

def test_create_user(self):
User = get_user_model()
user = User.objects.create_user(email="[email protected]", password="foo")
Expand All @@ -26,7 +25,9 @@ def test_create_user(self):

def test_create_superuser(self):
User = get_user_model()
admin_user = User.objects.create_superuser(email="[email protected]", password="foo")
admin_user = User.objects.create_superuser(
email="[email protected]", password="foo"
)
self.assertEqual(admin_user.email, "[email protected]")
self.assertTrue(admin_user.is_active)
self.assertTrue(admin_user.is_staff)
Expand All @@ -39,4 +40,5 @@ def test_create_superuser(self):
pass
with self.assertRaises(ValueError):
User.objects.create_superuser(
email="[email protected]", password="foo", is_superuser=False)
email="[email protected]", password="foo", is_superuser=False
)
File renamed without changes.
16 changes: 0 additions & 16 deletions cmpm__/cmp/asgi.py

This file was deleted.

127 changes: 0 additions & 127 deletions cmpm__/cmp/settings.py

This file was deleted.

22 changes: 0 additions & 22 deletions cmpm__/cmp/urls.py

This file was deleted.

Loading

0 comments on commit 2ca7e7c

Please sign in to comment.