From da0a217a8cb8ea27598ce8ab83e4661235ffdf6f Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Thu, 6 Jun 2024 15:10:24 -0300 Subject: [PATCH] feat: use surname/initials for author name (#7510) * feat: use surname/initials for author name * test: test new method * fix: handle case where author name is empty --- ietf/templates/submit/announce_to_lists.txt | 2 +- ietf/templates/submit/approval_request.txt | 2 +- ietf/templates/submit/manual_post_request.txt | 2 +- ietf/templates/submit/submission_status.html | 2 +- ietf/templates/submit/submitter_form.html | 14 +++--- ietf/utils/tests.py | 45 +++++++++++++++++++ ietf/utils/xmldraft.py | 25 ++++++++++- 7 files changed, 81 insertions(+), 11 deletions(-) diff --git a/ietf/templates/submit/announce_to_lists.txt b/ietf/templates/submit/announce_to_lists.txt index d7a3739af..cf1c8b325 100644 --- a/ietf/templates/submit/announce_to_lists.txt +++ b/ietf/templates/submit/announce_to_lists.txt @@ -1,7 +1,7 @@ {% autoescape off %}{% filter wordwrap:78 %}Internet-Draft {{ submission.name }}-{{ submission.rev }}.txt is now available.{% if submission.group %} It is a work item of the {{ submission.group.name }} ({{ submission.group.acronym|upper }}){% if submission.group.type.name %} {{ submission.group.type.name }}{% endif %} of the {% if submission.group.type_id == "rg" %}IRTF{% else %}IETF{% endif %}.{% endif %}{% endfilter %} Title: {{ submission.title }} - Author{{ submission.authors|pluralize:",s" }}: {% if submission.authors|length == 1 %} {% endif %}{% for author in submission.authors %}{{ author.name }}{% if not forloop.last %} + Author{{ submission.authors|pluralize:",s" }}: {% if submission.authors|length == 1 %} {% endif %}{% for author in submission.authors %}{% firstof author.name author.affiliation "Unknown" %}{% if not forloop.last %} {% endif %}{% endfor %} Name: {{ submission.name }}-{{ submission.rev }}.txt Pages: {{ submission.pages }} diff --git a/ietf/templates/submit/approval_request.txt b/ietf/templates/submit/approval_request.txt index 9186e556f..7b9609a12 100644 --- a/ietf/templates/submit/approval_request.txt +++ b/ietf/templates/submit/approval_request.txt @@ -24,7 +24,7 @@ To approve the Internet-Draft, go to this URL (note: you need to login to be abl Authors: -{% for author in submission.authors %} {{ author.name }}{% if author.email %} <{{ author.email }}>{% endif%} +{% for author in submission.authors %} {% if author.name or author.affiliation %}{% firstof author.name author.affiliation %} {% endif %}{% if author.email %}<{{ author.email }}>{% endif %} {% endfor %} {% endautoescape %} diff --git a/ietf/templates/submit/manual_post_request.txt b/ietf/templates/submit/manual_post_request.txt index 7b515fbeb..7fe19e9a2 100644 --- a/ietf/templates/submit/manual_post_request.txt +++ b/ietf/templates/submit/manual_post_request.txt @@ -33,7 +33,7 @@ I-D Submission Tool URL: Authors: -{% for author in submission.authors %} {{ author.name }}{% if author.email %} <{{ author.email }}>{% endif%} +{% for author in submission.authors %} {% if author.name or author.affiliation %}{% firstof author.name author.affiliation %} {% endif %}{% if author.email %}<{{ author.email }}>{% endif %} {% endfor %} Comment to the secretariat: diff --git a/ietf/templates/submit/submission_status.html b/ietf/templates/submit/submission_status.html index 733b4217a..cdc5dd400 100644 --- a/ietf/templates/submit/submission_status.html +++ b/ietf/templates/submit/submission_status.html @@ -285,7 +285,7 @@ Author {{ forloop.counter }} - {{ author.name }} + {% if author.name %}{{ author.name }}{% endif %} {% if author.email %}<{{ author.email|linkify }}>{% endif %}
{% if author.affiliation %} diff --git a/ietf/templates/submit/submitter_form.html b/ietf/templates/submit/submitter_form.html index 1cf77260e..65b9ba509 100644 --- a/ietf/templates/submit/submitter_form.html +++ b/ietf/templates/submit/submitter_form.html @@ -11,12 +11,14 @@

{% load ietf_filters %} {% for author in submission.authors %} - + {% if author.name %} + + {% endif %} {% endfor %} {% bootstrap_form_errors submitter_form %} {% bootstrap_field submitter_form.name %} diff --git a/ietf/utils/tests.py b/ietf/utils/tests.py index 4ac2732ed..08adefc82 100644 --- a/ietf/utils/tests.py +++ b/ietf/utils/tests.py @@ -486,6 +486,51 @@ class XMLDraftTests(TestCase): ("-01", None), ) + def test_render_author_name(self): + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element("author", fullname="Joanna Q. Public")), + "Joanna Q. Public", + ) + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element( + "author", + fullname="Joanna Q. Public", + asciiFullname="Not the Same at All", + )), + "Joanna Q. Public", + ) + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element( + "author", + fullname="Joanna Q. Public", + initials="J. Q.", + surname="Public-Private", + )), + "Joanna Q. Public", + ) + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element( + "author", + initials="J. Q.", + surname="Public", + )), + "J. Q. Public", + ) + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element( + "author", + surname="Public", + )), + "Public", + ) + self.assertEqual( + XMLDraft.render_author_name(lxml.etree.Element( + "author", + initials="J. Q.", + )), + "J. Q.", + ) + class NameTests(TestCase): diff --git a/ietf/utils/xmldraft.py b/ietf/utils/xmldraft.py index 3a9ac02b1..c39c4d0a0 100644 --- a/ietf/utils/xmldraft.py +++ b/ietf/utils/xmldraft.py @@ -179,6 +179,29 @@ class XMLDraft(Draft): # abstract = self.xmlroot.findtext('front/abstract') # return abstract.strip() if abstract else '' + @staticmethod + def render_author_name(author_elt): + """Get a displayable name for an author, if possible + + Based on TextWriter.render_author_name() from xml2rfc. If fullname is present, uses that. + If not, uses either initials + surname or just surname. Finally, returns None because this + author is evidently an organization, not a person. + + Does not involve ascii* attributes because rfc7991 requires fullname if any of those are + present. + """ + # Use fullname attribute, if present + fullname = author_elt.attrib.get("fullname", "").strip() + if fullname: + return fullname + surname = author_elt.attrib.get("surname", "").strip() + initials = author_elt.attrib.get("initials", "").strip() + if surname or initials: + # This allows the possibility that only initials are used, which is a bit nonsensical + # but seems to be technically allowed by RFC 7991. + return f"{initials} {surname}".strip() + return None + def get_author_list(self): """Get detailed author list @@ -197,7 +220,7 @@ class XMLDraft(Draft): for author in self.xmlroot.findall('front/author'): info = { - 'name': author.attrib.get('fullname'), + 'name': self.render_author_name(author), 'email': author.findtext('address/email'), 'affiliation': author.findtext('organization'), }