add filter servers on accounts and mailboxes to send messages
This commit is contained in:
parent
2666b47213
commit
a6ef81ad8f
|
@ -26,12 +26,13 @@ from .actions import (list_contacts, service_report, delete_related_services, di
|
||||||
enable_selected)
|
enable_selected)
|
||||||
from .forms import AccountCreationForm
|
from .forms import AccountCreationForm
|
||||||
from .models import Account
|
from .models import Account
|
||||||
|
from .filters import HasTipeServerFilter
|
||||||
|
|
||||||
|
|
||||||
class AccountAdmin(ChangePasswordAdminMixin, auth.UserAdmin, ExtendedModelAdmin):
|
class AccountAdmin(ChangePasswordAdminMixin, auth.UserAdmin, ExtendedModelAdmin):
|
||||||
list_display = ('username', 'full_name', 'type', 'is_active')
|
list_display = ('username', 'full_name', 'type', 'is_active')
|
||||||
list_filter = (
|
list_filter = (
|
||||||
'type', 'is_active',
|
'type', 'is_active', HasTipeServerFilter
|
||||||
)
|
)
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(_("User"), {
|
(_("User"), {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from django.contrib.admin import SimpleListFilter
|
from django.contrib.admin import SimpleListFilter
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from orchestra.contrib.orchestration.models import Server
|
||||||
|
from orchestra.contrib.websites.models import Website
|
||||||
|
from orchestra.settings import WEB_SERVERS
|
||||||
|
|
||||||
class IsActiveListFilter(SimpleListFilter):
|
class IsActiveListFilter(SimpleListFilter):
|
||||||
title = _("is active")
|
title = _("is active")
|
||||||
|
@ -25,3 +27,16 @@ class IsActiveListFilter(SimpleListFilter):
|
||||||
elif self.value() == 'object':
|
elif self.value() == 'object':
|
||||||
return queryset.filter(is_active=False)
|
return queryset.filter(is_active=False)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
class HasTipeServerFilter(SimpleListFilter):
|
||||||
|
title = _("has type server")
|
||||||
|
parameter_name = 'has_servers'
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return [ (x.id, x.name) for x in Server.objects.filter(name__in=WEB_SERVERS) ]
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
if self.value() is not None:
|
||||||
|
serverWebsites = Website.objects.filter(target_server=self.value())
|
||||||
|
return queryset.filter(id__in=[ x.account.id for x in serverWebsites ] )
|
||||||
|
return queryset
|
|
@ -20,7 +20,7 @@ from orchestra.core import caches
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
from .actions import SendMailboxEmail, SendAddressEmail
|
from .actions import SendMailboxEmail, SendAddressEmail
|
||||||
from .filters import HasMailboxListFilter, HasForwardListFilter, HasAddressListFilter
|
from .filters import HasMailboxListFilter, HasForwardListFilter, HasAddressListFilter, HasTipeServerFilter
|
||||||
from .forms import MailboxCreationForm, MailboxChangeForm, AddressForm
|
from .forms import MailboxCreationForm, MailboxChangeForm, AddressForm
|
||||||
from .models import Mailbox, Address, Autoresponse
|
from .models import Mailbox, Address, Autoresponse
|
||||||
from .widgets import OpenCustomFilteringOnSelect
|
from .widgets import OpenCustomFilteringOnSelect
|
||||||
|
@ -40,7 +40,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
|
||||||
list_display = (
|
list_display = (
|
||||||
'name', 'account_link', 'display_filtering', 'display_addresses', 'display_active',
|
'name', 'account_link', 'display_filtering', 'display_addresses', 'display_active',
|
||||||
)
|
)
|
||||||
list_filter = (IsActiveListFilter, HasAddressListFilter, 'filtering')
|
list_filter = (IsActiveListFilter, HasAddressListFilter, 'filtering', HasTipeServerFilter)
|
||||||
search_fields = (
|
search_fields = (
|
||||||
'account__username', 'account__short_name', 'account__full_name', 'name',
|
'account__username', 'account__short_name', 'account__full_name', 'name',
|
||||||
'addresses__name', 'addresses__domain__name',
|
'addresses__name', 'addresses__domain__name',
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django.contrib.admin import SimpleListFilter
|
from django.contrib.admin import SimpleListFilter
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from orchestra.contrib.orchestration.models import Server
|
||||||
|
from orchestra.contrib.websites.models import Website
|
||||||
|
from orchestra.settings import WEB_SERVERS
|
||||||
|
|
||||||
class HasMailboxListFilter(SimpleListFilter):
|
class HasMailboxListFilter(SimpleListFilter):
|
||||||
""" Filter addresses whether they have any mailbox or not """
|
""" Filter addresses whether they have any mailbox or not """
|
||||||
|
@ -45,3 +47,17 @@ class HasAddressListFilter(HasMailboxListFilter):
|
||||||
elif self.value() == 'False':
|
elif self.value() == 'False':
|
||||||
return queryset.filter(addresses__isnull=True)
|
return queryset.filter(addresses__isnull=True)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
class HasTipeServerFilter(SimpleListFilter):
|
||||||
|
title = _("has type server")
|
||||||
|
parameter_name = 'has_servers'
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return [ (x.id, x.name) for x in Server.objects.filter(name__in=WEB_SERVERS) ]
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
if self.value() is not None:
|
||||||
|
serverWebsites = Website.objects.filter(target_server=self.value())
|
||||||
|
return queryset.filter(account__in=[ x.account.id for x in serverWebsites ] )
|
||||||
|
return queryset
|
|
@ -58,7 +58,7 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin)
|
||||||
list_display = (
|
list_display = (
|
||||||
'name', 'display_type', 'display_detail', 'display_websites', 'account_link', 'target_server',
|
'name', 'display_type', 'display_detail', 'display_websites', 'account_link', 'target_server',
|
||||||
)
|
)
|
||||||
list_filter = ('type', HasWebsiteListFilter, DetailListFilter)
|
list_filter = ('type', HasWebsiteListFilter, DetailListFilter, 'target_server')
|
||||||
inlines = [WebAppOptionInline]
|
inlines = [WebAppOptionInline]
|
||||||
readonly_fields = ('account_link',)
|
readonly_fields = ('account_link',)
|
||||||
change_readonly_fields = ('name', 'type', 'display_websites', 'display_sftpuser', 'target_server',)
|
change_readonly_fields = ('name', 'type', 'display_websites', 'display_sftpuser', 'target_server',)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
|
||||||
'name', 'display_domains', 'display_webapps', 'account_link', 'target_server', 'display_active'
|
'name', 'display_domains', 'display_webapps', 'account_link', 'target_server', 'display_active'
|
||||||
)
|
)
|
||||||
list_filter = (
|
list_filter = (
|
||||||
'protocol', IsActiveListFilter, HasWebAppsListFilter, HasDomainsFilter
|
'protocol', IsActiveListFilter, HasWebAppsListFilter, HasDomainsFilter, 'target_server'
|
||||||
)
|
)
|
||||||
change_readonly_fields = ('name',)
|
change_readonly_fields = ('name',)
|
||||||
inlines = (ContentInline, WebsiteDirectiveInline)
|
inlines = (ContentInline, WebsiteDirectiveInline)
|
||||||
|
|
Loading…
Reference in New Issue