khaganat-web/neluser/admin.py

42 lines
1.3 KiB
Python
Raw Permalink Normal View History

2019-07-24 16:45:09 +00:00
from django.utils.translation import ugettext_lazy as _
2018-01-27 20:06:40 +00:00
from django.contrib import admin
2019-07-24 16:45:09 +00:00
from .models import NelUser
from .views import send_activation_email
2018-01-27 20:06:40 +00:00
2019-07-24 16:45:09 +00:00
class NelUserAdmin(admin.ModelAdmin):
2019-07-24 17:07:41 +00:00
list_display = (
"email",
"date_joined",
"last_login",
"is_active",
"is_staff",
"is_superuser",
)
readonly_fields = ("date_joined", "last_login")
list_filter = ("is_active", "is_staff", "is_superuser")
search_fields = ("email",)
2019-07-24 16:45:09 +00:00
fieldsets = [
2019-07-24 17:07:41 +00:00
(_("info"), {"fields": ["is_active", "email", "date_joined", "last_login"]}),
(
_("user_permissions"),
{"fields": ["is_staff", "is_superuser", "groups", "user_permissions"]},
),
(_("misc"), {"fields": ["nsfw_allowed"]}),
2019-07-24 16:45:09 +00:00
]
2019-07-24 17:07:41 +00:00
actions = ["resend_activation_link"]
2019-07-24 16:45:09 +00:00
def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
send_activation_email(request, obj)
def resend_activation_link(self, request, queryset):
for user in queryset:
if not user.is_active:
send_activation_email(request, user)
2019-07-24 17:07:41 +00:00
resend_activation_link.short_description = _("resend_activation_link")
2019-07-24 16:45:09 +00:00
admin.site.register(NelUser, NelUserAdmin)