From 37ef4a25e34de346a32435d9f027a7ac9dd092de Mon Sep 17 00:00:00 2001 From: Eric Vyncke Date: Sat, 4 Nov 2023 14:59:29 +0100 Subject: [PATCH 1/3] Fix #3911 by adding a markdown filter for template --- ietf/doc/templatetags/ietf_filters.py | 21 ++++++++++++++ .../migrations/0011_adjust_important_dates.py | 29 +++++++++++++++++++ ietf/templates/meeting/important-dates.html | 25 +--------------- 3 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 ietf/name/migrations/0011_adjust_important_dates.py diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index e59ef2bed3..6a7f021363 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -6,6 +6,7 @@ import re from urllib.parse import urljoin from zoneinfo import ZoneInfo +import markdown as python_markdown from django import template from django.conf import settings @@ -228,6 +229,26 @@ def link_other_doc_match(match): return f'{match[1]}' +@register.filter(name="markdown", is_safe=True, needs_autoescape=True) +def markdown(string, autoescape=None): + """ + Render a markdown string into HTML + """ + string = bleach_cleaner.clean( + python_markdown.markdown( + string, + extensions=[ + "extra", + "nl2br", + "sane_lists", + "toc", + ], + ) + ) + # One issue is that the string is enclosed in

... Let's remove the leading/trailing ones... + string = string[3:-4] + return mark_safe(string) + @register.filter(name="urlize_ietf_docs", is_safe=True, needs_autoescape=True) def urlize_ietf_docs(string, autoescape=None): """ diff --git a/ietf/name/migrations/0011_adjust_important_dates.py b/ietf/name/migrations/0011_adjust_important_dates.py new file mode 100644 index 0000000000..f163d07ec9 --- /dev/null +++ b/ietf/name/migrations/0011_adjust_important_dates.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.7 on 2023-11-04 12:50 + +from django.db import migrations, models + +def markdown_names(apps, schema_editor): + ImportantDateName = apps.get_model("name", "ImportantDateName") + changes = [ + ('bofproposals', "Preliminary BOF proposals requested. To request a __BoF__ session use the [IETF BoF Request Tool](/doc/bof-requests)."), + ('openreg', "IETF Online Registration Opens [Register Here](https://www.ietf.org/how/meetings/register/)."), + ('opensched', "Working Group and BOF scheduling begins. To request a Working Group session, use the [IETF Meeting Session Request Tool](/secr/sreq/). If you are working on a BOF request, it is highly recommended to tell the IESG now by sending an [email to iesg@ietf.org](mailtp:iesg@ietf.org) to get advance help with the request."), + ('cutoffwgreq', "Cut-off date for requests to schedule Working Group Meetings at UTC 23:59. To request a __Working Group__ session, use the [IETF Meeting Session Request Tool](/secr/sreq/)."), + ('idcutoff', "Internet-Draft submission cut-off (for all Internet-Drafts, including -00) by UTC 23:59. Upload using the [I-D Submission Tool](/submit/)."), + ('cutoffwgreq', "Cut-off date for requests to schedule Working Group Meetings at UTC 23:59. To request a __Working Group__ session, use the [IETF Meeting Session Request Tool](/secr/sreq/)."), + ('bofprelimcutoff', "Cut-off date for BOF proposal requests. To request a __BoF__ session use the [IETF BoF Request Tool](/doc/bof-requests)."), + ('cutoffbofreq', "Cut-off date for BOF proposal requests to Area Directors at UTC 23:59. To request a __BoF__ session use the [IETF BoF Request Tool](/doc/bof-requests)."), + ] + for slug, newDescription in changes: + datename = ImportantDateName.objects.get(pk=slug) # If the slug does not exist, then Django will throw an exception :-) + datename.desc = newDescription + datename.save() + +class Migration(migrations.Migration): + dependencies = [ + ("name", "0010_subseries"), + ] + + operations = [ + migrations.RunPython(markdown_names), + ] diff --git a/ietf/templates/meeting/important-dates.html b/ietf/templates/meeting/important-dates.html index 1d786ebc88..437f2cd9a6 100644 --- a/ietf/templates/meeting/important-dates.html +++ b/ietf/templates/meeting/important-dates.html @@ -45,30 +45,7 @@

