Skip to content

Commit b30a202

Browse files
committed
Add accounts app and update core templates/settings
1 parent efc7b11 commit b30a202

6 files changed

Lines changed: 194 additions & 88 deletions

File tree

BalkanPress/accounts/admin.py

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .models import AppUser
55

6+
67
# Register your models here.
78
@admin.register(AppUser)
89
class AppUserAdmin(UserAdmin):
@@ -32,20 +33,54 @@ class AppUserAdmin(UserAdmin):
3233
"last_name",
3334
)
3435

35-
ordering = (
36-
"username",
37-
)
36+
ordering = ("username",)
3837

3938
fieldsets = (
4039
(None, {"fields": ("username", "password")}),
41-
("Personal info", {"fields": ("first_name", "last_name", "email", "display_name", "bio", "avatar")}),
42-
("Permissions", {"fields": ("is_active", "is_staff", "is_superuser", "is_author", "groups", "user_permissions")}),
40+
(
41+
"Personal info",
42+
{
43+
"fields": (
44+
"first_name",
45+
"last_name",
46+
"email",
47+
"display_name",
48+
"bio",
49+
"avatar",
50+
)
51+
},
52+
),
53+
(
54+
"Permissions",
55+
{
56+
"fields": (
57+
"is_active",
58+
"is_staff",
59+
"is_superuser",
60+
"is_author",
61+
"groups",
62+
"user_permissions",
63+
)
64+
},
65+
),
4366
("Important dates", {"fields": ("last_login", "date_joined")}),
4467
)
4568

4669
add_fieldsets = (
47-
(None, {
48-
"classes": ("wide",),
49-
"fields": ("username", "password1", "password2", "email", "display_name", "is_author", "is_staff", "is_active"),
50-
}),
51-
)
70+
(
71+
None,
72+
{
73+
"classes": ("wide",),
74+
"fields": (
75+
"username",
76+
"password1",
77+
"password2",
78+
"email",
79+
"display_name",
80+
"is_author",
81+
"is_staff",
82+
"is_active",
83+
),
84+
},
85+
),
86+
)

BalkanPress/accounts/forms.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
UserModel = get_user_model()
99

10+
1011
class ProfileBaseForm(BootStrapModelForm):
1112
class Meta:
1213
model = UserModel
@@ -29,6 +30,7 @@ class Meta:
2930
"is_author": "Mark if you want to publish articles",
3031
}
3132

33+
3234
class RegisterForm(UserCreationForm):
3335
class Meta:
3436
model = UserModel
@@ -40,50 +42,33 @@ class Meta:
4042
"password2",
4143
)
4244
widgets = {
43-
"username": forms.TextInput(
44-
attrs={
45-
"placeholder": "Username"
46-
}
47-
),
48-
"email": forms.EmailInput(
49-
attrs={
50-
"placeholder": "Email"
51-
}
52-
),
53-
"display_name": forms.TextInput(
54-
attrs={
55-
"placeholder": "Display name"
56-
}
57-
),
45+
"username": forms.TextInput(attrs={"placeholder": "Username"}),
46+
"email": forms.EmailInput(attrs={"placeholder": "Email"}),
47+
"display_name": forms.TextInput(attrs={"placeholder": "Display name"}),
5848
}
5949

50+
6051
class LoginForm(AuthenticationForm):
6152
username = forms.CharField(
62-
widget=forms.TextInput(
63-
attrs={
64-
"autofocus": True,
65-
"placeholder": "Username"
66-
}
67-
)
53+
widget=forms.TextInput(attrs={"autofocus": True, "placeholder": "Username"})
6854
)
6955
password = forms.CharField(
7056
strip=False,
71-
widget=forms.PasswordInput(
72-
attrs={
73-
"placeholder": "Password"
74-
}
75-
),
57+
widget=forms.PasswordInput(attrs={"placeholder": "Password"}),
7658
)
7759

60+
7861
class LogoutForm(forms.Form):
7962
confirm = forms.BooleanField(
8063
required=True,
8164
label="I want to log out.",
8265
)
8366

67+
8468
class ProfileEditForm(ProfileBaseForm):
8569
pass
8670

