Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Document type badges #7760

Merged
merged 14 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ietf/doc/templatetags/document_type_badge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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 warnings import warn

# from ietf.group.models import Group
jennifer-richards marked this conversation as resolved.
Show resolved Hide resolved
# from ietf.name.models import GroupTypeName

register = template.Library()


@register.simple_tag
def document_type_badge(doc, snapshot):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

submission from the context is being lost here I think

if doc.type_id == "rfc":
return render_to_string(
"doc/badge/doc-badge-rfc.html",
{"doc": doc, "snapshot": snapshot},
)
elif doc.type_id == "draft":
return render_to_string(
"doc/badge/doc-badge-draft.html",
{"doc": doc, "snapshot": snapshot},
)
else:
error_message = f"Unsupported document type {doc.type_id}."
if settings.SERVER_MODE != 'production':
raise ValueError(error_message)
else:
warn(error_message)
jennifer-richards marked this conversation as resolved.
Show resolved Hide resolved
return ""
5 changes: 5 additions & 0 deletions ietf/static/css/document_html.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions ietf/templates/doc/badge/doc-badge-draft.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load origin %}
{% load static %}
{% load ietf_filters %}
{% load person_filters %}
{% origin %}
{# Non-RFC #}

{% if doc.became_rfc %}
<div{% if document_html %} class="alert alert-warning small"{% endif %}>This is an older version of an Internet-Draft that was ultimately published as <a href="{% if document_html %}{% url 'ietf.doc.views_doc.document_html' name=doc.became_rfc.name %}{% else %}{% url 'ietf.doc.views_doc.document_main' name=doc.became_rfc.name %}{% endif %}">{{doc.became_rfc.name|prettystdname}}</a>.</div>
{% elif snapshot and doc.rev != latest_rev %}
<div{% if document_html %} class="alert alert-warning small p-2 mt-2"{% endif %}>This is an older version of an Internet-Draft whose latest revision state is "{{ doc.doc.get_state }}".</div>
{% else %}
<span class="{% if doc.get_state_slug == 'active' %}text-success{% elif doc.get_state_slug == 'expired' or doc.get_state_slug == 'repl' %}text-danger{% endif %}" style="border: dashed 3px green">{% if snapshot and doc.rev == latest_rev %}{{ doc.doc.get_state }}{% else %}{{ doc.get_state }}{% endif %} Internet-Draft</span>
{% if submission %}({{ submission|safe }}){% endif %}
{% if resurrected_by %}- resurrect requested by {{ resurrected_by }}{% endif %}
{% endif %}
13 changes: 13 additions & 0 deletions ietf/templates/doc/badge/doc-badge-rfc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load origin %}
{% load static %}
{% load ietf_filters %}
{% load person_filters %}
{% origin %}

<span class="text-success" style="border: dashed 3px green">RFC
{% if not document_html %}
- {{ doc.std_level }}
{% else %}
<span class="badge rounded-pill badge-{% if not snapshot %}{{ doc|std_level_to_label_format }}{% else %}generic{% endif %}">{{ doc.std_level }}</span>
{% endif %}
</span>
10 changes: 3 additions & 7 deletions ietf/templates/doc/document_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load origin %}
{% load static %}
{% load ietf_filters textfilters %}
{% load document_type_badge %}
{% load django_vite %}
{% origin %}
<html data-bs-theme="auto" lang="en">
Expand Down Expand Up @@ -107,6 +108,7 @@
{{ doc.name }}-{{ doc.rev }}
{% endif %}
<br class="d-sm-none">

<span class="ms-sm-3 badge rounded-pill badge-{% if not snapshot %}{{ doc|std_level_to_label_format }}{% else %}draft{% endif %}">
{% if not snapshot %}
{{ doc.std_level }}
Expand Down Expand Up @@ -185,13 +187,7 @@
{{ doc.name }}-{{ doc.rev }}
{% endif %}
<br>
<span class="badge rounded-pill badge-{% if not snapshot %}{{ doc|std_level_to_label_format }}{% else %}draft{% endif %}">
{% if not snapshot %}
{{ doc.std_level }}
{% else %}
Internet-Draft
{% endif %}
</span>
{% document_type_badge doc snapshot%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs the context?

</p>
</div>
{% if request.COOKIES.htmlconf and request.COOKIES.htmlconf != 'html' and html %}
Expand Down
19 changes: 2 additions & 17 deletions ietf/templates/doc/document_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load static %}
{% load ietf_filters %}
{% load person_filters %}
{% load document_type_badge %}
{% origin %}

<tbody class="meta align-top {% if not document_html %} border-top{% endif %}">
Expand All @@ -11,14 +12,8 @@
<th scope="row">{% if document_html %}Document type{% else %}Type{% endif %}</th>
<td class="edit"></td>
<td>
{% document_type_badge doc snapshot%}
{% if doc.type_id == "rfc" %}
<span class="text-success">RFC
{% if not document_html %}
- {{ doc.std_level }}
{% else %}
<span class="badge rounded-pill badge-{% if not snapshot %}{{ doc|std_level_to_label_format }}{% else %}draft{% endif %}">{{ doc.std_level }}</span>
{% endif %}
</span>
{% if doc.pub_date %}
{% if document_html %}<br>{% else %}({% endif %}{{ doc.pub_date|date:"F Y" }}{% if not document_html %}){% endif %}
{% else %}
Expand Down Expand Up @@ -59,16 +54,6 @@
{% if submission %}({{ submission|safe }}){% endif %}
rjsparks marked this conversation as resolved.
Show resolved Hide resolved
</div>
{% endif %}
{% else %}
{% if doc.became_rfc %}
<div{% if document_html %} class="alert alert-warning small"{% endif %}>This is an older version of an Internet-Draft that was ultimately published as <a href="{% if document_html %}{% url 'ietf.doc.views_doc.document_html' name=doc.became_rfc.name %}{% else %}{% url 'ietf.doc.views_doc.document_main' name=doc.became_rfc.name %}{% endif %}">{{doc.became_rfc.name|prettystdname}}</a>.</div>
{% elif snapshot and doc.rev != latest_rev %}
<div{% if document_html %} class="alert alert-warning small p-2 mt-2"{% endif %}>This is an older version of an Internet-Draft whose latest revision state is "{{ doc.doc.get_state }}".</div>
{% else %}
<span class="{% if doc.get_state_slug == 'active' %}text-success{% elif doc.get_state_slug == 'expired' or doc.get_state_slug == 'repl' %}text-danger{% endif %}">{% if snapshot and doc.rev == latest_rev %}{{ doc.doc.get_state }}{% else %}{{ doc.get_state }}{% endif %} Internet-Draft</span>
{% 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" %}
<div class="badge rounded-pill text-bg-warning{% if not document_html %} float-end{% endif %}">
Expand Down
Loading