Skip to content

Commit 221ccec

Browse files
committed
backports to support 3.7
1 parent fef3c16 commit 221ccec

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

validity/tables.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import itertools
23
from functools import partial
34

@@ -14,7 +15,7 @@
1415
from utilities.paginator import EnhancedPaginator
1516

1617
from validity import models
17-
from validity.templatetags.validity import colorful_percentage
18+
from validity.templatetags.validity import colorful_percentage, isodatetime
1819

1920

2021
class SelectorTable(NetBoxTable):
@@ -298,3 +299,6 @@ class ScriptResultTable(BaseTable):
298299
class Meta(BaseTable.Meta):
299300
empty_text = _("No results found")
300301
fields = ("index", "time", "status", "message")
302+
303+
def render_time(self, value):
304+
return isodatetime(datetime.datetime.fromisoformat(value))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% load form_helpers %}
2+
<div class="field-group mb-5">
3+
<div class="row mb-2">
4+
<h5 class="offset-sm-3">{{ group }}</h5>
5+
</div>
6+
{% for name in fields %}
7+
{% with field=form|getfield:name %}
8+
{% render_field field %}
9+
{% endwith %}
10+
{% endfor %}
11+
</div>

validity/templates/validity/scripts/result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'extras/script_result.html' %}
2-
2+
{% load validity %}
33
{% block title %}Script Execution Result{% endblock title %}
44
{% block subtitle %}{% endblock %}
55

validity/templates/validity/scripts/run.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends 'generic/object.html' %}
22
{% load helpers %}
3-
{% load form_helpers %}
43
{% load log_levels %}
4+
{% load validity %}
55

66
{% block title %}Run Compliance Tests{% endblock %}
77
{% block breadcrumbs %}

validity/templatetags/validity.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from typing import Any
22

33
from django import template
4+
from django.contrib.humanize.templatetags.humanize import naturaltime
45
from django.db.models import Model
56
from django.http.request import HttpRequest
67
from django.utils.html import format_html
78
from django.utils.safestring import mark_safe
9+
from django.utils.timezone import localtime
810
from django.utils.translation import gettext_lazy as _
911
from utilities.templatetags.builtins.filters import linkify, placeholder
1012

@@ -91,3 +93,18 @@ def bg():
9193
@register.filter
9294
def nb_version():
9395
return config.netbox_version
96+
97+
98+
@register.inclusion_tag("validity/inc/fieldset.html")
99+
def render_fieldset(form, fieldset):
100+
# backport of the native render_fieldset appeared in 4.0
101+
name, items = fieldset if config.netbox_version < "4.0.0" else fieldset.name, fieldset.items
102+
return {"group": name, "fields": items, "form": form}
103+
104+
105+
@register.filter()
106+
def isodatetime(value, spec="seconds"):
107+
# backport of the native isodatetime in 4.0
108+
value = localtime(value) if value.tzinfo else value
109+
text = f"{value.date().isoformat()} {value.time().isoformat(spec)}"
110+
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')

0 commit comments

Comments
 (0)