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

mark_safe support for admin fields #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions django_celery_monitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
from django.template import RequestContext
from django.utils.encoding import force_text
from django.utils.html import escape

try:
from django.utils.safestring import mark_safe
except ImportError:
def mark_safe(func):
def wrapper():
func()
return wrapper


from django.utils.translation import ugettext_lazy as _

from celery import current_app
Expand Down Expand Up @@ -40,6 +50,7 @@ def __init__(self, *args, **kwargs):
self.title = self.model_admin.list_page_title


@mark_safe
@display_field(_('state'), 'state')
def colored_state(task):
"""Return the task state colored with HTML/CSS according to its level.
Expand All @@ -51,6 +62,7 @@ def colored_state(task):
return '<b><span style="color: {0};">{1}</span></b>'.format(color, state)


@mark_safe
@display_field(_('state'), 'last_heartbeat')
def node_state(node):
"""Return the worker state colored with HTML/CSS according to its level.
Expand All @@ -62,6 +74,7 @@ def node_state(node):
return '<b><span style="color: {0};">{1}</span></b>'.format(color, state)


@mark_safe
@display_field(_('ETA'), 'eta')
def eta(task):
"""Return the task ETA as a grey "none" if none is provided."""
Expand All @@ -70,6 +83,7 @@ def eta(task):
return escape(make_aware(task.eta))


@mark_safe
@display_field(_('when'), 'tstamp')
def tstamp(task):
"""Better timestamp rendering.
Expand All @@ -83,6 +97,7 @@ def tstamp(task):
)


@mark_safe
@display_field(_('name'), 'name')
def name(task):
"""Return the task name and abbreviates it to maximum of 16 characters."""
Expand Down