0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Move page content type usage view to wagtail.admin.views.pages.usage

This commit is contained in:
Matt Westcott 2020-08-05 17:46:41 +01:00 committed by Matt Westcott
parent 54c6bf8998
commit 085f38f457
2 changed files with 33 additions and 28 deletions

View File

@ -1,8 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator
from django.db import transaction
from django.http import Http404, HttpResponse
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import reverse
@ -24,34 +22,10 @@ from wagtail.admin.views.pages.move import * # noqa
from wagtail.admin.views.pages.preview import * # noqa
from wagtail.admin.views.pages.revisions import * # noqa
from wagtail.admin.views.pages.search import * # noqa
from wagtail.admin.views.pages.usage import * # noqa
from wagtail.admin.views.pages.workflow import * # noqa
def content_type_use(request, content_type_app_name, content_type_model_name):
try:
content_type = ContentType.objects.get_by_natural_key(content_type_app_name, content_type_model_name)
except ContentType.DoesNotExist:
raise Http404
page_class = content_type.model_class()
# page_class must be a Page type and not some other random model
if not issubclass(page_class, Page):
raise Http404
pages = page_class.objects.all()
paginator = Paginator(pages, per_page=10)
pages = paginator.get_page(request.GET.get('p'))
return TemplateResponse(request, 'wagtailadmin/pages/content_type_use.html', {
'pages': pages,
'app_name': content_type_app_name,
'content_type': content_type,
'page_class': page_class,
})
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id).specific
if not page.permissions_for_user(request.user).can_delete():

View File

@ -0,0 +1,31 @@
from django.contrib.contenttypes.models import ContentType
from django.core.paginator import Paginator
from django.http import Http404
from django.template.response import TemplateResponse
from wagtail.core.models import Page
def content_type_use(request, content_type_app_name, content_type_model_name):
try:
content_type = ContentType.objects.get_by_natural_key(content_type_app_name, content_type_model_name)
except ContentType.DoesNotExist:
raise Http404
page_class = content_type.model_class()
# page_class must be a Page type and not some other random model
if not issubclass(page_class, Page):
raise Http404
pages = page_class.objects.all()
paginator = Paginator(pages, per_page=10)
pages = paginator.get_page(request.GET.get('p'))
return TemplateResponse(request, 'wagtailadmin/pages/content_type_use.html', {
'pages': pages,
'app_name': content_type_app_name,
'content_type': content_type,
'page_class': page_class,
})