kopia lustrzana https://github.com/wagtail/wagtail
Add get_table_kwargs mechanism to BaseListingView
This allows passing additional kwargs to the table constructor. Use this to pass use_row_ordering_attributes to PageTable, rather than patching the already-created table object.pull/10626/head
rodzic
f057e65c99
commit
03c0f28797
|
@ -70,8 +70,11 @@ class NavigateToChildrenColumn(BaseColumn):
|
|||
|
||||
|
||||
class PageTable(Table):
|
||||
# If true, attributes will be added on the <tr> element to support reordering
|
||||
use_row_ordering_attributes = False
|
||||
def __init__(self, *args, use_row_ordering_attributes=False, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# If true, attributes will be added on the <tr> element to support reordering
|
||||
self.use_row_ordering_attributes = use_row_ordering_attributes
|
||||
|
||||
def get_row_classname(self, instance):
|
||||
if not instance.live:
|
||||
|
|
|
@ -149,13 +149,18 @@ class BaseListingView(WagtailAdminTemplateMixin, BaseListView):
|
|||
ordering = self.default_ordering
|
||||
return ordering
|
||||
|
||||
def get_table(self, object_list, **kwargs):
|
||||
def get_table_kwargs(self):
|
||||
return {
|
||||
"ordering": self.get_ordering(),
|
||||
"classname": self.table_classname,
|
||||
"base_url": self.index_url,
|
||||
}
|
||||
|
||||
def get_table(self, object_list):
|
||||
return self.table_class(
|
||||
self.columns,
|
||||
object_list,
|
||||
ordering=self.get_ordering(),
|
||||
classname=self.table_classname,
|
||||
**kwargs,
|
||||
**self.get_table_kwargs(),
|
||||
)
|
||||
|
||||
def get_index_url(self):
|
||||
|
@ -165,10 +170,10 @@ class BaseListingView(WagtailAdminTemplateMixin, BaseListView):
|
|||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
|
||||
index_url = self.get_index_url()
|
||||
context["index_url"] = index_url
|
||||
self.index_url = self.get_index_url()
|
||||
table = self.get_table(context["object_list"])
|
||||
|
||||
table = self.get_table(context["object_list"], base_url=index_url)
|
||||
context["index_url"] = self.index_url
|
||||
context["table"] = table
|
||||
context["media"] = table.media
|
||||
context["is_paginated"] = bool(self.paginate_by)
|
||||
|
|
|
@ -164,17 +164,19 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
|||
def get_index_url(self):
|
||||
return reverse("wagtailadmin_explore", args=[self.parent_page.id])
|
||||
|
||||
def get_table_kwargs(self):
|
||||
kwargs = super().get_table_kwargs()
|
||||
kwargs["use_row_ordering_attributes"] = self.show_ordering_column
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
show_ordering_column = self.ordering == "ord"
|
||||
if show_ordering_column:
|
||||
self.show_ordering_column = self.ordering == "ord"
|
||||
if self.show_ordering_column:
|
||||
self.columns = self.columns.copy()
|
||||
self.columns[0] = OrderingColumn("ordering", width="10px", sort_key="ord")
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
if show_ordering_column:
|
||||
context["table"].use_row_ordering_attributes = True
|
||||
|
||||
side_panels = PageSidePanels(
|
||||
self.request,
|
||||
self.parent_page.get_latest_revision_as_object(),
|
||||
|
@ -193,8 +195,6 @@ class IndexView(PermissionCheckedMixin, BaseListingView):
|
|||
"side_panels": side_panels,
|
||||
"locale": None,
|
||||
"translations": [],
|
||||
"show_ordering_column": show_ordering_column,
|
||||
"show_bulk_actions": not show_ordering_column,
|
||||
"show_locale_labels": False,
|
||||
"index_url": self.get_index_url(),
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue