65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
from .models import User, UserProfile, LoginAttempt, EmailVerification
|
|
|
|
|
|
@admin.register(User)
|
|
class UserAdmin(BaseUserAdmin):
|
|
"""Custom User admin."""
|
|
|
|
list_display = ('email', 'username', 'first_name', 'last_name', 'is_verified', 'is_active', 'date_joined')
|
|
list_filter = ('is_verified', 'is_active', 'is_staff', 'is_superuser', 'date_joined')
|
|
search_fields = ('email', 'username', 'first_name', 'last_name')
|
|
ordering = ('-date_joined',)
|
|
|
|
fieldsets = (
|
|
(None, {'fields': ('email', 'username', 'password')}),
|
|
('Personal info', {'fields': ('first_name', 'last_name', 'avatar')}),
|
|
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
|
|
('Email Settings', {'fields': (
|
|
'smtp_host', 'smtp_port', 'smtp_username', 'smtp_use_tls',
|
|
'imap_host', 'imap_port', 'imap_username', 'imap_use_ssl'
|
|
)}),
|
|
('Important dates', {'fields': ('last_login', 'date_joined')}),
|
|
('Security', {'fields': ('is_verified', 'last_login_ip')}),
|
|
)
|
|
|
|
add_fieldsets = (
|
|
(None, {
|
|
'classes': ('wide',),
|
|
'fields': ('email', 'username', 'first_name', 'last_name', 'password1', 'password2'),
|
|
}),
|
|
)
|
|
|
|
|
|
@admin.register(UserProfile)
|
|
class UserProfileAdmin(admin.ModelAdmin):
|
|
"""User Profile admin."""
|
|
|
|
list_display = ('user', 'timezone', 'language', 'theme', 'auto_reply_enabled')
|
|
list_filter = ('timezone', 'language', 'theme', 'auto_reply_enabled')
|
|
search_fields = ('user__email', 'user__username')
|
|
raw_id_fields = ('user',)
|
|
|
|
|
|
@admin.register(LoginAttempt)
|
|
class LoginAttemptAdmin(admin.ModelAdmin):
|
|
"""Login Attempt admin."""
|
|
|
|
list_display = ('email', 'ip_address', 'success', 'failure_reason', 'timestamp')
|
|
list_filter = ('success', 'timestamp')
|
|
search_fields = ('email', 'ip_address')
|
|
readonly_fields = ('timestamp',)
|
|
ordering = ('-timestamp',)
|
|
|
|
|
|
@admin.register(EmailVerification)
|
|
class EmailVerificationAdmin(admin.ModelAdmin):
|
|
"""Email Verification admin."""
|
|
|
|
list_display = ('user', 'token', 'is_used', 'created_at', 'expires_at')
|
|
list_filter = ('is_used', 'created_at', 'expires_at')
|
|
search_fields = ('user__email', 'token')
|
|
readonly_fields = ('token', 'created_at')
|
|
raw_id_fields = ('user',)
|