kopia lustrzana https://github.com/wagtail/wagtail
Extract generic functionality from sites index view
rodzic
1d535aa081
commit
c0505bb8aa
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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):
|
||||
|
|
Ładowanie…
Reference in New Issue