Skip to content

Commit

Permalink
backports to support 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Sep 8, 2024
1 parent fef3c16 commit 221ccec
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
6 changes: 5 additions & 1 deletion validity/tables.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import itertools
from functools import partial

Expand All @@ -14,7 +15,7 @@
from utilities.paginator import EnhancedPaginator

from validity import models
from validity.templatetags.validity import colorful_percentage
from validity.templatetags.validity import colorful_percentage, isodatetime


class SelectorTable(NetBoxTable):
Expand Down Expand Up @@ -298,3 +299,6 @@ class ScriptResultTable(BaseTable):
class Meta(BaseTable.Meta):
empty_text = _("No results found")
fields = ("index", "time", "status", "message")

def render_time(self, value):
return isodatetime(datetime.datetime.fromisoformat(value))
11 changes: 11 additions & 0 deletions validity/templates/validity/inc/fieldset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load form_helpers %}
<div class="field-group mb-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{{ group }}</h5>
</div>
{% for name in fields %}
{% with field=form|getfield:name %}
{% render_field field %}
{% endwith %}
{% endfor %}
</div>
2 changes: 1 addition & 1 deletion validity/templates/validity/scripts/result.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'extras/script_result.html' %}

{% load validity %}
{% block title %}Script Execution Result{% endblock title %}
{% block subtitle %}{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion validity/templates/validity/scripts/run.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'generic/object.html' %}
{% load helpers %}
{% load form_helpers %}
{% load log_levels %}
{% load validity %}

{% block title %}Run Compliance Tests{% endblock %}
{% block breadcrumbs %}
Expand Down
17 changes: 17 additions & 0 deletions validity/templatetags/validity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any

from django import template
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.db.models import Model
from django.http.request import HttpRequest
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.timezone import localtime
from django.utils.translation import gettext_lazy as _
from utilities.templatetags.builtins.filters import linkify, placeholder

Expand Down Expand Up @@ -91,3 +93,18 @@ def bg():
@register.filter
def nb_version():
return config.netbox_version


@register.inclusion_tag("validity/inc/fieldset.html")
def render_fieldset(form, fieldset):
# backport of the native render_fieldset appeared in 4.0
name, items = fieldset if config.netbox_version < "4.0.0" else fieldset.name, fieldset.items
return {"group": name, "fields": items, "form": form}


@register.filter()
def isodatetime(value, spec="seconds"):
# backport of the native isodatetime in 4.0
value = localtime(value) if value.tzinfo else value
text = f"{value.date().isoformat()} {value.time().isoformat(spec)}"
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')

0 comments on commit 221ccec

Please sign in to comment.