2014-05-08 16:59:35 +00:00
|
|
|
from django.contrib import admin
|
2023-10-24 16:59:02 +00:00
|
|
|
from django.urls import re_path as url
|
2014-05-08 16:59:35 +00:00
|
|
|
from django.contrib.auth.admin import UserAdmin
|
2023-10-24 16:59:02 +00:00
|
|
|
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
|
2015-07-21 10:44:32 +00:00
|
|
|
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
|
2016-04-15 09:56:10 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-09-01 15:47:43 +00:00
|
|
|
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',),
|
2023-09-01 15:47:43 +00:00
|
|
|
'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)
|