|
22 | 22 | from django.contrib.admin.utils import ( |
23 | 23 | NestedObjects, |
24 | 24 | construct_change_message, |
| 25 | + display_for_value, |
25 | 26 | flatten_fieldsets, |
26 | 27 | get_deleted_objects, |
27 | 28 | lookup_spawns_duplicates, |
|
74 | 75 | SOURCE_MODEL_VAR = "_source_model" |
75 | 76 | TO_FIELD_VAR = "_to_field" |
76 | 77 | IS_FACETS_VAR = "_facets" |
| 78 | +EMPTY_VALUE_STRING = "-" |
77 | 79 |
|
78 | 80 |
|
79 | 81 | class ShowFacets(enum.Enum): |
@@ -1394,10 +1396,13 @@ def response_add(self, request, obj, post_url_continue=None): |
1394 | 1396 | current_app=self.admin_site.name, |
1395 | 1397 | ) |
1396 | 1398 | # Add a link to the object's change form if the user can edit the obj. |
| 1399 | + obj_display = display_for_value(str(obj), EMPTY_VALUE_STRING) |
1397 | 1400 | if self.has_change_permission(request, obj): |
1398 | | - obj_repr = format_html('<a href="{}">{}</a>', urlquote(obj_url), obj) |
| 1401 | + obj_repr = format_html( |
| 1402 | + '<a href="{}">{}</a>', urlquote(obj_url), obj_display |
| 1403 | + ) |
1399 | 1404 | else: |
1400 | | - obj_repr = str(obj) |
| 1405 | + obj_repr = obj_display |
1401 | 1406 | msg_dict = { |
1402 | 1407 | "name": opts.verbose_name, |
1403 | 1408 | "obj": obj_repr, |
@@ -1547,9 +1552,12 @@ def response_change(self, request, obj): |
1547 | 1552 | preserved_filters = self.get_preserved_filters(request) |
1548 | 1553 | preserved_qsl = self._get_preserved_qsl(request, preserved_filters) |
1549 | 1554 |
|
| 1555 | + obj_display = display_for_value(str(obj), EMPTY_VALUE_STRING) |
1550 | 1556 | msg_dict = { |
1551 | 1557 | "name": opts.verbose_name, |
1552 | | - "obj": format_html('<a href="{}">{}</a>', urlquote(request.path), obj), |
| 1558 | + "obj": format_html( |
| 1559 | + '<a href="{}">{}</a>', urlquote(request.path), obj_display |
| 1560 | + ), |
1553 | 1561 | } |
1554 | 1562 | if "_continue" in request.POST: |
1555 | 1563 | msg = format_html( |
@@ -1728,7 +1736,7 @@ def response_delete(self, request, obj_display, obj_id): |
1728 | 1736 | _("The %(name)s “%(obj)s” was deleted successfully.") |
1729 | 1737 | % { |
1730 | 1738 | "name": self.opts.verbose_name, |
1731 | | - "obj": obj_display, |
| 1739 | + "obj": display_for_value(str(obj_display), EMPTY_VALUE_STRING), |
1732 | 1740 | }, |
1733 | 1741 | messages.SUCCESS, |
1734 | 1742 | ) |
@@ -1951,7 +1959,9 @@ def _changeform_view(self, request, object_id, form_url, extra_context): |
1951 | 1959 | context = { |
1952 | 1960 | **self.admin_site.each_context(request), |
1953 | 1961 | "title": title % self.opts.verbose_name, |
1954 | | - "subtitle": str(obj) if obj else None, |
| 1962 | + "subtitle": ( |
| 1963 | + display_for_value(str(obj), EMPTY_VALUE_STRING) if obj else None |
| 1964 | + ), |
1955 | 1965 | "adminform": admin_form, |
1956 | 1966 | "object_id": object_id, |
1957 | 1967 | "original": obj, |
@@ -2252,6 +2262,7 @@ def _delete_view(self, request, object_id, extra_context): |
2252 | 2262 | "subtitle": None, |
2253 | 2263 | "object_name": object_name, |
2254 | 2264 | "object": obj, |
| 2265 | + "escaped_object": display_for_value(str(obj), EMPTY_VALUE_STRING), |
2255 | 2266 | "deleted_objects": deleted_objects, |
2256 | 2267 | "model_count": dict(model_count).items(), |
2257 | 2268 | "perms_lacking": perms_needed, |
@@ -2300,7 +2311,8 @@ def history_view(self, request, object_id, extra_context=None): |
2300 | 2311 |
|
2301 | 2312 | context = { |
2302 | 2313 | **self.admin_site.each_context(request), |
2303 | | - "title": _("Change history: %s") % obj, |
| 2314 | + "title": _("Change history: %s") |
| 2315 | + % display_for_value(str(obj), EMPTY_VALUE_STRING), |
2304 | 2316 | "subtitle": None, |
2305 | 2317 | "action_list": page_obj, |
2306 | 2318 | "page_range": page_range, |
|
0 commit comments