-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.py
103 lines (89 loc) · 2.64 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin, GroupAdmin
from django.contrib.admin.forms import AdminAuthenticationForm
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import Group
from gpauth.forms import UserChangeForm, UserCreationForm
from gpauth.models import User, GpPermission, GpGroup
from django.utils.translation import gettext_lazy as _
admin.site.site_header = settings.SITE_HEADER
admin.site.site_title = settings.SITE_TITLE
admin.site.index_title = settings.INDEX_TITLE
admin.site.site_url = None
AuthenticationForm.base_fields["username"].widget.attrs["autocomplete"] = "off"
AuthenticationForm.base_fields["password"].widget.attrs["autocomplete"] = "off"
AdminAuthenticationForm.base_fields["username"].widget.attrs["autocomplete"] = "off"
AdminAuthenticationForm.base_fields["password"].widget.attrs["autocomplete"] = "off"
admin.site.unregister(Group)
@admin.register(User)
class UserCustomAdmin(UserAdmin):
form = UserChangeForm
add_form = UserCreationForm
list_display = (
"email",
"get_full_name",
"is_superuser",
"is_staff",
"is_active",
)
list_display_links = list_display
list_filter = (
"is_superuser",
"is_active",
"is_staff",
)
fieldsets = (
(None, {"fields": ("email", "name", "password", "photo")}),
(
_("Permissions"),
{
"fields": (
"is_superuser",
"is_staff",
"is_active",
"groups",
"user_permissions",
)
},
),
(
_("Important dates"),
{
"fields": (
"date_joined",
"last_login",
)
},
),
)
add_fieldsets = (
(
None,
{
"fields": (
"email",
"name",
"password1",
"password2",
)
},
),
)
search_fields = ("email",)
ordering = ("name",)
filter_horizontal = ["user_permissions"]
list_per_page = 30
@admin.register(GpPermission)
class PermissionAdmin(admin.ModelAdmin):
list_display = ("name", "content_type", "codename")
list_display_links = list_display
search_fields = (
"name",
"content_type__app_label",
"content_type__model",
"codename",
)
@admin.register(GpGroup)
class GroupAdmin(GroupAdmin):
pass