[Django] #35668: Expand format_html_join() to allow keyword formatting

31 views
Skip to first unread message

Django

unread,
Aug 10, 2024, 2:10:47 AM8/10/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
------------------------------+---------------------------------------
Reporter: Adam Johnson | Type: New feature
Status: new | Component: Utilities
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
[https://docs.djangoproject.com/en/stable/ref/utils/#django.utils.html.format_html_join
`format_html_join()`] currently allows formatting positional arguments
only. It would be nice if it expanded support to allow keyword arguments,
like the underlying `format_html()` does. Keyword arguments would come
from an iterable of mappings (dicts and dict-like objects). This would
allow less repetition when a value is used multiple times in the template
string, like:

{{{
from django.utils.html import format_html_join

html = format_html_join(
"\n",
'<li data-id="{id}">{title} ({id})</li>',
[
{"id": book.id, "title": book.title}
for book in books
]
)
}}}

and even:

{{{
from django.utils.html import format_html_join

html = format_html_join(
"\n",
'<li data-id="{id}">{title} ({id})</li>',
Book.objects.values("id", "title")
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35668>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 10, 2024, 10:02:57 AM8/10/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: New feature | Status: new
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted

Comment:

Makes totally sense to me!
--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:1>

Django

unread,
Aug 10, 2024, 8:02:05 PM8/10/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mohamed Nabil Rady):

* owner: (none) => Mohamed Nabil Rady
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:2>

Django

unread,
Aug 10, 2024, 8:20:31 PM8/10/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mohamed Nabil Rady):

How should the function behave if we want to use only args, only kwargs,
or both ?


{{{
from django.utils.html import format_html_join

html = format_html_join(
"\n",
'<li data-id="{id}">{title} ({id})</li>',
[
{"id": book.id, "title": book.title}
for book in books
]
)
}}}

How will this example work ? The third argument should the args generator.
--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:3>

Django

unread,
Aug 11, 2024, 8:25:14 AM8/11/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Johnson):

The idea is that if the third argument contains mappings (dicts or dict-
like objects), the formatting uses them as kwaegs, rather than as args.
Arg and kwarg modes will be exclusive.
--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:4>

Django

unread,
Aug 11, 2024, 4:33:49 PM8/11/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mohamed Nabil Rady):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/18469 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:5>

Django

unread,
Aug 11, 2024, 5:03:10 PM8/11/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:6>

Django

unread,
Aug 17, 2024, 5:34:40 AM8/17/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adam Johnson):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:7>

Django

unread,
Aug 20, 2024, 2:20:43 AM8/20/24
to django-...@googlegroups.com
#35668: Expand format_html_join() to allow keyword formatting
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Mohamed
| Nabil Rady
Type: New feature | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"231c0d85931b5afde3e3caec0e6bc5ca6132bb7a" 231c0d85]:
{{{#!CommitTicketReference repository=""
revision="231c0d85931b5afde3e3caec0e6bc5ca6132bb7a"
Fixed #35668 -- Added mapping support to format_html_join.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35668#comment:8>
Reply all
Reply to author
Forward
0 new messages