How to use the orchestra.admin.utils.admin_link 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 / mailboxes / admin.py View on Github external
def display_forward(self, address):
        forward_mailboxes = {m.name: m for m in address.get_forward_mailboxes()}
        values = []
        for forward in address.forward.split():
            mbox = forward_mailboxes.get(forward)
            if mbox:
                values.append(admin_link()(mbox))
            else:
                values.append(forward)
        return '<br>'.join(values)
    display_forward.short_description = _("Forward")
github glic3rinu / django-orchestra / orchestra / contrib / orchestration / admin.py View on Github external
)
    list_display_links = ('id', 'backend')
    list_filter = ('state', 'server', 'backend', 'operations__action')
    search_fields = ('script',)
    date_hierarchy = 'created_at'
    inlines = (BackendOperationInline,)
    fields = (
        'backend', 'server_link', 'state', 'display_script', 'mono_stdout',
        'mono_stderr', 'mono_traceback', 'exit_code', 'task_id', 'display_created',
        'execution_time'
    )
    readonly_fields = fields
    actions = (retry_backend,)
    change_view_actions = actions
    
    server_link = admin_link('server')
    display_created = admin_date('created_at', short_description=_("Created"))
    display_state = admin_colored('state', colors=STATE_COLORS)
    display_script = display_code('script')
    mono_stdout = display_mono('stdout')
    mono_stderr = display_mono('stderr')
    mono_traceback = display_mono('traceback')
    
    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')
github glic3rinu / django-orchestra / orchestra / contrib / letsencrypt / actions.py View on Github external
def letsencrypt(modeladmin, request, queryset):
    wildcards = set()
    domains = set()
    content_error = ''
    contentless = queryset.exclude(content__path='/').distinct()
    if contentless:
        content_error = ungettext(
            ugettext("Selected website %s doesn't have a webapp mounted on <tt>/</tt>."),
            ugettext("Selected websites %s don't have a webapp mounted on <tt>/</tt>."),
            len(contentless),
        )
        content_error += ugettext("<br>Websites need a webapp (e.g. static) mounted on / "
                                  "for let's encrypt HTTP-01 challenge to work.")
        content_error = content_error % ', '.join((admin_link()(website) for website in contentless))
        content_error = '<ul class="errorlist"><li>%s</li></ul>' % content_error
    queryset = queryset.prefetch_related('domains')
    for website in queryset:
        for domain in website.domains.all():
            if domain.name.startswith('*.'):
                wildcards.add(domain.name)
            else:
                domains.add(domain.name)
    form = LetsEncryptForm(domains, wildcards, initial={'domains': '\n'.join(domains)})
    action_value = 'letsencrypt'
    if request.POST.get('post') == 'generic_confirmation':
        form = LetsEncryptForm(domains, wildcards, request.POST)
        if not content_error and form.is_valid():
            cleaned_data = form.cleaned_data
            domains = set(cleaned_data['domains'])
            operations = []
github glic3rinu / django-orchestra / orchestra / contrib / webapps / admin.py View on Github external
def display_websites(self, webapp):
        websites = []
        for content in webapp.content_set.all():
            site_url = content.get_absolute_url()
            site_link = get_on_site_link(site_url)
            website = content.website
            name = "%s on %s %s" % (website.name, content.path, site_link)
            link = admin_link(display=name)(website)
            websites.append(link)
        if not websites:
            add_url = reverse('admin:websites_website_add')
            add_url += '?account=%s' % webapp.account_id
            plus = '<strong style="color:green; font-size:12px">+</strong>'
            websites.append('<a href="%s">%s%s</a>' % (add_url, plus, ugettext("Add website")))
        return '<br>'.join(websites)
    display_websites.short_description = _("web sites")
github glic3rinu / django-orchestra / orchestra / contrib / orchestration / admin.py View on Github external
def instance_link(self, operation):
        link = admin_link('instance')(self, operation)
        if link == '---':
            return _("Deleted {0}").format(operation.instance_repr or '-'.join(
                (escape(operation.content_type), escape(operation.object_id))))
        return link
    instance_link.allow_tags = True
github glic3rinu / django-orchestra / orchestra / contrib / plans / admin.py View on Github external
num_contracts.admin_order_field = 'contracts__count'
    num_contracts.allow_tags = True
    
    def get_queryset(self, request):
        qs = super(PlanAdmin, self).get_queryset(request)
        return qs.annotate(models.Count('contracts', distinct=True))


