forked from django-cms/cmsplugin-filer
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashboard #5
Open
SteinRobert
wants to merge
1
commit into
master
Choose a base branch
from
dashboard
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dashboard #5
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,59 @@ | ||
# -*- 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 | ||
|
||
|
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should use |
||
] | ||
|
||
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 | ||
|
101 changes: 101 additions & 0 deletions
101
cmsplugin_filer_link2/templates/admin/cmsplugin_filer_link/change_list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{% extends 'admin/change_list.html' %} | ||
{% load i18n %} | ||
|
||
{% block extrastyle %} | ||
{{ block.super }} | ||
<style> | ||
.link2-critical-error { | ||
color: red; | ||
} | ||
.link2-warning { | ||
color: #ffbb00 | ||
} | ||
.error-list { | ||
display: inline-block; | ||
margin-right: 50px; | ||
} | ||
a.cms-btn.btn-analysis { | ||
background-color: #0bf !important; | ||
color: white !important; | ||
display: inline-block; | ||
padding: 8px 16px !important; | ||
margin-bottom: 30px; | ||
margin-top: 10px; | ||
} | ||
a.cms-btn.btn-analysis:hover { | ||
color: white !important; | ||
background-color: #00aaee !important; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block content_title %} | ||
<h1> | ||
{% trans 'Welcome to you link health state dashboard!' %} | ||
</h1> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{# Short error overview report. #} | ||
{% if error_count %} | ||
<div> | ||
{% blocktrans count counter=error_count %} | ||
We have identified 1 issue: | ||
{% plural %} | ||
We have identified {{ error_count }} issues: | ||
{% endblocktrans %} | ||
</div> | ||
<ul class="error-list"> | ||
{% if redirected_links %} | ||
<li class="link2-warning"> | ||
{% blocktrans count counter=redirected_links|length %} | ||
1 link is | ||
{% plural %} | ||
{{ counter }} links are | ||
{% endblocktrans %} | ||
redirected (3xx). | ||
</li> | ||
{% endif %} | ||
{% if not_found_errors %} | ||
<li class="link2-critical-error"> | ||
{% blocktrans count counter=not_found_errors|length %} | ||
1 link leads | ||
{% plural %} | ||
{{ counter }} links lead | ||
{% endblocktrans %} | ||
into a page which cannot be found (4xx). | ||
</li> | ||
{% endif %} | ||
{% if server_errors %} | ||
<li class="link2-critical-error"> | ||
{% blocktrans count counter=server_errors|length %} | ||
1 link leads | ||
{% plural %} | ||
{{ counter }} links lead | ||
{% endblocktrans %} | ||
into a page which results in a server error (5xx). | ||
</li> | ||
{% endif %} | ||
{% if bad_configured_links %} | ||
<li class="link2-critical-error"> | ||
{% blocktrans count counter=bad_configured_links|length %} | ||
1 link is | ||
{% plural %} | ||
{{ counter }} links are | ||
{% endblocktrans %} | ||
badly configured. | ||
</li> | ||
{% endif %} | ||
</ul> | ||
{% else %} | ||
<div> | ||
{% blocktrans %} | ||
Everything seems to be fine! | ||
{% endblocktrans %} | ||
</div> | ||
{% endif %} | ||
<a class="cms-btn btn-analysis" href="{% url 'admin:cmsplugin_filer_link2_linkhealthstate_update_health_state' %}">{% trans 'Start link analysis' %}</a> | ||
{{ block.super }} | ||
{% endblock %} | ||
|
||
{% block object_tools %}{% endblock %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
link_name
in the list currently links to the link state of a link. There, the user could change the link or the status. I think both doesn't really make sense, so maybe we should not link to the health status of a link from within the list?This should do the trick from within the
__init__
of theLinkStateAdmin
:self.list_display_links = (None, )
(http://stackoverflow.com/questions/1618728/disable-link-to-edit-object-in-djangos-admin-display-list-only)