kopia lustrzana https://github.com/wagtail/wagtail
allow edit URL to be overridden from IndexView
This means we're not limited to named URL routes that take a single ID argument (which wouldn't work for snippets, for instance).pull/7574/head
rodzic
3827e848ac
commit
7740e06813
|
@ -107,9 +107,10 @@ class TitleColumn(Column):
|
|||
"""A column where data is styled as a title and wrapped in a link"""
|
||||
cell_template_name = "wagtailadmin/tables/title_cell.html"
|
||||
|
||||
def __init__(self, name, url_name=None, **kwargs):
|
||||
def __init__(self, name, url_name=None, get_url=None, **kwargs):
|
||||
super().__init__(name, **kwargs)
|
||||
self.url_name = url_name
|
||||
self._get_url_func = get_url
|
||||
|
||||
def get_cell_context_data(self, instance, parent_context):
|
||||
context = super().get_cell_context_data(instance, parent_context)
|
||||
|
@ -117,7 +118,10 @@ class TitleColumn(Column):
|
|||
return context
|
||||
|
||||
def get_link_url(self, instance, parent_context):
|
||||
return reverse(self.url_name, args=(instance.pk,))
|
||||
if self._get_url_func:
|
||||
return self._get_url_func(instance)
|
||||
else:
|
||||
return reverse(self.url_name, args=(instance.pk,))
|
||||
|
||||
|
||||
class StatusFlagColumn(Column):
|
||||
|
|
|
@ -29,9 +29,12 @@ class IndexView(PermissionCheckedMixin, WagtailAdminTemplateMixin, BaseListView)
|
|||
return self.columns
|
||||
except AttributeError:
|
||||
return [
|
||||
TitleColumn('name', accessor=str, url_name=self.edit_url_name),
|
||||
TitleColumn('name', accessor=str, get_url=lambda obj: self.get_edit_url(obj)),
|
||||
]
|
||||
|
||||
def get_edit_url(self, instance):
|
||||
return reverse(self.edit_url_name, args=(instance.pk,))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
table = Table(self.get_columns(), context['object_list'])
|
||||
|
|
Ładowanie…
Reference in New Issue