Add support for showing on delete information on generic usage view

pull/10072/head
Sage Abdullah 2023-02-10 14:52:51 +00:00
rodzic 6165f8a004
commit 8bb055652c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
3 zmienionych plików z 13 dodań i 3 usunięć

Wyświetl plik

@ -5,8 +5,7 @@
{% if edit_url %}
<a href="{{ edit_url }}#content-path-{{ reference.content_path }}">
{% endif %}
{{ reference.describe_source_field }}
{% if edit_url %}</a>{% endif %}
{{ reference.describe_source_field }}{% if edit_url %}</a>{% endif %}{% if describe_on_delete %}: {{ reference.describe_on_delete }}{% endif %}
</li>
{% endfor %}
</ul>

Wyświetl plik

@ -290,9 +290,11 @@ class ReferencesColumn(Column):
sort_key=None,
width=None,
get_url=None,
describe_on_delete=False,
):
super().__init__(name, label, accessor, classname, sort_key, width)
self._get_url_func = get_url
self.describe_on_delete = describe_on_delete
def get_edit_url(self, instance):
if self._get_url_func:
@ -301,6 +303,7 @@ class ReferencesColumn(Column):
def get_cell_context_data(self, instance, parent_context):
context = super().get_cell_context_data(instance, parent_context)
context["edit_url"] = self.get_edit_url(instance)
context["describe_on_delete"] = self.describe_on_delete
return context

Wyświetl plik

@ -1,3 +1,4 @@
from django.utils.functional import cached_property
from django.utils.text import capfirst
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy
@ -19,6 +20,10 @@ class UsageView(BaseObjectMixin, IndexView):
is_searchable = False
page_title = gettext_lazy("Usage of")
@cached_property
def describe_on_delete(self):
return bool(self.request.GET.get("describe_on_delete"))
def get_object(self):
object = super().get_object()
if isinstance(object, DraftStateMixin):
@ -49,9 +54,12 @@ class UsageView(BaseObjectMixin, IndexView):
),
tables.ReferencesColumn(
"field",
label=_("Field"),
label=_("If you confirm deletion")
if self.describe_on_delete
else _("Field"),
accessor="references",
get_url=lambda r: r["edit_url"],
describe_on_delete=self.describe_on_delete,
),
]