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 5 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ cover/
.cache/
htmlcov/
coverage.xml
env/
.vscode/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the change to the .gitignore file since they are folder local do your computer. You can easily add it to your global gitignore instead.

18 changes: 10 additions & 8 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,7 @@ 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 +59,14 @@ 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,17 +78,19 @@ 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,
)


Expand Down
9 changes: 3 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 escape, mark_safe, format_html

try:
from django.db.models.functions import Now
Expand Down Expand Up @@ -101,12 +101,9 @@ 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