from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin as StockUserAdmin
from django.contrib.auth.models import User as UserType
from ..vote import models
from ..vote.elfs import is_elf
User = get_user_model()
[docs]
class UserAdmin(StockUserAdmin):
list_display = (
'username',
'display_name',
'email',
'is_elf',
'is_staff',
'is_superuser',
'has_usable_password',
)
[docs]
@admin.display()
def display_name(self, obj: UserType) -> str:
return obj.profile.display_name
[docs]
@admin.display(boolean=True)
def is_elf(self, obj: UserType) -> bool:
return is_elf(obj)
[docs]
@admin.display(boolean=True)
def has_usable_password(self, obj: UserType) -> bool:
return obj.has_usable_password()
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
[docs]
class ShowAdmin(admin.ModelAdmin):
list_display = ('showtime', 'end', 'voting_allowed')
[docs]
class UserBadgeAdmin(admin.ModelAdmin):
list_display = ('profile', 'twitter_user', 'badge')
list_filter = ('profile', 'twitter_user', 'badge')
[docs]
class VoteAdmin(admin.ModelAdmin):
list_display = ('__str__', 'date', 'vote_kind')
list_filter = ('kind', 'twitter_user')
filter_horizontal = ('tracks',)
[docs]
class TrackAdmin(admin.ModelAdmin):
list_display = ('id3_title', 'id3_artist')
[docs]
class PlayAdmin(admin.ModelAdmin):
list_display = ('track', 'date')
[docs]
class BlockAdmin(admin.ModelAdmin):
list_display = ('track', 'reason', 'show')
[docs]
class DiscardShortlistAdmin(admin.ModelAdmin):
list_display = ('track', 'show')
[docs]
class ProfileAdmin(admin.ModelAdmin):
list_display = ('__str__', 'is_patron', 'is_abuser')
[docs]
@admin.display()
def username(self, obj: models.Profile) -> str:
return obj.user.username
[docs]
class RequestAdmin(admin.ModelAdmin):
list_display = ('created', 'filled_by', 'claimant', 'submitted_by')
list_filter = ('filled_by', 'claimant', 'submitted_by')
[docs]
class NoteAdmin(admin.ModelAdmin):
list_display = ('track', 'show', 'public', 'content')
[docs]
class UserTrackListAdmin(admin.ModelAdmin):
list_display = ('__str__', 'slug', 'user', 'public')
list_filter = ('public',)
admin.site.register(models.Show, ShowAdmin)
admin.site.register(models.TwitterUser, TwitterUserAdmin)
admin.site.register(models.UserBadge, UserBadgeAdmin)
admin.site.register(models.Track, TrackAdmin)
admin.site.register(models.Vote, VoteAdmin)
admin.site.register(models.Play, PlayAdmin)
admin.site.register(models.Block, BlockAdmin)
admin.site.register(models.Shortlist, DiscardShortlistAdmin)
admin.site.register(models.Discard, DiscardShortlistAdmin)
admin.site.register(models.Profile, ProfileAdmin)
admin.site.register(models.Request, RequestAdmin)
admin.site.register(models.Note, NoteAdmin)
admin.site.register(models.UserTrackList, UserTrackListAdmin)