regluit/libraryauth/admin.py

57 lines
1.6 KiB
Python
Raw Normal View History

2018-07-26 17:59:58 +00:00
from django import forms
2018-12-07 19:51:25 +00:00
from django.contrib.admin import ModelAdmin, site, register
2018-07-26 17:59:58 +00:00
from django.contrib.auth.models import User
from selectable.base import ModelLookup
2018-07-26 17:59:58 +00:00
from selectable.forms import AutoCompleteSelectWidget, AutoCompleteSelectField
from selectable.registry import registry
2018-07-26 17:59:58 +00:00
from . import models
class UserLookup(ModelLookup):
model = User
search_fields = ('username__icontains',)
registry.register(UserLookup)
class LibraryAdminForm(forms.ModelForm):
user = AutoCompleteSelectField(
2018-07-26 17:59:58 +00:00
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
2013-11-30 20:41:05 +00:00
owner = AutoCompleteSelectField(
2018-07-26 17:59:58 +00:00
UserLookup,
widget=AutoCompleteSelectWidget(UserLookup),
required=True,
)
class Meta(object):
model = models.Library
2018-07-26 17:59:58 +00:00
widgets = {'group':forms.HiddenInput}
exclude = ('group', )
2018-07-26 17:59:58 +00:00
2018-12-07 19:51:25 +00:00
@register(models.Library)
class LibraryAdmin(ModelAdmin):
list_display = ('user', )
form = LibraryAdminForm
search_fields = ['user__username']
2018-12-07 19:51:25 +00:00
@register(models.Block)
class BlockAdmin(ModelAdmin):
list_display = ('library', 'lower', 'upper',)
2013-11-30 20:41:05 +00:00
search_fields = ('library__name', 'lower', 'upper',)
2018-12-07 19:51:25 +00:00
@register(models.CardPattern)
class CardPatternAdmin(ModelAdmin):
list_display = ('library', 'pattern', 'checksum',)
2013-11-30 20:41:05 +00:00
search_fields = ('library__name', )
2013-10-11 02:31:31 +00:00
2018-12-07 19:51:25 +00:00
@register(models.EmailPattern)
2013-10-11 02:31:31 +00:00
class EmailPatternAdmin(ModelAdmin):
list_display = ('library', 'pattern', )
2013-11-30 20:41:05 +00:00
search_fields = ('library__name',)
2018-12-07 19:51:25 +00:00
@register(models.BadUsernamePattern)
class EmailPatternAdmin(ModelAdmin):
list_display = ('pattern', 'last')