Skip to content
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

Allow tags fix for Django 2.0 #40

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions django_celery_monitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.html import escape, format_html
from django.utils.translation import ugettext_lazy as _

from celery import current_app
Expand Down Expand Up @@ -48,7 +48,8 @@ def colored_state(task):
"""
state = escape(task.state)
color = TASK_STATE_COLORS.get(task.state, 'black')
return '<b><span style="color: {0};">{1}</span></b>'.format(color, state)
return format_html('<b><span style="color: {0};">{1}</span></b>', color,
state)


@display_field(_('state'), 'last_heartbeat')
Expand All @@ -59,14 +60,15 @@ def node_state(node):
"""
state = node.is_alive() and 'ONLINE' or 'OFFLINE'
color = NODE_STATE_COLORS[state]
return '<b><span style="color: {0};">{1}</span></b>'.format(color, state)
return format_html('<b><span style="color: {0};">{1}</span></b>', color,
state)


@display_field(_('ETA'), 'eta')
def eta(task):
"""Return the task ETA as a grey "none" if none is provided."""
if not task.eta:
return '<span style="color: gray;">none</span>'
return format_html('<span style="color: gray;">none</span>')
return escape(make_aware(task.eta))


Expand All @@ -78,18 +80,16 @@ def tstamp(task):
it as a "natural date" -- a human readable version.
"""
value = make_aware(task.tstamp)
return '<div title="{0}">{1}</div>'.format(
escape(str(value)), escape(naturaldate(value)),
)
return format_html('<div title="{0}">{1}</div>', str(value),
naturaldate(value))


@display_field(_('name'), 'name')
def name(task):
"""Return the task name and abbreviates it to maximum of 16 characters."""
short_name = abbrtask(task.name, 16)
return '<div title="{0}"><b>{1}</b></div>'.format(
escape(task.name), escape(short_name),
)
return format_html('<div title="{0}"><b>{1}</b></div>', task.name,
short_name)


class ModelMonitor(admin.ModelAdmin):
Expand Down
10 changes: 4 additions & 6 deletions django_celery_monitor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.conf import settings
from django.db.models import DateTimeField, Func
from django.utils import timezone
from django.utils.html import escape
from django.utils.html import mark_safe, format_html

try:
from django.db.models.functions import Now
Expand Down Expand Up @@ -101,12 +101,10 @@ def f(task):
if val.startswith("u'") or val.startswith('u"'):
val = val[2:-1]
shortval = val.replace(',', ',\n')
shortval = shortval.replace('\n', '|br/|')
shortval = shortval.replace('\n', '<br/>')

if len(shortval) > maxlen:
shortval = shortval[:maxlen] + '...'
styled = FIXEDWIDTH_STYLE.format(
escape(val[:255]), pt, escape(shortval),
)
return styled.replace('|br/|', '<br/>')
return format_html(FIXEDWIDTH_STYLE, val[:255], pt,
mark_safe(shortval))
return f
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def add_default(m):
def add_doc(m):
return (('doc', m.groups()[0]),)


pats = {re_meta: add_default,
re_doc: add_doc}
here = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -111,6 +112,7 @@ def _reqs(*f):
def reqs(*f):
return [req for subreq in _reqs(*f) for req in subreq]


# -*- Long Description -*-

if os.path.exists('README.rst'):
Expand Down