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
|
2013-10-02 16:02:08 +00:00
|
|
|
|
|
|
|
from selectable.base import ModelLookup
|
2018-07-26 17:59:58 +00:00
|
|
|
from selectable.forms import AutoCompleteSelectWidget, AutoCompleteSelectField
|
2013-10-02 16:02:08 +00:00
|
|
|
from selectable.registry import registry
|
|
|
|
|
2018-07-26 17:59:58 +00:00
|
|
|
from . import models
|
2013-10-02 16:02:08 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
)
|
2013-10-02 16:02:08 +00:00
|
|
|
class Meta(object):
|
|
|
|
model = models.Library
|
2018-07-26 17:59:58 +00:00
|
|
|
widgets = {'group':forms.HiddenInput}
|
2013-10-10 06:41:50 +00:00
|
|
|
exclude = ('group', )
|
2018-07-26 17:59:58 +00:00
|
|
|
|
2018-12-07 19:51:25 +00:00
|
|
|
@register(models.Library)
|
2013-10-02 16:02:08 +00:00
|
|
|
class LibraryAdmin(ModelAdmin):
|
|
|
|
list_display = ('user', )
|
|
|
|
form = LibraryAdminForm
|
|
|
|
search_fields = ['user__username']
|
|
|
|
|
2018-12-07 19:51:25 +00:00
|
|
|
@register(models.Block)
|
2013-10-08 19:37:22 +00:00
|
|
|
class BlockAdmin(ModelAdmin):
|
|
|
|
list_display = ('library', 'lower', 'upper',)
|
2013-11-30 20:41:05 +00:00
|
|
|
search_fields = ('library__name', 'lower', 'upper',)
|
2013-10-02 16:02:08 +00:00
|
|
|
|
2018-12-07 19:51:25 +00:00
|
|
|
@register(models.CardPattern)
|
2013-10-10 06:41:50 +00:00
|
|
|
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',)
|
2016-11-09 20:24:11 +00:00
|
|
|
|
2018-12-07 19:51:25 +00:00
|
|
|
@register(models.BadUsernamePattern)
|
|
|
|
class EmailPatternAdmin(ModelAdmin):
|
|
|
|
list_display = ('pattern', 'last')
|