From c0505bb8aa0e422fd40a68e340956a5adf8ee34a Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Sun, 16 Aug 2015 16:13:49 +0200 Subject: [PATCH] Extract generic functionality from sites index view --- wagtail/wagtailadmin/views/generic.py | 12 ++++++++++++ wagtail/wagtailsites/views.py | 13 +++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) 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):