71+
8772
class ProfileDeleteForm(ReadOnlyModelForm):
8873
confirmation = forms.BooleanField(
8974
required=True,
@@ -96,8 +81,4 @@ class Meta(ProfileBaseForm.Meta):
9681
pass
9782

9883
def clean_confirmation(self):
99-
return validate_confirmation(
100-
self.cleaned_data.get(
101-
"confirmation"
102-
)
103-
)
84+
return validate_confirmation(self.cleaned_data.get("confirmation"))

BalkanPress/accounts/migrations/0001_initial.py

Lines changed: 114 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,129 @@ class Migration(migrations.Migration):
1111
initial = True
1212

1313
dependencies = [
14-
('auth', '0012_alter_user_first_name_max_length'),
14+
("auth", "0012_alter_user_first_name_max_length"),
1515
]
1616

1717
operations = [
1818
migrations.CreateModel(
19-
name='AppUser',
19+
name="AppUser",
2020
fields=[
21-
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22-
('password', models.CharField(max_length=128, verbose_name='password')),
23-
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
24-
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
25-
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
26-
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
27-
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
28-
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
29-
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
30-
('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')),
31-
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
32-
('display_name', models.CharField(blank=True, max_length=150)),
33-
('is_author', models.BooleanField(default=False)),
34-
('bio', models.TextField(blank=True)),
35-
('avatar', models.ImageField(blank=True, null=True, upload_to='avatars/')),
36-
('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')),
37-
('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')),
21+
(
22+
"id",
23+
models.BigAutoField(
24+
auto_created=True,
25+
primary_key=True,
26+
serialize=False,
27+
verbose_name="ID",
28+
),
29+
),
30+
("password", models.CharField(max_length=128, verbose_name="password")),
31+
(
32+
"last_login",
33+
models.DateTimeField(
34+
blank=True, null=True, verbose_name="last login"
35+
),
36+
),
37+
(
38+
"is_superuser",
39+
models.BooleanField(
40+
default=False,
41+
help_text="Designates that this user has all permissions without explicitly assigning them.",
42+
verbose_name="superuser status",
43+
),
44+
),
45+
(
46+
"username",
47+
models.CharField(
48+
error_messages={
49+
"unique": "A user with that username already exists."
50+
},
51+
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
52+
max_length=150,
53+
unique=True,
54+
validators=[
55+
django.contrib.auth.validators.UnicodeUsernameValidator()
56+
],
57+
verbose_name="username",
58+
),
59+
),
60+
(
61+
"first_name",
62+
models.CharField(
63+
blank=True, max_length=150, verbose_name="first name"
64+
),
65+
),
66+
(
67+
"last_name",
68+
models.CharField(
69+
blank=True, max_length=150, verbose_name="last name"
70+
),
71+
),
72+
(
73+
"email",
74+
models.EmailField(
75+
blank=True, max_length=254, verbose_name="email address"
76+
),
77+
),
78+
(
79+
"is_staff",
80+
models.BooleanField(
81+
default=False,
82+
help_text="Designates whether the user can log into this admin site.",
83+
verbose_name="staff status",
84+
),
85+
),
86+
(
87+
"is_active",
88+
models.BooleanField(
89+
default=True,
90+
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
91+
verbose_name="active",
92+
),
93+
),
94+
(
95+
"date_joined",
96+
models.DateTimeField(
97+
default=django.utils.timezone.now, verbose_name="date joined"
98+
),
99+
),
100+
("display_name", models.CharField(blank=True, max_length=150)),
101+
("is_author", models.BooleanField(default=False)),
102+
("bio", models.TextField(blank=True)),
103+
(
104+
"avatar",
105+
models.ImageField(blank=True, null=True, upload_to="avatars/"),
106+
),
107+
(
108+
"groups",
109+
models.ManyToManyField(
110+
blank=True,
111+
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
112+
related_name="user_set",
113+
related_query_name="user",
114+
to="auth.group",
115+
verbose_name="groups",
116+
),
117+
),
118+
(
119+
"user_permissions",
120+
models.ManyToManyField(
121+
blank=True,
122+
help_text="Specific permissions for this user.",
123+
related_name="user_set",
124+
related_query_name="user",
125+
to="auth.permission",
126+
verbose_name="user permissions",
127+
),
128+
),
38129
],
39130
options={
40-
'verbose_name': 'user',
41-
'verbose_name_plural': 'users',
42-
'abstract': False,
131+
"verbose_name": "user",
132+
"verbose_name_plural": "users",
133+
"abstract": False,
43134
},
44135
managers=[
45-
('objects', django.contrib.auth.models.UserManager()),
136+
("objects", django.contrib.auth.models.UserManager()),
46137
],
47138
),
48139
]

BalkanPress/accounts/urls.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
from django.urls import path, include
1+
from django.urls import include, path
22

3-
from .views import (
4-
RegisterView,
5-
LoginView,
6-
LogoutView,
7-
ProfileView,
8-
ProfileEditView,
9-
ProfileDeleteView,
10-
UserListView,
11-
AdminUserDeleteView,
12-
)
3+
from .views import (AdminUserDeleteView, LoginView, LogoutView,
4+
ProfileDeleteView, ProfileEditView, ProfileView,
5+
RegisterView, UserListView)
136

147
app_name = "accounts"
158

@@ -30,4 +23,4 @@
3023
path("logout/", LogoutView.as_view(), name="logout"),
3124
path("profile/", include(profile_patterns)),
3225
path("users/", include(user_admin_patterns)),
33-
]
26+
]

0 commit comments

Comments
 (0)