{% endif %} - {{ d.name.desc|urlize_ietf_docs|linkify }}{% if d.name.desc|slice:"-1:" != "." %}.{% endif %} - {% if first and d.name.slug == 'openreg' or first and d.name.slug == 'earlybird' %} - Register here. - {% endif %} - {% if d.name.slug == 'opensched' %} - To request a Working Group session, use the - IETF Meeting Session Request Tool. - If you are working on a BOF request, it is highly recommended - to tell the IESG now by sending an email to - iesg@ietf.org - to get advance help with the request. - {% endif %} - {% if d.name.slug == 'cutoffwgreq' %} - To request a Working Group session, use the - IETF Meeting Session Request Tool. - {% endif %} - {% if d.name.slug == 'cutoffbofreq' %} - To request a BOF, please see instructions on - Requesting a BOF. - {% endif %} - {% if d.name.slug == 'idcutoff' %} - Upload using the - I-D Submission Tool. - {% endif %} + {{ d.name.desc|urlize_ietf_docs|linkify|markdown }}{% if d.name.desc|slice:"-1:" != "." %}.{% endif %} {% if d.name.slug == 'draftwgagenda' or d.name.slug == 'revwgagenda' or d.name.slug == 'procsub' or d.name.slug == 'revslug' %} Upload using the Meeting Materials Management Tool. From ff54c0f0709de0cf3b22dda2f091bc370e959b88 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Sun, 5 Nov 2023 10:35:00 +0100 Subject: [PATCH 2/3] fix: move the new markdown filter to utils --- ietf/doc/templatetags/ietf_filters.py | 22 ------------------- .../migrations/0011_adjust_important_dates.py | 4 ++-- ietf/templates/meeting/important-dates.html | 2 +- ietf/utils/templatetags/htmlfilters.py | 7 ++++++ 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index 6a7f021363..f52edf1bd6 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -6,7 +6,6 @@ import re from urllib.parse import urljoin from zoneinfo import ZoneInfo -import markdown as python_markdown from django import template from django.conf import settings @@ -228,27 +227,6 @@ def link_other_doc_match(match): url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=doc + rev)) return f'{match[1]}' - -@register.filter(name="markdown", is_safe=True, needs_autoescape=True) -def markdown(string, autoescape=None): - """ - Render a markdown string into HTML - """ - string = bleach_cleaner.clean( - python_markdown.markdown( - string, - extensions=[ - "extra", - "nl2br", - "sane_lists", - "toc", - ], - ) - ) - # One issue is that the string is enclosed in

... Let's remove the leading/trailing ones... - string = string[3:-4] - return mark_safe(string) - @register.filter(name="urlize_ietf_docs", is_safe=True, needs_autoescape=True) def urlize_ietf_docs(string, autoescape=None): """ diff --git a/ietf/name/migrations/0011_adjust_important_dates.py b/ietf/name/migrations/0011_adjust_important_dates.py index f163d07ec9..9f2fa58394 100644 --- a/ietf/name/migrations/0011_adjust_important_dates.py +++ b/ietf/name/migrations/0011_adjust_important_dates.py @@ -1,6 +1,6 @@ -# Generated by Django 4.2.7 on 2023-11-04 12:50 +# Copyright The IETF Trust 2023, All Rights Reserved -from django.db import migrations, models +from django.db import migrations def markdown_names(apps, schema_editor): ImportantDateName = apps.get_model("name", "ImportantDateName") diff --git a/ietf/templates/meeting/important-dates.html b/ietf/templates/meeting/important-dates.html index 437f2cd9a6..0ff6f82994 100644 --- a/ietf/templates/meeting/important-dates.html +++ b/ietf/templates/meeting/important-dates.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {# Copyright The IETF Trust 2017, All Rights Reserved #} {% load origin %} -{% load ietf_filters static textfilters ietf_filters %} +{% load ietf_filters static textfilters htmlfilters %} {% block pagehead %} {% endblock %} diff --git a/ietf/utils/templatetags/htmlfilters.py b/ietf/utils/templatetags/htmlfilters.py index a0f9232c57..1e399e2d72 100644 --- a/ietf/utils/templatetags/htmlfilters.py +++ b/ietf/utils/templatetags/htmlfilters.py @@ -7,6 +7,7 @@ from django.template.defaultfilters import stringfilter from ietf.utils.html import remove_tags +from ietf.utils.markdown import markdown as utils_markdown register = Library() @@ -16,3 +17,9 @@ def removetags(value, tags): """Removes a comma-separated list of [X]HTML tags from the output.""" return remove_tags(value, re.split(r"\s*,\s*", tags)) + +@register.filter(name="markdown", is_safe=True) +def markdown(string): + # One issue is that the string is enclosed in

... Let's remove the leading/trailing ones... + return utils_markdown(string)[3:-4] + From 3571e00bf646d92922115986f4aa23e95ac4ab3e Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Thu, 9 Nov 2023 17:09:56 +0100 Subject: [PATCH 3/3] fix: linkify after markdown --- ietf/templates/meeting/important-dates.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ietf/templates/meeting/important-dates.html b/ietf/templates/meeting/important-dates.html index 0ff6f82994..1d41b4a7f0 100644 --- a/ietf/templates/meeting/important-dates.html +++ b/ietf/templates/meeting/important-dates.html @@ -45,7 +45,7 @@

{% endif %} - {{ d.name.desc|urlize_ietf_docs|linkify|markdown }}{% if d.name.desc|slice:"-1:" != "." %}.{% endif %} + {{ d.name.desc|urlize_ietf_docs|markdown|linkify }}{% if d.name.desc|slice:"-1:" != "." %}.{% endif %} {% if d.name.slug == 'draftwgagenda' or d.name.slug == 'revwgagenda' or d.name.slug == 'procsub' or d.name.slug == 'revslug' %} Upload using the Meeting Materials Management Tool.