How to use the orchestra.admin.ExtendedModelAdmin function in orchestra

To help you get started, we’ve selected a few orchestra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glic3rinu / django-orchestra / orchestra / contrib / orchestration / admin.py View on Github external
class Media:
        css = {
            'all': ('orchestra/css/pygments/github.css',)
        }
    
    def get_queryset(self, request):
        """ Order by structured name and imporve performance """
        qs = super(BackendLogAdmin, self).get_queryset(request)
        return qs.select_related('server').defer('script', 'stdout')
    
    def has_add_permission(self, *args, **kwargs):
        return False


class ServerAdmin(ExtendedModelAdmin):
    list_display = ('name', 'address', 'os', 'display_ping', 'display_uptime')
    list_filter = ('os',)
    actions = (orchestrate,)
    change_view_actions = actions
    
    def display_ping(self, instance):
        return self._remote_state[instance.pk][0]
    display_ping.short_description = _("Ping")
    display_ping.allow_tags = True
    
    def display_uptime(self, instance):
        return self._remote_state[instance.pk][1]
    display_uptime.short_description = _("Uptime")
    display_uptime.allow_tags = True
    
    def get_queryset(self, request):
github glic3rinu / django-orchestra / orchestra / contrib / payments / admin.py View on Github external
Transaction.WAITTING_PROCESSING: 'darkorange',
    Transaction.WAITTING_EXECUTION: 'magenta',
    Transaction.EXECUTED: 'olive',
    Transaction.SECURED: 'green',
    Transaction.REJECTED: 'red',
}

PROCESS_STATE_COLORS = {
    TransactionProcess.CREATED: 'blue',
    TransactionProcess.EXECUTED: 'olive',
    TransactionProcess.ABORTED: 'red',
    TransactionProcess.COMMITED: 'green',
}


class PaymentSourceAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin):
    list_display = ('label', 'method', 'number', 'account_link', 'is_active')
    list_filter = ('method', 'is_active')
    change_readonly_fields = ('method',)
    search_fields = ('account__username', 'account__full_name', 'data')
    plugin = PaymentMethod
    plugin_field = 'method'


class TransactionInline(admin.TabularInline):
    model = Transaction
    can_delete = False
    extra = 0
    fields = (
        'transaction_link', 'bill_link', 'source_link', 'display_state',
        'amount', 'currency'
    )
github glic3rinu / django-orchestra / orchestra / contrib / resources / admin.py View on Github external
ct_id = resource_models[rel.related_model]
            except KeyError:
                pass
            else:
                manager = getattr(obj, field)
                ids = manager.values_list('id', flat=True)
                qset = Q(qset) | Q(content_type_id=ct_id, object_id__in=ids, resource__is_active=True)
        related = ResourceData.objects.filter(qset)
        related_ids = related.values_list('id', flat=True)
        related_ids = ','.join(map(str, related_ids))
        url = reverse('admin:resources_resourcedata_changelist')
        url += '?id__in=%s' % related_ids
        return redirect(url)


class MonitorDataAdmin(ExtendedModelAdmin):
    list_display = ('id', 'monitor', content_object_link, 'display_created', 'value')
    list_filter = ('monitor', ResourceDataListFilter)
    add_fields = ('monitor', 'content_type', 'object_id', 'created_at', 'value')
    fields = ('monitor', 'content_type', content_object_link, 'display_created', 'value', 'state')
    change_readonly_fields = fields
    list_select_related = ('content_type',)
    search_fields = ('content_object_repr',)
    date_hierarchy = 'created_at'
    
    display_created = admin_date('created_at', short_description=_("Created"))
    
    def filter_used_monitordata(self, request, queryset):
        query_string = parse_qs(request.META['QUERY_STRING'])
        resource_data = query_string.get('resource_data')
        if resource_data:
            mdata = ResourceData.objects.get(pk=int(resource_data[0]))
