From 17bd3124686c33c1089a179e32a2d57f4856a54a Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Thu, 29 Aug 2024 07:32:58 +1200 Subject: [PATCH] fix: Document type badges (#7760) * fix: document type badge#7475 * chore: PR feedback (naming) * fix: use type_id rather than str(type) for conditionals in templatetag * fix: remove debugging CSS inline style dashed border * fix: document type badge template tag passing context variables * fix: context vars to document_type_badge * fix: badge error logging --------- Co-authored-by: Robert Sparks --- ietf/doc/templatetags/document_type_badge.py | 29 +++++++++++++++++++ ietf/static/css/document_html.scss | 5 ++++ ietf/templates/doc/badge/doc-badge-draft.html | 16 ++++++++++ ietf/templates/doc/badge/doc-badge-rfc.html | 13 +++++++++ ietf/templates/doc/document_html.html | 10 ++----- ietf/templates/doc/document_info.html | 19 ++---------- 6 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 ietf/doc/templatetags/document_type_badge.py create mode 100644 ietf/templates/doc/badge/doc-badge-draft.html create mode 100644 ietf/templates/doc/badge/doc-badge-rfc.html diff --git a/ietf/doc/templatetags/document_type_badge.py b/ietf/doc/templatetags/document_type_badge.py new file mode 100644 index 000000000..a82c606ff --- /dev/null +++ b/ietf/doc/templatetags/document_type_badge.py @@ -0,0 +1,29 @@ +# Copyright The IETF Trust 2015-2020, All Rights Reserved +from django import template +from django.conf import settings +from django.template.loader import render_to_string +from ietf.utils.log import log + +register = template.Library() + + +@register.simple_tag +def document_type_badge(doc, snapshot, submission, resurrected_by): + context = {"doc": doc, "snapshot": snapshot, "submission": submission, "resurrected_by": resurrected_by} + if doc.type_id == "rfc": + return render_to_string( + "doc/badge/doc-badge-rfc.html", + context, + ) + elif doc.type_id == "draft": + return render_to_string( + "doc/badge/doc-badge-draft.html", + context, + ) + else: + error_message = f"Unsupported document type {doc.type_id}." + if settings.SERVER_MODE != 'production': + raise ValueError(error_message) + else: + log(error_message) + return "" diff --git a/ietf/static/css/document_html.scss b/ietf/static/css/document_html.scss index 0b5a70f12..47ef8d64b 100644 --- a/ietf/static/css/document_html.scss +++ b/ietf/static/css/document_html.scss @@ -320,6 +320,11 @@ tbody.meta tr { background-color: $danger; } +.badge-generic { + color: white; + background-color: $danger; +} + #toc-nav { width: inherit; overscroll-behavior-y: none; // Prevent overscrolling from scrolling the main content diff --git a/ietf/templates/doc/badge/doc-badge-draft.html b/ietf/templates/doc/badge/doc-badge-draft.html new file mode 100644 index 000000000..f7f66b6c5 --- /dev/null +++ b/ietf/templates/doc/badge/doc-badge-draft.html @@ -0,0 +1,16 @@ +{% load origin %} +{% load static %} +{% load ietf_filters %} +{% load person_filters %} +{% origin %} +{# Non-RFC #} + +{% if doc.became_rfc %} + This is an older version of an Internet-Draft that was ultimately published as {{doc.became_rfc.name|prettystdname}}. +{% elif snapshot and doc.rev != latest_rev %} + This is an older version of an Internet-Draft whose latest revision state is "{{ doc.doc.get_state }}". +{% else %} + {% if snapshot and doc.rev == latest_rev %}{{ doc.doc.get_state }}{% else %}{{ doc.get_state }}{% endif %} Internet-Draft + {% if submission %}({{ submission|safe }}){% endif %} + {% if resurrected_by %}- resurrect requested by {{ resurrected_by }}{% endif %} +{% endif %} \ No newline at end of file diff --git a/ietf/templates/doc/badge/doc-badge-rfc.html b/ietf/templates/doc/badge/doc-badge-rfc.html new file mode 100644 index 000000000..780f14a54 --- /dev/null +++ b/ietf/templates/doc/badge/doc-badge-rfc.html @@ -0,0 +1,13 @@ +{% load origin %} +{% load static %} +{% load ietf_filters %} +{% load person_filters %} +{% origin %} + +RFC + {% if not document_html %} + - {{ doc.std_level }} + {% else %} + {{ doc.std_level }} + {% endif %} + diff --git a/ietf/templates/doc/document_html.html b/ietf/templates/doc/document_html.html index 3eabe2ebb..a85b1f531 100644 --- a/ietf/templates/doc/document_html.html +++ b/ietf/templates/doc/document_html.html @@ -4,6 +4,7 @@ {% load origin %} {% load static %} {% load ietf_filters textfilters %} +{% load document_type_badge %} {% load django_vite %} {% origin %} @@ -107,6 +108,7 @@ {{ doc.name }}-{{ doc.rev }} {% endif %}
+ {% if not snapshot %} {{ doc.std_level }} @@ -185,13 +187,7 @@ {{ doc.name }}-{{ doc.rev }} {% endif %}
- - {% if not snapshot %} - {{ doc.std_level }} - {% else %} - Internet-Draft - {% endif %} - + {% document_type_badge doc snapshot submission resurrected_by %}

{% if request.COOKIES.htmlconf and request.COOKIES.htmlconf != 'html' and html %} diff --git a/ietf/templates/doc/document_info.html b/ietf/templates/doc/document_info.html index 97cd49cf7..71050f9d4 100644 --- a/ietf/templates/doc/document_info.html +++ b/ietf/templates/doc/document_info.html @@ -3,6 +3,7 @@ {% load static %} {% load ietf_filters %} {% load person_filters %} +{% load document_type_badge %} {% origin %} @@ -11,14 +12,8 @@ {% if document_html %}Document type{% else %}Type{% endif %} + {% document_type_badge doc snapshot submission resurrected_by %} {% if doc.type_id == "rfc" %} - RFC - {% if not document_html %} - - {{ doc.std_level }} - {% else %} - {{ doc.std_level }} - {% endif %} - {% if doc.pub_date %} {% if document_html %}
{% else %}({% endif %}{{ doc.pub_date|date:"F Y" }}{% if not document_html %}){% endif %} {% else %} @@ -59,16 +54,6 @@ {% if submission %}({{ submission|safe }}){% endif %} {% endif %} - {% else %} - {% if doc.became_rfc %} - This is an older version of an Internet-Draft that was ultimately published as {{doc.became_rfc.name|prettystdname}}. - {% elif snapshot and doc.rev != latest_rev %} - This is an older version of an Internet-Draft whose latest revision state is "{{ doc.doc.get_state }}". - {% else %} - {% if snapshot and doc.rev == latest_rev %}{{ doc.doc.get_state }}{% else %}{{ doc.get_state }}{% endif %} Internet-Draft - {% if submission %}({{ submission|safe }}){% endif %} - {% if resurrected_by %}- resurrect requested by {{ resurrected_by }}{% endif %} - {% endif %} {% endif %} {% if doc.get_state_slug != "active" and doc.get_state_slug != "rfc" and doc.type_id != "rfc" %}