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 %}
|
{% load i18n wagtailadmin_tags %}
|
||||||
|
|
||||||
{% if show_locale_labels %}
|
{% if show_locale_controls %}
|
||||||
<div>
|
<div>
|
||||||
{% if locale_options %}
|
{% if locale_options %}
|
||||||
{% if selected_locale %}
|
{% if selected_locale %}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ value }}
|
{{ value }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if column.show_locale_labels and page.depth == 2 %}
|
{% if show_locale_labels %}
|
||||||
{% status page.locale.get_display_name classname="w-status--label" %}
|
{% status page.locale.get_display_name classname="w-status--label" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
|
<td {% if column.classname %}class="{{ column.classname }}"{% endif %}>
|
||||||
{% if value %}
|
{% if value %}
|
||||||
<a href="{% url 'wagtailadmin_choose_page_child' value.id %}" class="navigate-parent">{{ value.get_admin_display_title }}</a>
|
<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 %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load l10n %}
|
{% load l10n %}
|
||||||
<td id="page_{{ page.pk|unlocalize }}_title" class="title" data-listing-page-title>
|
<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>
|
</td>
|
||||||
|
|
|
@ -72,7 +72,12 @@ class NavigateToChildrenColumn(BaseColumn):
|
||||||
|
|
||||||
class PageTable(Table):
|
class PageTable(Table):
|
||||||
def __init__(
|
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)
|
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."
|
"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):
|
def get_ascending_title_text(self, column):
|
||||||
return self.ascending_title_text_format % {
|
return self.ascending_title_text_format % {
|
||||||
"parent": self.parent_page and self.parent_page.get_admin_display_title(),
|
"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):
|
def get_context_data(self, parent_context):
|
||||||
context = super().get_context_data(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")
|
context["perms"] = parent_context.get("perms")
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -101,6 +101,15 @@ def can_choose_page(
|
||||||
class PageChooserTable(Table):
|
class PageChooserTable(Table):
|
||||||
classname = "listing chooser"
|
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):
|
def get_row_classname(self, page):
|
||||||
classnames = []
|
classnames = []
|
||||||
if page.is_parent_page:
|
if page.is_parent_page:
|
||||||
|
@ -116,11 +125,8 @@ class PageChooserTable(Table):
|
||||||
class PageTitleColumn(Column):
|
class PageTitleColumn(Column):
|
||||||
cell_template_name = "wagtailadmin/chooser/tables/page_title_cell.html"
|
cell_template_name = "wagtailadmin/chooser/tables/page_title_cell.html"
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, *args, is_multiple_choice=False, **kwargs):
|
||||||
self, *args, show_locale_labels=False, is_multiple_choice=False, **kwargs
|
|
||||||
):
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.show_locale_labels = show_locale_labels
|
|
||||||
self.is_multiple_choice = is_multiple_choice
|
self.is_multiple_choice = is_multiple_choice
|
||||||
|
|
||||||
def get_value(self, instance):
|
def get_value(self, instance):
|
||||||
|
@ -129,19 +135,24 @@ class PageTitleColumn(Column):
|
||||||
def get_cell_context_data(self, instance, parent_context):
|
def get_cell_context_data(self, instance, parent_context):
|
||||||
context = super().get_cell_context_data(instance, parent_context)
|
context = super().get_cell_context_data(instance, parent_context)
|
||||||
context["page"] = instance
|
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
|
return context
|
||||||
|
|
||||||
|
|
||||||
class ParentPageColumn(Column):
|
class ParentPageColumn(Column):
|
||||||
cell_template_name = "wagtailadmin/chooser/tables/parent_page_cell.html"
|
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):
|
def get_value(self, instance):
|
||||||
return instance.get_parent()
|
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):
|
class PageStatusColumn(Column):
|
||||||
cell_template_name = "wagtailadmin/chooser/tables/page_status_cell.html"
|
cell_template_name = "wagtailadmin/chooser/tables/page_status_cell.html"
|
||||||
|
@ -170,7 +181,6 @@ class BrowseView(View):
|
||||||
PageTitleColumn(
|
PageTitleColumn(
|
||||||
"title",
|
"title",
|
||||||
label=_("Title"),
|
label=_("Title"),
|
||||||
show_locale_labels=self.i18n_enabled,
|
|
||||||
is_multiple_choice=self.is_multiple_choice,
|
is_multiple_choice=self.is_multiple_choice,
|
||||||
),
|
),
|
||||||
DateColumn(
|
DateColumn(
|
||||||
|
@ -361,6 +371,7 @@ class BrowseView(View):
|
||||||
table = PageChooserTable(
|
table = PageChooserTable(
|
||||||
self.columns,
|
self.columns,
|
||||||
[self.parent_page] + list(pages),
|
[self.parent_page] + list(pages),
|
||||||
|
show_locale_labels=self.i18n_enabled,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Render
|
# Render
|
||||||
|
@ -378,7 +389,7 @@ class BrowseView(View):
|
||||||
for desired_class in self.desired_classes
|
for desired_class in self.desired_classes
|
||||||
],
|
],
|
||||||
"page_types_restricted": (page_type_string != "wagtailcore.page"),
|
"page_types_restricted": (page_type_string != "wagtailcore.page"),
|
||||||
"show_locale_labels": self.i18n_enabled,
|
"show_locale_controls": self.i18n_enabled,
|
||||||
"locale_options": locale_options,
|
"locale_options": locale_options,
|
||||||
"selected_locale": selected_locale,
|
"selected_locale": selected_locale,
|
||||||
"is_multiple_choice": self.is_multiple_choice,
|
"is_multiple_choice": self.is_multiple_choice,
|
||||||
|
@ -398,12 +409,8 @@ class SearchView(View):
|
||||||
@property
|
@property
|
||||||
def columns(self):
|
def columns(self):
|
||||||
cols = [
|
cols = [
|
||||||
PageTitleColumn(
|
PageTitleColumn("title", label=_("Title")),
|
||||||
"title", label=_("Title"), show_locale_labels=self.i18n_enabled
|
ParentPageColumn("parent", label=_("Parent")),
|
||||||
),
|
|
||||||
ParentPageColumn(
|
|
||||||
"parent", label=_("Parent"), show_locale_labels=self.i18n_enabled
|
|
||||||
),
|
|
||||||
DateColumn(
|
DateColumn(
|
||||||
"updated",
|
"updated",
|
||||||
label=_("Updated"),
|
label=_("Updated"),
|
||||||
|
@ -466,6 +473,7 @@ class SearchView(View):
|
||||||
table = PageChooserTable(
|
table = PageChooserTable(
|
||||||
self.columns,
|
self.columns,
|
||||||
pages,
|
pages,
|
||||||
|
show_locale_labels=self.i18n_enabled,
|
||||||
)
|
)
|
||||||
|
|
||||||
return TemplateResponse(
|
return TemplateResponse(
|
||||||
|
@ -478,7 +486,6 @@ class SearchView(View):
|
||||||
"table": table,
|
"table": table,
|
||||||
"pages": pages,
|
"pages": pages,
|
||||||
"page_type_string": page_type_string,
|
"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 = super().get_table_kwargs()
|
||||||
kwargs["use_row_ordering_attributes"] = self.show_ordering_column
|
kwargs["use_row_ordering_attributes"] = self.show_ordering_column
|
||||||
kwargs["parent_page"] = self.parent_page
|
kwargs["parent_page"] = self.parent_page
|
||||||
|
kwargs["show_locale_labels"] = self.i18n_enabled and self.parent_page.is_root()
|
||||||
|
|
||||||
if self.show_ordering_column:
|
if self.show_ordering_column:
|
||||||
kwargs["attrs"] = {
|
kwargs["attrs"] = {
|
||||||
"aria-description": gettext(
|
"aria-description": gettext(
|
||||||
|
@ -182,6 +184,7 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
||||||
if self.show_ordering_column:
|
if self.show_ordering_column:
|
||||||
self.columns = self.columns.copy()
|
self.columns = self.columns.copy()
|
||||||
self.columns[0] = OrderingColumn("ordering", width="10px", sort_key="ord")
|
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)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
@ -203,13 +206,11 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
||||||
"side_panels": side_panels,
|
"side_panels": side_panels,
|
||||||
"locale": None,
|
"locale": None,
|
||||||
"translations": [],
|
"translations": [],
|
||||||
"show_locale_labels": False,
|
|
||||||
"index_url": self.get_index_url(),
|
"index_url": self.get_index_url(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if getattr(settings, "WAGTAIL_I18N_ENABLED", False):
|
if self.i18n_enabled and not self.parent_page.is_root():
|
||||||
if not self.parent_page.is_root():
|
|
||||||
context.update(
|
context.update(
|
||||||
{
|
{
|
||||||
"locale": self.parent_page.locale,
|
"locale": self.parent_page.locale,
|
||||||
|
@ -226,7 +227,5 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
context["show_locale_labels"] = True
|
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -166,6 +166,11 @@ class BaseSearchView(PermissionCheckedMixin, BaseListingView):
|
||||||
def get_index_url(self):
|
def get_index_url(self):
|
||||||
return reverse("wagtailadmin_pages:search")
|
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]:
|
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context.update(
|
context.update(
|
||||||
|
@ -176,7 +181,6 @@ class BaseSearchView(PermissionCheckedMixin, BaseListingView):
|
||||||
"selected_content_type": self.selected_content_type,
|
"selected_content_type": self.selected_content_type,
|
||||||
"ordering": self.ordering,
|
"ordering": self.ordering,
|
||||||
"index_url": self.get_index_url(),
|
"index_url": self.get_index_url(),
|
||||||
"show_locale_labels": self.show_locale_labels,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return context
|
return context
|
||||||
|
|
Ładowanie…
Reference in New Issue