mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Give generic IndexView a usable default listing
Comment out `template_name = 'wagtailsites/index.html'` in wagtail.sites.views to see it in action. This consists of a single 'Name' column consisting of the str() representation of the object, linking to the URL obtained from edit_url_name.
This commit is contained in:
parent
975c85f117
commit
48a2813f39
@ -1,5 +1,5 @@
|
||||
{% extends "wagtailadmin/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load i18n wagtailadmin_tags %}
|
||||
|
||||
{% block titletag %}{{ page_title }} {{ page_subtitle }}{% endblock %}
|
||||
|
||||
@ -12,5 +12,8 @@
|
||||
{% endif %}
|
||||
|
||||
{% block listing %}
|
||||
<div class="nice-padding">
|
||||
{% component table %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
@ -8,6 +8,7 @@ from django.views.generic.edit import BaseCreateView, BaseDeleteView, BaseUpdate
|
||||
from django.views.generic.list import BaseListView
|
||||
|
||||
from wagtail.admin import messages
|
||||
from wagtail.admin.ui.tables import Table, TitleColumn
|
||||
from wagtail.core.log_actions import log
|
||||
|
||||
from .base import WagtailAdminTemplateMixin
|
||||
@ -19,15 +20,25 @@ class IndexView(PermissionCheckedMixin, WagtailAdminTemplateMixin, BaseListView)
|
||||
index_url_name = None
|
||||
add_url_name = None
|
||||
edit_url_name = None
|
||||
template_name = 'wagtailadmin/generic/index.html'
|
||||
context_object_name = None
|
||||
any_permission_required = ['add', 'change', 'delete']
|
||||
|
||||
def get_columns(self):
|
||||
try:
|
||||
return self.columns
|
||||
except AttributeError:
|
||||
return [
|
||||
TitleColumn('name', accessor=str, url_name=self.edit_url_name),
|
||||
]
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['can_add'] = (
|
||||
self.permission_policy is None
|
||||
or self.permission_policy.user_has_permission(self.request.user, 'add')
|
||||
)
|
||||
context['table'] = Table(self.get_columns(), context['object_list'])
|
||||
return context
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user