diff --git a/wagtail/wagtailadmin/views/generic.py b/wagtail/wagtailadmin/views/generic.py index 18b64ae95c..a70934d5ea 100644 --- a/wagtail/wagtailadmin/views/generic.py +++ b/wagtail/wagtailadmin/views/generic.py @@ -1,3 +1,4 @@ +from django.shortcuts import render from django.views.generic.base import View from wagtail.wagtailadmin.utils import permission_denied @@ -31,3 +32,14 @@ class PermissionCheckedView(View): return permission_denied(request) return super(PermissionCheckedView, self).dispatch(request, *args, **kwargs) + + +class IndexView(PermissionCheckedView): + def get_queryset(self): + return self.model.objects.all() + + def get(self, request): + object_list = self.get_queryset() + return render(request, self.template, { + self.context_object_name: object_list, + }) diff --git a/wagtail/wagtailsites/views.py b/wagtail/wagtailsites/views.py index 24a727626a..6341442ccd 100644 --- a/wagtail/wagtailsites/views.py +++ b/wagtail/wagtailsites/views.py @@ -5,17 +5,14 @@ from django.core.urlresolvers import reverse from wagtail.wagtailcore.models import Site from wagtail.wagtailsites.forms import SiteForm from wagtail.wagtailadmin import messages -from wagtail.wagtailadmin.views.generic import PermissionCheckedView +from wagtail.wagtailadmin.views.generic import PermissionCheckedView, IndexView -class Index(PermissionCheckedView): +class Index(IndexView): any_permission_required = ['wagtailcore.add_site', 'wagtailcore.change_site', 'wagtailcore.delete_site'] - - def get(self, request): - sites = Site.objects.all() - return render(request, 'wagtailsites/index.html', { - 'sites': sites, - }) + model = Site + context_object_name = 'sites' + template = 'wagtailsites/index.html' class Create(PermissionCheckedView):