django icon indicating copy to clipboard operation
django copied to clipboard

Note that action descriptions are %-formatted.

Open jbothma opened this issue 1 year ago • 3 comments

jbothma avatar Aug 05 '22 13:08 jbothma

Description strings are not %-formatted.

felixxm avatar Aug 10 '22 07:08 felixxm

I'm quite sure they are https://github.com/django/django/blob/main/django/contrib/admin/options.py#L1029

If I make a description Assign to University %r I get the following:

Screenshot_2022-08-05_14-42-35

For a realistic example, we generate actions based on category names. If a category name is something like Assign to SIOC: % change Matric result improvement we get the following exception:

Screenshot_2022-08-10_10-33-21

I was surprised by the need to escape these, so I figured a note in the docs might help. I couldn't see any documentation that this is actually an intended feature so personally I'd prefer if this didn't do interpolation on my descriptions.

We generate action functions dynamically and assign the description via the short_description attribute.

jbothma avatar Aug 10 '22 08:08 jbothma

I'm really surprised, we should document supported placeholders in Admin actions docs.

felixxm avatar Aug 10 '22 09:08 felixxm

@jbothma Do you have time to keep working on this?

felixxm avatar Feb 23 '23 07:02 felixxm

Hi! Happy to try! Can't make big promises.

Do you just want something like this?

    .. note::

        The description string will be %-formatted. Supported values are verbose_name
        and verbose_name_plural of the model.

        %-signs intended to be printed as-is should be escaped with another %-sign, i.e. as %%.

jbothma avatar Feb 23 '23 07:02 jbothma

Hi! Happy to try! Can't make big promises.

Do you just want something like this?

Yes something similar, e.g.

.. admonition:: Description formatting

    Action descriptions may contain ``'%(verbose_name)s'`` and
    ``'%(verbose_name_plural)s'``, which are replaced, respectively, by the ... and ....

felixxm avatar Feb 23 '23 08:02 felixxm

Superseded by #16640.

felixxm avatar Mar 09 '23 12:03 felixxm