class ContractedPlanAdmin(AccountAdminMixin, admin.ModelAdmin):
    list_display = ('id', 'plan_link', 'account_link')
    list_filter = ('plan__name',)
    list_select_related = ('plan', 'account')
    search_fields = ('account__username', 'plan__name', 'id')
    actions = (list_accounts,)
    
    plan_link = admin_link('plan')


admin.site.register(Plan, PlanAdmin)
admin.site.register(ContractedPlan, ContractedPlanAdmin)

insertattr(Service, 'inlines', RateInline)
github glic3rinu / django-orchestra / orchestra / contrib / issues / admin.py View on Github external
('queue', 'owner',),
                      ('state', 'priority'),
                      'description')
        }),
    )
    list_select_related = ('queue', 'owner', 'creator')
    
    class Media:
        css = {
            'all': ('issues/css/ticket-admin.css',)
        }
        js = (
            'issues/js/ticket-admin.js',
        )
    
    display_creator = admin_link('creator')
    display_queue = admin_link('queue')
    display_owner = admin_link('owner')
    updated = admin_date('updated_at')
    display_state = admin_colored('state', colors=STATE_COLORS, bold=False)
    display_priority = admin_colored('priority', colors=PRIORITY_COLORS, bold=False)
    
    def display_summary(self, ticket):
        context = {
            'creator': admin_link('creator')(self, ticket) if ticket.creator else ticket.creator_name,
            'created': admin_date('created_at')(ticket),
            'updated': '',
        }
        msg = ticket.messages.last()
        if msg:
            context.update({
                'updated': admin_date('created_at')(msg),
github glic3rinu / django-orchestra / orchestra / contrib / payments / admin.py View on Github external
actions.process_transactions, actions.mark_as_executed, actions.mark_as_secured,
        actions.mark_as_rejected, actions.reissue
    )
    search_fields = ('bill__number', 'bill__account__username', 'id')
    actions = change_view_actions + (actions.report, list_accounts,)
    filter_by_account_fields = ('bill', 'source')
    readonly_fields = (
        'bill_link', 'display_state', 'process_link', 'account_link', 'source_link',
        'display_created_at', 'display_modified_at'
    )
    list_select_related = ('source', 'bill__account', 'process')
    date_hierarchy = 'created_at'
    
    bill_link = admin_link('bill')
    source_link = admin_link('source')
    process_link = admin_link('process', short_description=_("proc"))
    account_link = admin_link('bill__account')
    display_created_at = admin_date('created_at', short_description=_("Created"))
    display_modified_at = admin_date('modified_at', short_description=_("Modified"))
    
    def has_delete_permission(self, *args, **kwargs):
        return False
    
    def get_actions(self, request):
        actions = super().get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions
    
    def get_change_readonly_fields(self, request, obj):
        if obj.state in (Transaction.WAITTING_PROCESSING, Transaction.WAITTING_EXECUTION):
            return ()
github glic3rinu / django-orchestra / orchestra / contrib / bills / admin.py View on Github external
actions = [
        actions.manage_lines, actions.download_bills, actions.close_bills, actions.send_bills,
        actions.amend_bills, actions.bill_report, actions.service_report,
        actions.close_send_download_bills, list_accounts,
    ]
    change_readonly_fields = ('account_link', 'type', 'is_open', 'amend_of_link')
    readonly_fields = (
        'number', 'display_total', 'is_sent', 'display_payment_state', 'created_on_display',
        'closed_on_display', 'updated_on_display', 'display_total_with_subtotals',
    )
    date_hierarchy = 'closed_on'
    
    created_on_display = admin_date('created_on', short_description=_("Created"))
    closed_on_display = admin_date('closed_on', short_description=_("Closed"))
    updated_on_display = admin_date('updated_on', short_description=_("Updated"))
    amend_of_link = admin_link('amend_of')
    
#    def amend_links(self, bill):
#        links = []
#        for amend in bill.amends.all():
#            url = reverse('admin:bills_bill_change', args=(amend.id,))
#            links.append('<a href="{url}">{num}</a>'.format(url=url, num=amend.number))
#        return '<br>'.join(links)
#    amend_links.short_description = _("Amends")
#    amend_links.allow_tags = True
    
    def num_lines(self, bill):
        return bill.lines__count
    num_lines.admin_order_field = 'lines__count'
    num_lines.short_description = _("lines")
    
    def display_total(self, bill):