kopia lustrzana https://github.com/wagtail/wagtail
Standardise on passing show_locale_labels as a kwarg on the table constructor
instead of plucking it out of the parent template context, or making it a flag on the column definitionpull/10626/head
rodzic
0b3f4dc1e8
commit
61f3cfed38
|
@ -1,6 +1,6 @@
|
|||
{% load i18n wagtailadmin_tags %}
|
||||
|
||||
{% if show_locale_labels %}
|
||||
{% if show_locale_controls %}
|
||||
<div>
|
||||
{% if locale_options %}
|
||||
{% if selected_locale %}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
{% else %}
|
||||
{{ value }}
|
||||
{% endif %}
|
||||
{% if column.show_locale_labels and page.depth == 2 %}
|
||||
{% if show_locale_labels %}
|
||||
{% status page.locale.get_display_name classname="w-status--label" %}
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
|
||||
{% if value %}
|
||||
<a href="{% url 'wagtailadmin_choose_page_child' value.id %}" class="navigate-parent">{{ value.get_admin_display_title }}</a>
|
||||
{% if column.show_locale_labels %}{% status value.locale.get_display_name classname="w-status--label" %}{% endif %}
|
||||
{% if show_locale_labels %}{% status value.locale.get_display_name classname="w-status--label" %}{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load l10n %}
|
||||
<td id="page_{{ page.pk|unlocalize }}_title" class="title" data-listing-page-title>
|
||||
{% include "wagtailadmin/pages/listing/_page_title_explore.html" with page=instance %}
|
||||
{% include "wagtailadmin/pages/listing/_page_title_explore.html" with page=instance show_locale_labels=show_locale_labels %}
|
||||
</td>
|
||||
|
|
|
@ -72,7 +72,12 @@ class NavigateToChildrenColumn(BaseColumn):
|
|||
|
||||
class PageTable(Table):
|
||||
def __init__(
|
||||
self, *args, use_row_ordering_attributes=False, parent_page=None, **kwargs
|
||||
self,
|
||||
*args,
|
||||
use_row_ordering_attributes=False,
|
||||
parent_page=None,
|
||||
show_locale_labels=False,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
@ -95,6 +100,8 @@ class PageTable(Table):
|
|||
"Sort the order of child pages within '%(parent)s' by '%(label)s' in descending order."
|
||||
)
|
||||
|
||||
self.show_locale_labels = show_locale_labels
|
||||
|
||||
def get_ascending_title_text(self, column):
|
||||
return self.ascending_title_text_format % {
|
||||
"parent": self.parent_page and self.parent_page.get_admin_display_title(),
|
||||
|
@ -122,6 +129,6 @@ class PageTable(Table):
|
|||
|
||||
def get_context_data(self, parent_context):
|
||||
context = super().get_context_data(parent_context)
|
||||
context["show_locale_labels"] = parent_context.get("show_locale_labels")
|
||||
context["show_locale_labels"] = self.show_locale_labels
|
||||
context["perms"] = parent_context.get("perms")
|
||||
return context
|
||||
|
|
|
@ -101,6 +101,15 @@ def can_choose_page(
|
|||
class PageChooserTable(Table):
|
||||
classname = "listing chooser"
|
||||
|
||||
def __init__(self, *args, show_locale_labels=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.show_locale_labels = show_locale_labels
|
||||
|
||||
def get_context_data(self, parent_context):
|
||||
context = super().get_context_data(parent_context)
|
||||
context["show_locale_labels"] = self.show_locale_labels
|
||||
return context
|
||||
|
||||
def get_row_classname(self, page):
|
||||
classnames = []
|
||||
if page.is_parent_page:
|
||||
|
@ -116,11 +125,8 @@ class PageChooserTable(Table):
|
|||
class PageTitleColumn(Column):
|
||||
cell_template_name = "wagtailadmin/chooser/tables/page_title_cell.html"
|
||||
|
||||
def __init__(
|
||||
self, *args, show_locale_labels=False, is_multiple_choice=False, **kwargs
|
||||
):
|
||||
def __init__(self, *args, is_multiple_choice=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.show_locale_labels = show_locale_labels
|
||||
self.is_multiple_choice = is_multiple_choice
|
||||
|
||||
def get_value(self, instance):
|
||||
|
@ -129,19 +135,24 @@ class PageTitleColumn(Column):
|
|||
def get_cell_context_data(self, instance, parent_context):
|
||||
context = super().get_cell_context_data(instance, parent_context)
|
||||
context["page"] = instance
|
||||
# only need to show locale labels for top-level pages
|
||||
context["show_locale_labels"] = (
|
||||
parent_context.get("show_locale_labels") and instance.depth == 2
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
class ParentPageColumn(Column):
|
||||
cell_template_name = "wagtailadmin/chooser/tables/parent_page_cell.html"
|
||||
|
||||
def __init__(self, *args, show_locale_labels=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.show_locale_labels = show_locale_labels
|
||||
|
||||
def get_value(self, instance):
|
||||
return instance.get_parent()
|
||||
|
||||
def get_cell_context_data(self, instance, parent_context):
|
||||
context = super().get_cell_context_data(instance, parent_context)
|
||||
context["show_locale_labels"] = parent_context.get("show_locale_labels")
|
||||
return context
|
||||
|
||||
|
||||
class PageStatusColumn(Column):
|
||||
cell_template_name = "wagtailadmin/chooser/tables/page_status_cell.html"
|
||||
|
@ -170,7 +181,6 @@ class BrowseView(View):
|
|||
PageTitleColumn(
|
||||
"title",
|
||||
label=_("Title"),
|
||||
show_locale_labels=self.i18n_enabled,
|
||||
is_multiple_choice=self.is_multiple_choice,
|
||||
),
|
||||
DateColumn(
|
||||
|
@ -361,6 +371,7 @@ class BrowseView(View):
|
|||
table = PageChooserTable(
|
||||
self.columns,
|
||||
[self.parent_page] + list(pages),
|
||||
show_locale_labels=self.i18n_enabled,
|
||||
)
|
||||
|
||||
# Render
|
||||
|
@ -378,7 +389,7 @@ class BrowseView(View):
|
|||
for desired_class in self.desired_classes
|
||||
],
|
||||
"page_types_restricted": (page_type_string != "wagtailcore.page"),
|
||||
"show_locale_labels": self.i18n_enabled,
|
||||
"show_locale_controls": self.i18n_enabled,
|
||||
"locale_options": locale_options,
|
||||
"selected_locale": selected_locale,
|
||||
"is_multiple_choice": self.is_multiple_choice,
|
||||
|
@ -398,12 +409,8 @@ class SearchView(View):
|
|||
@property
|
||||
def columns(self):
|
||||
cols = [
|
||||
PageTitleColumn(
|
||||
"title", label=_("Title"), show_locale_labels=self.i18n_enabled
|
||||
),
|
||||
ParentPageColumn(
|
||||
"parent", label=_("Parent"), show_locale_labels=self.i18n_enabled
|
||||
),
|
||||
PageTitleColumn("title", label=_("Title")),
|
||||
ParentPageColumn("parent", label=_("Parent")),
|
||||
DateColumn(
|
||||
"updated",
|
||||
label=_("Updated"),
|
||||
|
@ -466,6 +473,7 @@ class SearchView(View):
|
|||
table = PageChooserTable(
|
||||
self.columns,
|
||||
pages,
|
||||
show_locale_labels=self.i18n_enabled,
|
||||
)
|
||||
|
||||
return TemplateResponse(
|
||||
|
@ -478,7 +486,6 @@ class SearchView(View):
|
|||
"table": table,
|
||||
"pages": pages,
|
||||
"page_type_string": page_type_string,
|
||||
"show_locale_labels": self.i18n_enabled,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
|
|
@ -169,6 +169,8 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
|||
kwargs = super().get_table_kwargs()
|
||||
kwargs["use_row_ordering_attributes"] = self.show_ordering_column
|
||||
kwargs["parent_page"] = self.parent_page
|
||||
kwargs["show_locale_labels"] = self.i18n_enabled and self.parent_page.is_root()
|
||||
|
||||
if self.show_ordering_column:
|
||||
kwargs["attrs"] = {
|
||||
"aria-description": gettext(
|
||||
|
@ -182,6 +184,7 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
|||
if self.show_ordering_column:
|
||||
self.columns = self.columns.copy()
|
||||
self.columns[0] = OrderingColumn("ordering", width="10px", sort_key="ord")
|
||||
self.i18n_enabled = getattr(settings, "WAGTAIL_I18N_ENABLED", False)
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
|
@ -203,30 +206,26 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
|||
"side_panels": side_panels,
|
||||
"locale": None,
|
||||
"translations": [],
|
||||
"show_locale_labels": False,
|
||||
"index_url": self.get_index_url(),
|
||||
}
|
||||
)
|
||||
|
||||
if getattr(settings, "WAGTAIL_I18N_ENABLED", False):
|
||||
if not self.parent_page.is_root():
|
||||
context.update(
|
||||
{
|
||||
"locale": self.parent_page.locale,
|
||||
"translations": [
|
||||
{
|
||||
"locale": translation.locale,
|
||||
"url": reverse(
|
||||
"wagtailadmin_explore", args=[translation.id]
|
||||
),
|
||||
}
|
||||
for translation in self.parent_page.get_translations()
|
||||
.only("id", "locale")
|
||||
.select_related("locale")
|
||||
],
|
||||
}
|
||||
)
|
||||
else:
|
||||
context["show_locale_labels"] = True
|
||||
if self.i18n_enabled and not self.parent_page.is_root():
|
||||
context.update(
|
||||
{
|
||||
"locale": self.parent_page.locale,
|
||||
"translations": [
|
||||
{
|
||||
"locale": translation.locale,
|
||||
"url": reverse(
|
||||
"wagtailadmin_explore", args=[translation.id]
|
||||
),
|
||||
}
|
||||
for translation in self.parent_page.get_translations()
|
||||
.only("id", "locale")
|
||||
.select_related("locale")
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
return context
|
||||
|
|
|
@ -166,6 +166,11 @@ class BaseSearchView(PermissionCheckedMixin, BaseListingView):
|
|||
def get_index_url(self):
|
||||
return reverse("wagtailadmin_pages:search")
|
||||
|
||||
def get_table_kwargs(self):
|
||||
kwargs = super().get_table_kwargs()
|
||||
kwargs["show_locale_labels"] = self.show_locale_labels
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(
|
||||
|
@ -176,7 +181,6 @@ class BaseSearchView(PermissionCheckedMixin, BaseListingView):
|
|||
"selected_content_type": self.selected_content_type,
|
||||
"ordering": self.ordering,
|
||||
"index_url": self.get_index_url(),
|
||||
"show_locale_labels": self.show_locale_labels,
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
|
Ładowanie…
Reference in New Issue