From 037d262325268ef78e0479106b294cc515239b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Fri, 8 Dec 2017 00:03:16 +0200 Subject: [PATCH 1/9] format html --- .gitignore | 1 + django_celery_monitor/admin.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 0ec4d19a..6be57896 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ cover/ .cache/ htmlcov/ coverage.xml +env/* \ No newline at end of file diff --git a/django_celery_monitor/admin.py b/django_celery_monitor/admin.py index da4465e8..054954c9 100644 --- a/django_celery_monitor/admin.py +++ b/django_celery_monitor/admin.py @@ -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 @@ -48,7 +48,7 @@ def colored_state(task): """ state = escape(task.state) color = TASK_STATE_COLORS.get(task.state, 'black') - return '{1}'.format(color, state) + return format_html('{1}'.format(color, state)) @display_field(_('state'), 'last_heartbeat') @@ -59,14 +59,14 @@ def node_state(node): """ state = node.is_alive() and 'ONLINE' or 'OFFLINE' color = NODE_STATE_COLORS[state] - return '{1}'.format(color, state) + return format_html('{1}'.format(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 'none' + return format_html('none') return escape(make_aware(task.eta)) @@ -78,18 +78,18 @@ def tstamp(task): it as a "natural date" -- a human readable version. """ value = make_aware(task.tstamp) - return '
{1}
'.format( + return format_html('
{1}
'.format( escape(str(value)), escape(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 '
{1}
'.format( + return format_html('
{1}
'.format( escape(task.name), escape(short_name), - ) + )) class ModelMonitor(admin.ModelAdmin): From 9df9301e364bbc583107ba74cb2977ddb0d43cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Fri, 8 Dec 2017 00:13:13 +0200 Subject: [PATCH 2/9] admin updates --- .gitignore | 3 ++- django_celery_monitor/admin.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6be57896..26cb40ab 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ cover/ .cache/ htmlcov/ coverage.xml -env/* \ No newline at end of file +env/ +.vscode/ \ No newline at end of file diff --git a/django_celery_monitor/admin.py b/django_celery_monitor/admin.py index 054954c9..677cfe88 100644 --- a/django_celery_monitor/admin.py +++ b/django_celery_monitor/admin.py @@ -48,7 +48,7 @@ def colored_state(task): """ state = escape(task.state) color = TASK_STATE_COLORS.get(task.state, 'black') - return format_html('{1}'.format(color, state)) + return format_html('{1}', color, state) @display_field(_('state'), 'last_heartbeat') @@ -59,7 +59,7 @@ def node_state(node): """ state = node.is_alive() and 'ONLINE' or 'OFFLINE' color = NODE_STATE_COLORS[state] - return format_html('{1}'.format(color, state)) + return format_html('{1}', color, state) @display_field(_('ETA'), 'eta') @@ -78,18 +78,20 @@ def tstamp(task): it as a "natural date" -- a human readable version. """ value = make_aware(task.tstamp) - return format_html('
{1}
'.format( - escape(str(value)), escape(naturaldate(value)), - )) + return format_html('
{1}
', + 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 format_html('
{1}
'.format( - escape(task.name), escape(short_name), - )) + return format_html('
{1}
', + task.name, + short_name, + ) class ModelMonitor(admin.ModelAdmin): From 49ab46ce505d0d04e26ee8e55d8343b32601fce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Fri, 8 Dec 2017 00:44:31 +0200 Subject: [PATCH 3/9] fixed columns format_html --- django_celery_monitor/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django_celery_monitor/utils.py b/django_celery_monitor/utils.py index a6656747..8c134077 100644 --- a/django_celery_monitor/utils.py +++ b/django_celery_monitor/utils.py @@ -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, format_html try: from django.db.models.functions import Now @@ -105,8 +105,10 @@ def f(task): if len(shortval) > maxlen: shortval = shortval[:maxlen] + '...' - styled = FIXEDWIDTH_STYLE.format( - escape(val[:255]), pt, escape(shortval), + styled = format_html(FIXEDWIDTH_STYLE, + val[:255], + pt, + shortval ) return styled.replace('|br/|', '
') return f From a093f6f28701de6a37d0dc0fe82e7eccc04f1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Fri, 8 Dec 2017 00:48:57 +0200 Subject: [PATCH 4/9] add one more format_html --- django_celery_monitor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_celery_monitor/utils.py b/django_celery_monitor/utils.py index 8c134077..12d45507 100644 --- a/django_celery_monitor/utils.py +++ b/django_celery_monitor/utils.py @@ -110,5 +110,5 @@ def f(task): pt, shortval ) - return styled.replace('|br/|', '
') + return format_html(styled.replace('|br/|', '
')) return f From 7d77c131274fd2cd7963a54205516217f40557bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Fri, 8 Dec 2017 01:20:55 +0200 Subject: [PATCH 5/9] finalize fix --- django_celery_monitor/utils.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/django_celery_monitor/utils.py b/django_celery_monitor/utils.py index 12d45507..90f58d3d 100644 --- a/django_celery_monitor/utils.py +++ b/django_celery_monitor/utils.py @@ -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, format_html +from django.utils.html import escape, mark_safe, format_html try: from django.db.models.functions import Now @@ -101,14 +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', '
') if len(shortval) > maxlen: shortval = shortval[:maxlen] + '...' - styled = format_html(FIXEDWIDTH_STYLE, - val[:255], - pt, - shortval - ) - return format_html(styled.replace('|br/|', '
')) + return format_html(FIXEDWIDTH_STYLE, val[:255], pt, mark_safe(shortval)) return f From 9960816befdfb6562dda3e6a0d16f64dea92b7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Wed, 10 Jan 2018 21:02:13 +0200 Subject: [PATCH 6/9] remove gitignore statements --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 26cb40ab..0ec4d19a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,3 @@ cover/ .cache/ htmlcov/ coverage.xml -env/ -.vscode/ \ No newline at end of file From 6d946fc458856f0f85a341b129c9d8c5c0a91b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Wed, 10 Jan 2018 21:10:27 +0200 Subject: [PATCH 7/9] fix linelength --- django_celery_monitor/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django_celery_monitor/utils.py b/django_celery_monitor/utils.py index 90f58d3d..59589740 100644 --- a/django_celery_monitor/utils.py +++ b/django_celery_monitor/utils.py @@ -105,5 +105,6 @@ def f(task): if len(shortval) > maxlen: shortval = shortval[:maxlen] + '...' - return format_html(FIXEDWIDTH_STYLE, val[:255], pt, mark_safe(shortval)) + return format_html(FIXEDWIDTH_STYLE, val[:255], pt, + mark_safe(shortval)) return f From 20e9b999ae9b38e89616a70fed18859746aeaf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Wed, 10 Jan 2018 21:22:25 +0200 Subject: [PATCH 8/9] remove unused import --- django_celery_monitor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_celery_monitor/utils.py b/django_celery_monitor/utils.py index 59589740..e6b0a6aa 100644 --- a/django_celery_monitor/utils.py +++ b/django_celery_monitor/utils.py @@ -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, mark_safe, format_html +from django.utils.html import mark_safe, format_html try: from django.db.models.functions import Now From 9835972f940cb60051d426e56e89a9bc5b62734c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20Va=CC=88in?= Date: Wed, 10 Jan 2018 21:38:21 +0200 Subject: [PATCH 9/9] fix all flake issues --- django_celery_monitor/admin.py | 18 ++++++++---------- setup.py | 2 ++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/django_celery_monitor/admin.py b/django_celery_monitor/admin.py index 677cfe88..6b197b28 100644 --- a/django_celery_monitor/admin.py +++ b/django_celery_monitor/admin.py @@ -48,7 +48,8 @@ def colored_state(task): """ state = escape(task.state) color = TASK_STATE_COLORS.get(task.state, 'black') - return format_html('{1}', color, state) + return format_html('{1}', color, + state) @display_field(_('state'), 'last_heartbeat') @@ -59,7 +60,8 @@ def node_state(node): """ state = node.is_alive() and 'ONLINE' or 'OFFLINE' color = NODE_STATE_COLORS[state] - return format_html('{1}', color, state) + return format_html('{1}', color, + state) @display_field(_('ETA'), 'eta') @@ -78,20 +80,16 @@ def tstamp(task): it as a "natural date" -- a human readable version. """ value = make_aware(task.tstamp) - return format_html('
{1}
', - str(value), - naturaldate(value) - ) + return format_html('
{1}
', 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 format_html('
{1}
', - task.name, - short_name, - ) + return format_html('
{1}
', task.name, + short_name) class ModelMonitor(admin.ModelAdmin): diff --git a/setup.py b/setup.py index 1de64b7a..2dcd549e 100644 --- a/setup.py +++ b/setup.py @@ -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__)) @@ -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'):