tildetown-admin/ttadmin/users/admin.py

36 lines
1.1 KiB
Python
Raw Permalink Normal View History

2016-11-20 05:34:38 +00:00
from django.contrib import admin
2017-01-14 06:22:28 +00:00
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
2017-01-14 06:34:08 +00:00
from .models import Townie, Pubkey
2017-11-09 21:58:57 +00:00
from common.social import post_users_to_social
2016-11-20 05:34:38 +00:00
2017-01-14 06:34:08 +00:00
class PubkeyInline(admin.TabularInline):
model = Pubkey
2017-01-21 09:06:35 +00:00
extra = 1
2017-01-14 06:34:08 +00:00
2019-07-16 01:38:11 +00:00
def bulk_accept(madmin, req, qs):
for townie in qs:
2019-07-16 01:38:11 +00:00
townie.state = 'accepted'
townie.save()
2017-11-09 21:58:57 +00:00
post_users_to_social(qs)
2019-07-16 01:38:11 +00:00
bulk_accept.short_description = 'mark selected townies as accepted'
def bulk_reject(madmin, req, qs):
for townie in qs:
townie.state = 'rejected'
townie.save()
bulk_reject.short_description = 'mark selected townies as rejected'
2016-11-20 05:34:38 +00:00
@admin.register(Townie)
class TownieAdmin(admin.ModelAdmin):
2017-01-14 06:34:08 +00:00
inlines = [PubkeyInline]
2019-07-16 01:38:11 +00:00
list_display = ('username', 'state', 'email')
2019-07-10 16:27:29 +00:00
readonly_fields = ('reasons', 'plans', 'socials')
2019-07-16 01:38:11 +00:00
ordering = ('state',)
2017-11-10 23:00:22 +00:00
exclude = ('first_name', 'last_name', 'password', 'groups', 'user_permissions', 'last_login', 'is_staff', 'is_active', 'is_superuser')
2019-07-16 01:38:11 +00:00
actions = (bulk_accept, bulk_reject,)
2017-01-21 09:25:02 +00:00
search_fields = ('username', 'email', 'displayname')