From c596f485a531e692b3a5e2a22336e3e0f4f60cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 6 Apr 2020 15:02:49 +0300 Subject: [PATCH] DRY: adding "now_isoformat" template tag --- hc/front/templatetags/hc_extras.py | 6 ++++++ hc/front/views.py | 4 ---- templates/integrations/add_shell.html | 2 +- templates/integrations/webhook_form.html | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py index 16fc643f..23c767b7 100644 --- a/hc/front/templatetags/hc_extras.py +++ b/hc/front/templatetags/hc_extras.py @@ -4,6 +4,7 @@ from django import template from django.conf import settings from django.utils.html import escape from django.utils.safestring import mark_safe +from django.utils.timezone import now from hc.lib.date import format_duration, format_approx_duration, format_hms @@ -151,3 +152,8 @@ def fix_asterisks(s): @register.filter def format_headers(headers): return "\n".join("%s: %s" % (k, v) for k, v in headers.items()) + + +@register.simple_tag +def now_isoformat(): + return now().replace(microsecond=0).isoformat() diff --git a/hc/front/views.py b/hc/front/views.py index 2c6eedaf..20e21308 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -179,7 +179,6 @@ def my_checks(request, code): "checks": checks, "channels": channels, "num_down": num_down, - "now": timezone.now(), "tags": pairs, "ping_endpoint": settings.PING_ENDPOINT, "timezones": pytz.all_timezones, @@ -860,7 +859,6 @@ def add_webhook(request, code): "page": "channels", "project": project, "form": form, - "now": timezone.now().replace(microsecond=0).isoformat(), } return render(request, "integrations/webhook_form.html", ctx) @@ -896,7 +894,6 @@ def edit_webhook(request, code): "project": channel.project, "channel": channel, "form": form, - "now": timezone.now().replace(microsecond=0).isoformat(), } return render(request, "integrations/webhook_form.html", ctx) @@ -921,7 +918,6 @@ def add_shell(request, code): "page": "channels", "project": project, "form": form, - "now": timezone.now().replace(microsecond=0).isoformat(), } return render(request, "integrations/add_shell.html", ctx) diff --git a/templates/integrations/add_shell.html b/templates/integrations/add_shell.html index 6c4ae7a0..19f8ce06 100644 --- a/templates/integrations/add_shell.html +++ b/templates/integrations/add_shell.html @@ -94,7 +94,7 @@ $NOW Current UTC time in ISO8601 format.
- Example: "{{ now }}" + Example: "{% now_isoformat %}" diff --git a/templates/integrations/webhook_form.html b/templates/integrations/webhook_form.html index f2f41278..955c397c 100644 --- a/templates/integrations/webhook_form.html +++ b/templates/integrations/webhook_form.html @@ -198,7 +198,7 @@ $NOW Current UTC time in ISO8601 format.
- Example: "{{ now }}" + Example: "{% now_isoformat %}"