#36038: Added a test case for the display_for_field function when a FileField is
passed.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: display_for_field, | Triage Stage:
FileFIeld | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Antoliny:
Old description:
> {{{
> def display_for_field(value, field, empty_value_display):
> from django.contrib.admin.templatetags.admin_list import
> _boolean_icon
> ...
> elif isinstance(field, (models.IntegerField, models.FloatField)):
> return formats.number_format(value)
> elif isinstance(field, models.FileField) and value:
> return format_html('<a href="{}">{}</a>', value.url, value)
> ...
> }}}
> There is no test case for the display_for_field function when a
> `FileField` object is passed. -->
> [https://github.com/django/django/blob/main/tests/admin_utils/tests.py
> admin_utils test code]
>
> When the `FileField` handling was added in the above function, I found
> that the test was conducted indirectly through the FileWidget readonly
> attribute. -->
> [https://github.com/django/django/blob/main/tests/admin_widgets/tests.py#L654
> test code]
>
> However, I believe it would be better to have a direct test case for when
> a FileField is passed, considering that display_for_field function is
> globally accessible.
New description:
{{{
def display_for_field(value, field, empty_value_display):
from django.contrib.admin.templatetags.admin_list import _boolean_icon
...
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
...
}}}
There is no test case for the `display_for_field` function when a
`FileField` object is passed. -->
[https://github.com/django/django/blob/main/tests/admin_utils/tests.py
admin_utils test code]
When the `FileField` handling was added in the above function, I found
that the test was conducted indirectly through the `FileWidget` readonly
attribute. -->
[https://github.com/django/django/blob/main/tests/admin_widgets/tests.py#L654
test code]
However, I believe it would be better to have a direct test case for when
a `FileField` is passed, considering that `display_for_field` function is
globally accessible.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36038#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070193fe0ef144-cb6d8453-9f89-4aaf-955c-f3d89db7b216-000000%40eu-central-1.amazonses.com.