django-orchestra/orchestra/contrib/lists/admin.py

60 lines
2.2 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.contrib import admin
from django.urls import re_path as url
2014-05-08 16:59:35 +00:00
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy as _
2014-05-08 16:59:35 +00:00
2014-10-15 12:47:28 +00:00
from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
2016-03-31 16:02:50 +00:00
from orchestra.admin.actions import disable, enable
2014-07-21 15:43:36 +00:00
from orchestra.admin.utils import admin_link
from orchestra.contrib.accounts.actions import list_accounts
2015-04-05 10:46:24 +00:00
from orchestra.contrib.accounts.admin import SelectAccountAdminMixin
2015-04-09 14:32:10 +00:00
from orchestra.contrib.accounts.filters import IsActiveListFilter
from orchestra.forms import UserCreationForm, NonStoredUserChangeForm
2014-05-08 16:59:35 +00:00
2016-02-23 11:49:10 +00:00
from . import settings
2016-03-14 10:40:11 +00:00
from .filters import HasCustomAddressListFilter
2014-05-08 16:59:35 +00:00
from .models import List
class ListAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
2015-04-09 14:32:10 +00:00
list_display = (
'name', 'address_name', 'address_domain_link', 'account_link', 'display_active'
)
2014-05-08 16:59:35 +00:00
add_fieldsets = (
(None, {
'classes': ('wide',),
2015-04-09 14:32:10 +00:00
'fields': ('account_link', 'name', 'is_active')
2014-05-08 16:59:35 +00:00
}),
(_("Address"), {
'classes': ('wide',),
'fields': (('address_name', 'address_domain'),)
}),
(_("Admin"), {
'classes': ('wide',),
'fields': ('admin_email',),
2014-05-08 16:59:35 +00:00
}),
)
fieldsets = (
(None, {
'classes': ('wide',),
2015-04-09 14:32:10 +00:00
'fields': ('account_link', 'name', 'is_active')
2014-05-08 16:59:35 +00:00
}),
(_("Address"), {
'classes': ('wide',),
2016-02-23 11:49:10 +00:00
'description': _("Additional address besides the default <name>@%s"
) % settings.LISTS_DEFAULT_DOMAIN,
2014-05-08 16:59:35 +00:00
'fields': (('address_name', 'address_domain'),)
}),
)
2014-11-18 13:59:21 +00:00
search_fields = ('name', 'address_name', 'address_domain__name', 'account__username')
2016-03-14 10:40:11 +00:00
list_filter = (IsActiveListFilter, HasCustomAddressListFilter)
2014-05-08 16:59:35 +00:00
readonly_fields = ('account_link',)
change_readonly_fields = ('name',)
2014-11-20 15:34:59 +00:00
list_select_related = ('account', 'address_domain',)
2014-05-08 16:59:35 +00:00
filter_by_account_fields = ['address_domain']
2016-03-31 16:02:50 +00:00
actions = (disable, enable, list_accounts)
2014-05-08 16:59:35 +00:00
2014-07-21 15:43:36 +00:00
address_domain_link = admin_link('address_domain', order='address_domain__name')
2014-05-08 16:59:35 +00:00
admin.site.register(List, ListAdmin)