github glic3rinu / django-orchestra / orchestra / contrib / orders / admin.py View on Github external
def get_queryset(self, request):
        qs = super(MetricStorageInline, self).get_queryset(request)
        change_view = bool(self.parent_object and self.parent_object.pk)
        if change_view:
            qs = qs.order_by('-id')
            parent_id = self.parent_object.pk
            try:
                tenth_id = qs.filter(order_id=parent_id).values_list('id', flat=True)[9]
            except IndexError:
                pass
            else:
                return qs.filter(pk__gte=tenth_id)
        return qs


class OrderAdmin(AccountAdminMixin, ExtendedModelAdmin):
    list_display = (
        'display_description', 'service_link', 'account_link', 'content_object_link',
        'display_registered_on', 'display_billed_until', 'display_cancelled_on',
        'display_metric'
    )
    list_filter = (
        ActiveOrderListFilter, IgnoreOrderListFilter, BilledOrderListFilter, 'account__type',
        'service',
    )
    default_changelist_filters = (
        ('ignore', '0'),
    )
    actions = (
        BillSelectedOrders(), mark_as_ignored, mark_as_not_ignored, report, list_accounts
    )
    change_view_actions = (BillSelectedOrders(), mark_as_ignored, mark_as_not_ignored)
github glic3rinu / django-orchestra / orchestra / contrib / mailer / admin.py View on Github external
from .actions import last
from .engine import send_pending
from .models import Message, SMTPLog


COLORS = {
    Message.QUEUED: 'purple',
    Message.SENT: 'green',
    Message.DEFERRED: 'darkorange',
    Message.FAILED: 'red',
    SMTPLog.SUCCESS: 'green',
    SMTPLog.FAILURE: 'red',
}


