mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 17:36:49 +01:00
Move page content type usage view to wagtail.admin.views.pages.usage
This commit is contained in:
parent
54c6bf8998
commit
085f38f457
@ -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():
|
||||
|
31
wagtail/admin/views/pages/usage.py
Normal file
31
wagtail/admin/views/pages/usage.py
Normal 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,
|
||||
})
|
Loading…
Reference in New Issue
Block a user