Added convenient list filters
This commit is contained in:
parent
d39e742809
commit
ec0c319ad4
4
TODO.md
4
TODO.md
|
@ -430,8 +430,6 @@ mkhomedir_helper or create ssh homes with bash.rc and such
|
|||
# Automatically re-run backends until success? only timedout executions?
|
||||
# TODO save serialized versions ob backendoperation.instance in order to allow backend reexecution of deleted objects
|
||||
|
||||
# websites active list_display
|
||||
# account for account.is_active on service is_active filters like systemusers
|
||||
|
||||
# upgrade to django 1.9 and make margins wider
|
||||
# lets encrypt: DNS vs HTTP challange
|
||||
|
@ -440,5 +438,3 @@ mkhomedir_helper or create ssh homes with bash.rc and such
|
|||
|
||||
# Warning websites with ssl options without https protocol
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,16 +21,10 @@ class HasMainUserListFilter(SimpleListFilter):
|
|||
return queryset.filter(users__isnull=True).distinct()
|
||||
|
||||
|
||||
class IsActiveListFilter(SimpleListFilter):
|
||||
title = _("Is active")
|
||||
class IsActiveListFilter(HasMainUserListFilter):
|
||||
title = _("is active")
|
||||
parameter_name = 'active'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
('True', _("True")),
|
||||
('False', _("False")),
|
||||
)
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value() == 'True':
|
||||
return queryset.filter(is_active=True, account__is_active=True)
|
||||
|
|
|
@ -41,12 +41,6 @@ class HasAddressFilter(HasWebsiteFilter):
|
|||
title = _("has addresses")
|
||||
parameter_name = 'has_addresses'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
('True', _("True")),
|
||||
('False', _("False")),
|
||||
)
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value() == 'True':
|
||||
return queryset.filter(addresses__isnull=False)
|
||||
|
|
|
@ -35,7 +35,7 @@ def letsencrypt(modeladmin, request, queryset):
|
|||
encrypt_domains.add(domain)
|
||||
website.encrypt_domains = encrypt_domains
|
||||
operations.extend(Operation.create_for_action(website, 'encrypt'))
|
||||
modeladmin.log_change(request, request.user, _("Encrypted!"))
|
||||
modeladmin.log_change(request, website, _("Encrypted!"))
|
||||
if not operations:
|
||||
messages.error(request, _("No backend operation has been executed."))
|
||||
else:
|
||||
|
|
|
@ -11,6 +11,7 @@ from orchestra.contrib.accounts.admin import SelectAccountAdminMixin
|
|||
from orchestra.contrib.accounts.filters import IsActiveListFilter
|
||||
|
||||
from . import settings
|
||||
from .filters import HasCustomAddressListFilter
|
||||
from .forms import ListCreationForm, ListChangeForm
|
||||
from .models import List
|
||||
|
||||
|
@ -50,7 +51,7 @@ class ListAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedModel
|
|||
}),
|
||||
)
|
||||
search_fields = ('name', 'address_name', 'address_domain__name', 'account__username')
|
||||
list_filter = (IsActiveListFilter,)
|
||||
list_filter = (IsActiveListFilter, HasCustomAddressListFilter)
|
||||
readonly_fields = ('account_link',)
|
||||
change_readonly_fields = ('name',)
|
||||
form = ListChangeForm
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
from django.contrib.admin import SimpleListFilter
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
class HasCustomAddressListFilter(SimpleListFilter):
|
||||
""" Filter addresses whether they have any webapp or not """
|
||||
title = _("has custom address")
|
||||
parameter_name = 'has_custom_address'
|
||||
|
||||
def lookups(self, request, model_admin):
|
||||
return (
|
||||
('True', _("True")),
|
||||
('False', _("False")),
|
||||
)
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value() == 'True':
|
||||
return queryset.exclude(address_name='')
|
||||
elif self.value() == 'False':
|
||||
return queryset.filter(address_name='')
|
||||
return queryset
|
|
@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from orchestra.admin import ExtendedModelAdmin
|
||||
from orchestra.admin.utils import admin_link
|
||||
from orchestra.contrib.accounts.admin import AccountAdminMixin
|
||||
from orchestra.contrib.accounts.filters import IsActiveListFilter
|
||||
from orchestra.plugins import PluginModelAdapter
|
||||
from orchestra.plugins.admin import SelectPluginAdminMixin
|
||||
from orchestra.utils.python import import_class
|
||||
|
@ -26,7 +27,7 @@ class MiscServiceAdmin(ExtendedModelAdmin):
|
|||
'name', 'verbose_name', 'num_instances', 'has_identifier', 'has_amount', 'is_active'
|
||||
)
|
||||
list_editable = ('is_active',)
|
||||
list_filter = ('has_identifier', 'has_amount', 'is_active')
|
||||
list_filter = ('has_identifier', 'has_amount', IsActiveListFilter)
|
||||
fields = (
|
||||
'verbose_name', 'name', 'description', 'has_identifier', 'has_amount', 'is_active'
|
||||
)
|
||||
|
@ -55,7 +56,7 @@ class MiscServiceAdmin(ExtendedModelAdmin):
|
|||
|
||||
class MiscellaneousAdmin(AccountAdminMixin, SelectPluginAdminMixin, admin.ModelAdmin):
|
||||
list_display = (
|
||||
'__str__', 'service_link', 'amount', 'dispaly_active', 'account_link', 'is_active'
|
||||
'__str__', 'service_link', 'amount', 'account_link', 'dispaly_active'
|
||||
)
|
||||
list_filter = ('service__name', 'is_active')
|
||||
list_select_related = ('service', 'account')
|
||||
|
|
|
@ -10,11 +10,12 @@ from orchestra.admin.actions import disable
|
|||
from orchestra.admin.utils import admin_link, change_url
|
||||
from orchestra.contrib.accounts.actions import list_accounts
|
||||
from orchestra.contrib.accounts.admin import AccountAdminMixin, SelectAccountAdminMixin
|
||||
from orchestra.contrib.accounts.filters import IsActiveListFilter
|
||||
from orchestra.forms.widgets import DynamicHelpTextSelect
|
||||
from orchestra.utils.html import get_on_site_link
|
||||
|
||||
from .directives import SiteDirective
|
||||
from .filters import HasWebAppsListFilter
|
||||
from .filters import HasWebAppsListFilter, HasDomainsFilter
|
||||
from .forms import WebsiteAdminForm, WebsiteDirectiveInlineFormSet
|
||||
from .models import Content, Website, WebsiteDirective
|
||||
|
||||
|
@ -56,8 +57,12 @@ class ContentInline(AccountAdminMixin, admin.TabularInline):
|
|||
|
||||
|
||||
class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
|
||||
list_display = ('name', 'display_domains', 'display_webapps', 'account_link')
|
||||
list_filter = ('protocol', 'is_active', HasWebAppsListFilter)
|
||||
list_display = (
|
||||
'name', 'display_domains', 'display_webapps', 'account_link', 'display_active'
|
||||
)
|
||||
list_filter = (
|
||||
'protocol', IsActiveListFilter, HasWebAppsListFilter, HasDomainsFilter
|
||||
)
|
||||
change_readonly_fields = ('name',)
|
||||
inlines = [ContentInline, WebsiteDirectiveInline]
|
||||
filter_horizontal = ['domains']
|
||||
|
|
|
@ -19,3 +19,16 @@ class HasWebAppsListFilter(SimpleListFilter):
|
|||
elif self.value() == 'False':
|
||||
return queryset.filter(content__isnull=True)
|
||||
return queryset
|
||||
|
||||
|
||||
class HasDomainsFilter(HasWebAppsListFilter):
|
||||
""" Filter addresses whether they have any domains or not """
|
||||
title = _("has domains")
|
||||
parameter_name = 'has_domains'
|
||||
|
||||
def queryset(self, request, queryset):
|
||||
if self.value() == 'True':
|
||||
return queryset.filter(domains__isnull=False)
|
||||
elif self.value() == 'False':
|
||||
return queryset.filter(domains__isnull=True)
|
||||
return queryset
|
||||
|
|
Loading…
Reference in New Issue