class MessageAdmin(ExtendedModelAdmin):
    list_display = (
        'display_subject', 'colored_state', 'priority', 'to_address', 'from_address',
        'created_at_delta', 'display_retries', 'last_try_delta',
    )
    list_filter = ('state', 'priority', 'retries')
    list_prefetch_related = ('logs',)
    search_fields = ('to_address', 'from_address', 'subject',)
    fieldsets = (
        (None, {
            'fields': ('state', 'priority', ('retries', 'last_try_delta', 'created_at_delta'),
                       'display_full_subject', 'display_from', 'display_to',
                       'display_content'),
        }),
        (_("Edit"), {
            'classes': ('collapse',),
            'fields': ('subject', 'from_address', 'to_address', 'content'),
github glic3rinu / django-orchestra / orchestra / contrib / payments / admin.py View on Github external
display_state = admin_colored('state', colors=STATE_COLORS)
    
    class Media:
        css = {
            'all': ('orchestra/css/hide-inline-id.css',)
        }
    
    def has_add_permission(self, *args, **kwargs):
        return False
    
    def get_queryset(self, *args, **kwargs):
        qs = super().get_queryset(*args, **kwargs)
        return qs.select_related('source', 'bill')


class TransactionAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
    list_display = (
        'id', 'bill_link', 'account_link', 'source_link', 'display_created_at',
        'display_modified_at', 'display_state', 'amount', 'process_link'
    )
    list_filter = ('source__method', 'state')
    fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': (
                'account_link',
                'bill_link',
                'source_link',
                'display_state',
                'amount',
                'currency',
                'process_link'
github glic3rinu / django-orchestra / orchestra / apps / systemusers / admin.py View on Github external
from django.utils.safestring import mark_safe

from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
from orchestra.admin.utils import wrap_admin_view
from orchestra.apps.accounts.admin import SelectAccountAdminMixin
from orchestra.apps.accounts.filters import IsActiveListFilter
from orchestra.forms import UserCreationForm, UserChangeForm

from . import settings
from .actions import grant_permission, delete_selected
from .filters import IsMainListFilter
from .forms import SystemUserCreationForm, SystemUserChangeForm
from .models import SystemUser


class SystemUserAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedModelAdmin):
    list_display = (
        'username', 'account_link', 'shell', 'display_home', 'display_active', 'display_main'
    )
    list_filter = (IsActiveListFilter, 'shell', IsMainListFilter)
    fieldsets = (
        (None, {
            'fields': ('username', 'password', 'account_link', 'is_active')
        }),
        (_("System"), {
            'fields': ('shell', ('home', 'directory'), 'groups'),
        }),
    )
    add_fieldsets = (
        (None, {
            'fields': ('account_link', 'username', 'password1', 'password2')
        }),
github glic3rinu / django-orchestra / orchestra / contrib / databases / admin.py View on Github external
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _

from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
from orchestra.admin.utils import change_url
from orchestra.contrib.accounts.actions import list_accounts
from orchestra.contrib.accounts.admin import SelectAccountAdminMixin

from .filters import HasUserListFilter, HasDatabaseListFilter
from .forms import DatabaseCreationForm, DatabaseUserChangeForm, DatabaseUserCreationForm
from .models import Database, DatabaseUser


class DatabaseAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
    list_display = ('name', 'type', 'display_users', 'account_link')
    list_filter = ('type', HasUserListFilter)
    search_fields = ('name', 'account__username')
    change_readonly_fields = ('name', 'type')
    extra = 1
    fieldsets = (
        (None, {
            'classes': ('extrapretty',),
            'fields': ('account_link', 'name', 'type', 'users', 'display_users'),
        }),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('account_link', 'name', 'type')
        }),
github glic3rinu / django-orchestra / orchestra / contrib / saas / admin.py View on Github external
from orchestra.admin import ExtendedModelAdmin, ChangePasswordAdminMixin
from orchestra.admin.actions import disable, enable
from orchestra.admin.utils import change_url
from orchestra.contrib.accounts.actions import list_accounts
from orchestra.contrib.accounts.admin import AccountAdminMixin
from orchestra.contrib.accounts.filters import IsActiveListFilter
from orchestra.plugins.admin import SelectPluginAdminMixin
from orchestra.utils.apps import isinstalled
from orchestra.utils.html import get_on_site_link

from .filters import CustomURLListFilter
from .models import SaaS
from .services import SoftwareService


class SaaSAdmin(SelectPluginAdminMixin, ChangePasswordAdminMixin, AccountAdminMixin, ExtendedModelAdmin):
    list_display = ('name', 'service', 'display_url', 'account_link', 'display_active')
    list_filter = ('service', IsActiveListFilter, CustomURLListFilter)
    search_fields = ('name', 'account__username')
    change_readonly_fields = ('service',)
    plugin = SoftwareService
    plugin_field = 'service'
    plugin_title = 'Software as a Service'
    actions = (disable, enable, list_accounts)
    
    def display_url(self, saas):
        site_domain = saas.get_site_domain()
        site_link = '<a href="http://%s">%s</a>' % (site_domain, site_domain)
        links = [site_link]
        if saas.custom_url and isinstalled('orchestra.contrib.websites'):
            try:
                website = saas.service_instance.get_website()
github glic3rinu / django-orchestra / orchestra / apps / websites / admin.py View on Github external
extra = 1
    fields = ('webapp', 'webapp_link', 'webapp_type', 'path')
    readonly_fields = ('webapp_link', 'webapp_type')
    filter_by_account_fields = ['webapp']
    
    webapp_link = admin_link('webapp', popup=True)
    webapp_link.short_description = _("Web App")
    
    def webapp_type(self, content):
        if not content.pk:
            return ''
        return content.webapp.get_type_display()
    webapp_type.short_description = _("Web App type")


class WebsiteAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
    list_display = ('name', 'display_domains', 'display_webapps', 'account_link')
    list_filter = ('protocol', 'is_active',)
    change_readonly_fields = ('name',)
    inlines = [ContentInline, WebsiteDirectiveInline]
    filter_horizontal = ['domains']
    fieldsets = (
        (None, {
            'classes': ('extrapretty',),
            'fields': ('account_link', 'name', 'protocol', 'domains', 'is_active'),
        }),
    )
    form = WebsiteAdminForm
    filter_by_account_fields = ['domains']
    list_prefetch_related = ('domains', 'content_set__webapp')
    search_fields = ('name', 'account__username', 'domains__name')