From 56a16f9690e40d530bbc8d3fb85414acd4c26d14 Mon Sep 17 00:00:00 2001 From: Robert Stein Date: Tue, 9 May 2017 15:04:04 +0200 Subject: [PATCH] Dasboard initiated ------------------ - display amount of issues at top (3xx, 4xx, 5xx and bad configured) - removed action dropdown - adds button to start link analysis --- cmsplugin_filer_link2/admin.py | 37 +++++++ .../cmsplugin_filer_link/change_list.html | 101 ++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 cmsplugin_filer_link2/templates/admin/cmsplugin_filer_link/change_list.html diff --git a/cmsplugin_filer_link2/admin.py b/cmsplugin_filer_link2/admin.py index a657ea81..c02547a2 100644 --- a/cmsplugin_filer_link2/admin.py +++ b/cmsplugin_filer_link2/admin.py @@ -1,9 +1,12 @@ # -*- coding: utf-8 -*- +from django.conf.urls import url from django.contrib import admin +from django.shortcuts import redirect from django.utils.safestring import mark_safe from django.utils.translation import activate from django.utils.translation import ugettext as _ +from cmsplugin_filer_link2.management.commands import check_links from .models import LinkHealthState @@ -11,12 +14,46 @@ class LinkStateAdmin(admin.ModelAdmin): list_display = ('link_name', 'link_to', 'state', 'on_page', 'detected') list_filter = ('state',) + change_list_template = 'admin/cmsplugin_filer_link/change_list.html' + + def changelist_view(self, request, extra_context=None): + context = { + 'not_found_errors': LinkHealthState.objects.filter(state=LinkHealthState.NOT_REACHABLE), + 'server_errors': LinkHealthState.objects.filter(state=LinkHealthState.SERVER_ERROR), + 'redirected_links': LinkHealthState.objects.filter(state=LinkHealthState.REDIRECT), + 'bad_configured_links': LinkHealthState.objects.filter(state=LinkHealthState.BAD_CONFIGURED), + 'error_count': LinkHealthState.objects.all().count() + } + context.update(extra_context or {}) + return super(LinkStateAdmin, self).changelist_view(request, context) + def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False + def get_actions(self, request): + actions = super(LinkStateAdmin, self).get_actions(request) + if 'delete_selected' in actions: + del actions['delete_selected'] + return actions + + def get_urls(self): + urlpatterns = super(LinkStateAdmin, self).get_urls() + + link_health_state_custom_urls = [ + url(r'^update-health-states/$', self.admin_site.admin_view(self.update_health_states), + name='%s_%s_update_health_state' % (self.model._meta.app_label, self.model._meta.model_name)) + ] + + return link_health_state_custom_urls + urlpatterns + + def update_health_states(self, request): + cmd = check_links.Command() + cmd.handle() + return redirect('admin:%s_%s_changelist' % (self.model._meta.app_label, self.model._meta.model_name)) + def link_name(self, obj): return obj.link link_name.allow_tags = True diff --git a/cmsplugin_filer_link2/templates/admin/cmsplugin_filer_link/change_list.html b/cmsplugin_filer_link2/templates/admin/cmsplugin_filer_link/change_list.html new file mode 100644 index 00000000..2f2aac01 --- /dev/null +++ b/cmsplugin_filer_link2/templates/admin/cmsplugin_filer_link/change_list.html @@ -0,0 +1,101 @@ +{% extends 'admin/change_list.html' %} +{% load i18n %} + +{% block extrastyle %} + {{ block.super }} + +{% endblock %} + +{% block content_title %} +

+ {% trans 'Welcome to you link health state dashboard!' %} +

+{% endblock %} + +{% block content %} + {# Short error overview report. #} + {% if error_count %} +
+ {% blocktrans count counter=error_count %} + We have identified 1 issue: + {% plural %} + We have identified {{ error_count }} issues: + {% endblocktrans %} +
+ + {% else %} +
+ {% blocktrans %} + Everything seems to be fine! + {% endblocktrans %} +
+ {% endif %} + {% trans 'Start link analysis' %} + {{ block.super }} +{% endblock %} + +{% block object_tools %}{% endblock %} \ No newline at end of file