Initial commit
This commit is contained in:
0
env/lib/python3.10/site-packages/wagtail/admin/api/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/admin/api/__init__.py
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/filters.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/filters.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/urls.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/urls.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/views.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/__pycache__/views.cpython-310.pyc
vendored
Normal file
Binary file not shown.
0
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__init__.py
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/base.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/base.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/convert_alias.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/convert_alias.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/copy.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/copy.cpython-310.pyc
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/create_alias.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/create_alias.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/delete.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/delete.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/move.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/move.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/publish.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/publish.cpython-310.pyc
vendored
Normal file
Binary file not shown.
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/unpublish.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/admin/api/actions/__pycache__/unpublish.cpython-310.pyc
vendored
Normal file
Binary file not shown.
6
env/lib/python3.10/site-packages/wagtail/admin/api/actions/base.py
vendored
Normal file
6
env/lib/python3.10/site-packages/wagtail/admin/api/actions/base.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class APIAction:
|
||||
serializer = None
|
||||
|
||||
def __init__(self, view, request):
|
||||
self.view = view
|
||||
self.request = request
|
||||
30
env/lib/python3.10/site-packages/wagtail/admin/api/actions/convert_alias.py
vendored
Normal file
30
env/lib/python3.10/site-packages/wagtail/admin/api/actions/convert_alias.py
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.convert_alias import ConvertAliasPageAction, ConvertAliasPageError
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class ConvertAliasPageAPIAction(APIAction):
|
||||
serializer = Serializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
return ConvertAliasPageAction(instance, user=self.request.user)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
new_page = action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
except ConvertAliasPageError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
serializer = self.view.get_serializer(new_page)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
67
env/lib/python3.10/site-packages/wagtail/admin/api/actions/copy.py
vendored
Normal file
67
env/lib/python3.10/site-packages/wagtail/admin/api/actions/copy.py
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.copy_page import CopyPageAction, CopyPageIntegrityError
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
from wagtail.coreutils import find_available_slug
|
||||
from wagtail.models import Page
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class CopyPageAPIActionSerializer(Serializer):
|
||||
# Note: CopyPageAction will validate the destination page
|
||||
destination_page_id = fields.IntegerField(required=False)
|
||||
recursive = fields.BooleanField(default=False, required=False)
|
||||
keep_live = fields.BooleanField(default=True, required=False)
|
||||
slug = fields.CharField(required=False)
|
||||
title = fields.CharField(required=False)
|
||||
|
||||
|
||||
class CopyPageAPIAction(APIAction):
|
||||
serializer = CopyPageAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
destination_page_id = data.get("destination_page_id")
|
||||
if destination_page_id is None:
|
||||
destination = instance.get_parent()
|
||||
else:
|
||||
destination = get_object_or_404(Page, id=destination_page_id)
|
||||
|
||||
update_attrs = {}
|
||||
if "slug" in data:
|
||||
update_attrs["slug"] = data["slug"]
|
||||
else:
|
||||
# If user didn't specify a particular slug, find an available one
|
||||
available_slug = find_available_slug(destination, instance.slug)
|
||||
if available_slug != instance.slug:
|
||||
update_attrs["slug"] = available_slug
|
||||
|
||||
if "title" in data:
|
||||
update_attrs["title"] = data["title"]
|
||||
|
||||
return CopyPageAction(
|
||||
page=instance,
|
||||
to=destination,
|
||||
recursive=data["recursive"],
|
||||
keep_live=data["keep_live"],
|
||||
update_attrs=update_attrs,
|
||||
user=self.request.user,
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
new_page = action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
except CopyPageIntegrityError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
serializer = self.view.get_serializer(new_page)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
51
env/lib/python3.10/site-packages/wagtail/admin/api/actions/copy_for_translation.py
vendored
Normal file
51
env/lib/python3.10/site-packages/wagtail/admin/api/actions/copy_for_translation.py
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.copy_for_translation import (
|
||||
CopyPageForTranslationAction,
|
||||
ParentNotTranslatedError,
|
||||
)
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
from wagtail.models.i18n import Locale
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class CopyForTranslationAPIActionSerializer(Serializer):
|
||||
locale = fields.CharField(max_length=100)
|
||||
copy_parents = fields.BooleanField(default=False, required=False)
|
||||
alias = fields.BooleanField(default=False, required=False)
|
||||
recursive = fields.BooleanField(default=False, required=False)
|
||||
|
||||
|
||||
class CopyForTranslationAPIAction(APIAction):
|
||||
serializer = CopyForTranslationAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
locale = get_object_or_404(Locale, language_code=data["locale"])
|
||||
|
||||
return CopyPageForTranslationAction(
|
||||
page=instance,
|
||||
locale=locale,
|
||||
copy_parents=data["copy_parents"],
|
||||
alias=data["alias"],
|
||||
user=self.request.user,
|
||||
include_subtree=data["recursive"],
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
translated_page = action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
except ParentNotTranslatedError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
serializer = self.view.get_serializer(translated_page)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
51
env/lib/python3.10/site-packages/wagtail/admin/api/actions/create_alias.py
vendored
Normal file
51
env/lib/python3.10/site-packages/wagtail/admin/api/actions/create_alias.py
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.create_alias import (
|
||||
CreatePageAliasAction,
|
||||
CreatePageAliasIntegrityError,
|
||||
)
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
from wagtail.models import Page
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class CreatePageAliasAPIActionSerializer(Serializer):
|
||||
destination_page_id = fields.IntegerField(required=False)
|
||||
recursive = fields.BooleanField(default=False, required=False)
|
||||
update_slug = fields.CharField(required=False)
|
||||
|
||||
|
||||
class CreatePageAliasAPIAction(APIAction):
|
||||
serializer = CreatePageAliasAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
parent, destination_page_id = None, data.get("destination_page_id")
|
||||
if destination_page_id:
|
||||
parent = get_object_or_404(Page, id=destination_page_id).specific
|
||||
|
||||
return CreatePageAliasAction(
|
||||
page=instance,
|
||||
recursive=data["recursive"],
|
||||
parent=parent,
|
||||
update_slug=data.get("update_slug"),
|
||||
user=self.request.user,
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
new_page = action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
except CreatePageAliasIntegrityError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
serializer = self.view.get_serializer(new_page)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
26
env/lib/python3.10/site-packages/wagtail/admin/api/actions/delete.py
vendored
Normal file
26
env/lib/python3.10/site-packages/wagtail/admin/api/actions/delete.py
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.delete_page import DeletePageAction
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class DeletePageAPIAction(APIAction):
|
||||
serializer = Serializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
return DeletePageAction(page=instance, user=self.request.user)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
53
env/lib/python3.10/site-packages/wagtail/admin/api/actions/move.py
vendored
Normal file
53
env/lib/python3.10/site-packages/wagtail/admin/api/actions/move.py
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.move_page import MovePageAction
|
||||
from wagtail.models import Page
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class MovePageAPIActionSerializer(Serializer):
|
||||
destination_page_id = fields.IntegerField(required=True)
|
||||
position = fields.ChoiceField(
|
||||
required=False,
|
||||
choices=[
|
||||
"left",
|
||||
"right",
|
||||
"first-child",
|
||||
"last-child",
|
||||
"first-sibling",
|
||||
"last-sibling",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class MovePageAPIAction(APIAction):
|
||||
serializer = MovePageAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
destination_page_id = data["destination_page_id"]
|
||||
target = get_object_or_404(Page, id=destination_page_id)
|
||||
|
||||
return MovePageAction(
|
||||
page=instance,
|
||||
target=target,
|
||||
pos=data.get("position"),
|
||||
user=self.request.user,
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
|
||||
instance.refresh_from_db()
|
||||
serializer = self.view.get_serializer(instance)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
34
env/lib/python3.10/site-packages/wagtail/admin/api/actions/publish.py
vendored
Normal file
34
env/lib/python3.10/site-packages/wagtail/admin/api/actions/publish.py
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.publish_page_revision import PublishPageRevisionAction
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class PublishPageAPIAction(APIAction):
|
||||
serializer = Serializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
user = self.request.user
|
||||
revision = instance.get_latest_revision() or instance.save_revision(user=user)
|
||||
return PublishPageRevisionAction(revision, user=user)
|
||||
|
||||
def execute(self, instance, data):
|
||||
try:
|
||||
action = self._action_from_data(instance, data)
|
||||
except RuntimeError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
try:
|
||||
action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
|
||||
new_page = instance.specific_class.objects.get(pk=instance.pk)
|
||||
serializer = self.view.get_serializer(new_page)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
42
env/lib/python3.10/site-packages/wagtail/admin/api/actions/revert_to_page_revision.py
vendored
Normal file
42
env/lib/python3.10/site-packages/wagtail/admin/api/actions/revert_to_page_revision.py
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.revert_to_page_revision import (
|
||||
RevertToPageRevisionAction,
|
||||
RevertToPageRevisionError,
|
||||
)
|
||||
from wagtail.api.v2.utils import BadRequestError
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class RevertToPageRevisionAPIActionSerializer(Serializer):
|
||||
revision_id = fields.IntegerField()
|
||||
|
||||
|
||||
class RevertToPageRevisionAPIAction(APIAction):
|
||||
serializer = RevertToPageRevisionAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
revision = get_object_or_404(instance.revisions, id=data["revision_id"])
|
||||
|
||||
return RevertToPageRevisionAction(
|
||||
page=instance, revision=revision, user=self.request.user
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
new_revision = action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
except RevertToPageRevisionError as e:
|
||||
raise BadRequestError(e.args[0])
|
||||
|
||||
serializer = self.view.get_serializer(new_revision.as_object())
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
35
env/lib/python3.10/site-packages/wagtail/admin/api/actions/unpublish.py
vendored
Normal file
35
env/lib/python3.10/site-packages/wagtail/admin/api/actions/unpublish.py
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||
from rest_framework import fields, status
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import Serializer
|
||||
|
||||
from wagtail.actions.unpublish_page import UnpublishPageAction
|
||||
|
||||
from .base import APIAction
|
||||
|
||||
|
||||
class UnpublishPageAPIActionSerializer(Serializer):
|
||||
recursive = fields.BooleanField(default=False, required=False)
|
||||
|
||||
|
||||
class UnpublishPageAPIAction(APIAction):
|
||||
serializer = UnpublishPageAPIActionSerializer
|
||||
|
||||
def _action_from_data(self, instance, data):
|
||||
return UnpublishPageAction(
|
||||
page=instance,
|
||||
user=self.request.user,
|
||||
include_descendants=data["recursive"],
|
||||
)
|
||||
|
||||
def execute(self, instance, data):
|
||||
action = self._action_from_data(instance, data)
|
||||
|
||||
try:
|
||||
action.execute()
|
||||
except DjangoValidationError as e:
|
||||
raise ValidationError(e.message_dict)
|
||||
|
||||
serializer = self.view.get_serializer(instance)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
45
env/lib/python3.10/site-packages/wagtail/admin/api/filters.py
vendored
Normal file
45
env/lib/python3.10/site-packages/wagtail/admin/api/filters.py
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
from rest_framework.filters import BaseFilterBackend
|
||||
|
||||
from wagtail import hooks
|
||||
from wagtail.api.v2.utils import BadRequestError, parse_boolean
|
||||
from wagtail.permissions import page_permission_policy
|
||||
|
||||
|
||||
class HasChildrenFilter(BaseFilterBackend):
|
||||
"""
|
||||
Filters the queryset by checking if the pages have children or not.
|
||||
This is useful when you want to get just the branches or just the leaves.
|
||||
"""
|
||||
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
if "has_children" in request.GET:
|
||||
try:
|
||||
has_children_filter = parse_boolean(request.GET["has_children"])
|
||||
except ValueError:
|
||||
raise BadRequestError("has_children must be 'true' or 'false'")
|
||||
|
||||
if has_children_filter is True:
|
||||
return queryset.filter(numchild__gt=0)
|
||||
else:
|
||||
return queryset.filter(numchild=0)
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
class ForExplorerFilter(BaseFilterBackend):
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
if request.GET.get("for_explorer"):
|
||||
if not hasattr(queryset, "_filtered_by_child_of"):
|
||||
raise BadRequestError(
|
||||
"filtering by for_explorer without child_of is not supported"
|
||||
)
|
||||
|
||||
parent_page = queryset._filtered_by_child_of
|
||||
for hook in hooks.get_hooks("construct_explorer_page_queryset"):
|
||||
queryset = hook(parent_page, queryset, request)
|
||||
|
||||
queryset = (
|
||||
page_permission_policy.explorable_instances(request.user) & queryset
|
||||
)
|
||||
|
||||
return queryset
|
||||
192
env/lib/python3.10/site-packages/wagtail/admin/api/serializers.py
vendored
Normal file
192
env/lib/python3.10/site-packages/wagtail/admin/api/serializers.py
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from rest_framework.fields import Field, ReadOnlyField
|
||||
|
||||
from wagtail.api.v2.serializers import PageSerializer, get_serializer_class
|
||||
from wagtail.api.v2.utils import get_full_url
|
||||
from wagtail.models import Page
|
||||
|
||||
|
||||
def get_model_listing_url(context, model):
|
||||
url_path = context["router"].get_model_listing_urlpath(model)
|
||||
|
||||
if url_path:
|
||||
return get_full_url(context["request"], url_path)
|
||||
|
||||
|
||||
class PageStatusField(Field):
|
||||
"""
|
||||
Serializes the "status" field.
|
||||
|
||||
Example:
|
||||
"status": {
|
||||
"status": "live",
|
||||
"live": true,
|
||||
"has_unpublished_changes": false
|
||||
},
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, page):
|
||||
return OrderedDict(
|
||||
[
|
||||
("status", page.status_string),
|
||||
("live", page.live),
|
||||
("has_unpublished_changes", page.has_unpublished_changes),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class PageChildrenField(Field):
|
||||
"""
|
||||
Serializes the "children" field.
|
||||
|
||||
Example:
|
||||
"children": {
|
||||
"count": 1,
|
||||
"listing_url": "/api/v1/pages/?child_of=2"
|
||||
}
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, page):
|
||||
return OrderedDict(
|
||||
[
|
||||
("count", self.context["base_queryset"].child_of(page).count()),
|
||||
(
|
||||
"listing_url",
|
||||
get_model_listing_url(self.context, Page)
|
||||
+ "?child_of="
|
||||
+ str(page.id),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class PageDescendantsField(Field):
|
||||
"""
|
||||
Serializes the "descendants" field.
|
||||
|
||||
Example:
|
||||
"descendants": {
|
||||
"count": 10,
|
||||
"listing_url": "/api/v1/pages/?descendant_of=2"
|
||||
}
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, page):
|
||||
return OrderedDict(
|
||||
[
|
||||
("count", self.context["base_queryset"].descendant_of(page).count()),
|
||||
(
|
||||
"listing_url",
|
||||
get_model_listing_url(self.context, Page)
|
||||
+ "?descendant_of="
|
||||
+ str(page.id),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class PageAncestorsField(Field):
|
||||
"""
|
||||
Serializes the page's ancestry.
|
||||
|
||||
Example:
|
||||
"ancestry": [
|
||||
{
|
||||
"id": 1,
|
||||
"meta": {
|
||||
"type": "wagtailcore.Page",
|
||||
"detail_url": "/api/v1/pages/1/"
|
||||
},
|
||||
"title": "Root"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"meta": {
|
||||
"type": "home.HomePage",
|
||||
"detail_url": "/api/v1/pages/2/"
|
||||
},
|
||||
"title": "Home"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, page):
|
||||
serializer_class = get_serializer_class(
|
||||
Page,
|
||||
["id", "type", "detail_url", "html_url", "title", "admin_display_title"],
|
||||
meta_fields=["type", "detail_url", "html_url"],
|
||||
base=AdminPageSerializer,
|
||||
)
|
||||
serializer = serializer_class(context=self.context, many=True)
|
||||
return serializer.to_representation(page.get_ancestors())
|
||||
|
||||
|
||||
class PageTranslationsField(Field):
|
||||
"""
|
||||
Serializes the page's translations.
|
||||
|
||||
Example:
|
||||
"translations": [
|
||||
{
|
||||
"id": 1,
|
||||
"meta": {
|
||||
"type": "home.HomePage",
|
||||
"detail_url": "/api/v1/pages/1/",
|
||||
"locale": "es"
|
||||
},
|
||||
"title": "Casa"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"meta": {
|
||||
"type": "home.HomePage",
|
||||
"detail_url": "/api/v1/pages/2/",
|
||||
"locale": "fr"
|
||||
},
|
||||
"title": "Maison"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, page):
|
||||
serializer_class = get_serializer_class(
|
||||
Page,
|
||||
[
|
||||
"id",
|
||||
"type",
|
||||
"detail_url",
|
||||
"html_url",
|
||||
"locale",
|
||||
"title",
|
||||
"admin_display_title",
|
||||
],
|
||||
meta_fields=["type", "detail_url", "html_url", "locale"],
|
||||
base=AdminPageSerializer,
|
||||
)
|
||||
serializer = serializer_class(context=self.context, many=True)
|
||||
return serializer.to_representation(page.get_translations())
|
||||
|
||||
|
||||
class AdminPageSerializer(PageSerializer):
|
||||
status = PageStatusField(read_only=True)
|
||||
children = PageChildrenField(read_only=True)
|
||||
descendants = PageDescendantsField(read_only=True)
|
||||
ancestors = PageAncestorsField(read_only=True)
|
||||
translations = PageTranslationsField(read_only=True)
|
||||
admin_display_title = ReadOnlyField(source="get_admin_display_title")
|
||||
16
env/lib/python3.10/site-packages/wagtail/admin/api/urls.py
vendored
Normal file
16
env/lib/python3.10/site-packages/wagtail/admin/api/urls.py
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
from django.urls import path
|
||||
|
||||
from wagtail import hooks
|
||||
from wagtail.api.v2.router import WagtailAPIRouter
|
||||
|
||||
from .views import PagesAdminAPIViewSet
|
||||
|
||||
admin_api = WagtailAPIRouter("wagtailadmin_api")
|
||||
admin_api.register_endpoint("pages", PagesAdminAPIViewSet)
|
||||
|
||||
for fn in hooks.get_hooks("construct_admin_api"):
|
||||
fn(admin_api)
|
||||
|
||||
urlpatterns = [
|
||||
path("main/", admin_api.urls),
|
||||
]
|
||||
161
env/lib/python3.10/site-packages/wagtail/admin/api/views.py
vendored
Normal file
161
env/lib/python3.10/site-packages/wagtail/admin/api/views.py
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import Http404
|
||||
from django.urls import path
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.response import Response
|
||||
|
||||
from wagtail.api.v2.views import PagesAPIViewSet
|
||||
from wagtail.models import Page
|
||||
|
||||
from .actions.convert_alias import ConvertAliasPageAPIAction
|
||||
from .actions.copy import CopyPageAPIAction
|
||||
from .actions.copy_for_translation import CopyForTranslationAPIAction
|
||||
from .actions.create_alias import CreatePageAliasAPIAction
|
||||
from .actions.delete import DeletePageAPIAction
|
||||
from .actions.move import MovePageAPIAction
|
||||
from .actions.publish import PublishPageAPIAction
|
||||
from .actions.revert_to_page_revision import RevertToPageRevisionAPIAction
|
||||
from .actions.unpublish import UnpublishPageAPIAction
|
||||
from .filters import ForExplorerFilter, HasChildrenFilter
|
||||
from .serializers import AdminPageSerializer
|
||||
|
||||
|
||||
class PagesAdminAPIViewSet(PagesAPIViewSet):
|
||||
base_serializer_class = AdminPageSerializer
|
||||
authentication_classes = [SessionAuthentication]
|
||||
|
||||
actions = {
|
||||
"convert_alias": ConvertAliasPageAPIAction,
|
||||
"copy": CopyPageAPIAction,
|
||||
"delete": DeletePageAPIAction,
|
||||
"publish": PublishPageAPIAction,
|
||||
"unpublish": UnpublishPageAPIAction,
|
||||
"move": MovePageAPIAction,
|
||||
"copy_for_translation": CopyForTranslationAPIAction,
|
||||
"create_alias": CreatePageAliasAPIAction,
|
||||
"revert_to_page_revision": RevertToPageRevisionAPIAction,
|
||||
}
|
||||
|
||||
# Add has_children and for_explorer filters
|
||||
filter_backends = PagesAPIViewSet.filter_backends + [
|
||||
HasChildrenFilter,
|
||||
ForExplorerFilter,
|
||||
]
|
||||
|
||||
meta_fields = PagesAPIViewSet.meta_fields + [
|
||||
"latest_revision_created_at",
|
||||
"status",
|
||||
"children",
|
||||
"descendants",
|
||||
"parent",
|
||||
"ancestors",
|
||||
"translations",
|
||||
]
|
||||
|
||||
body_fields = PagesAPIViewSet.body_fields + [
|
||||
"admin_display_title",
|
||||
]
|
||||
|
||||
listing_default_fields = PagesAPIViewSet.listing_default_fields + [
|
||||
"latest_revision_created_at",
|
||||
"status",
|
||||
"children",
|
||||
"admin_display_title",
|
||||
]
|
||||
|
||||
# Allow the parent field to appear on listings
|
||||
detail_only_fields = []
|
||||
|
||||
known_query_parameters = PagesAPIViewSet.known_query_parameters.union(
|
||||
["for_explorer", "has_children"]
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_detail_default_fields(cls, model):
|
||||
detail_default_fields = super().get_detail_default_fields(model)
|
||||
|
||||
# When i18n is disabled, remove "translations" from default fields
|
||||
if not getattr(settings, "WAGTAIL_I18N_ENABLED", False):
|
||||
detail_default_fields.remove("translations")
|
||||
|
||||
return detail_default_fields
|
||||
|
||||
def get_root_page(self):
|
||||
"""
|
||||
Returns the page that is used when the `&child_of=root` filter is used.
|
||||
"""
|
||||
return Page.get_first_root_node()
|
||||
|
||||
def get_base_queryset(self):
|
||||
"""
|
||||
Returns a queryset containing all pages that can be seen by this user.
|
||||
|
||||
This is used as the base for get_queryset and is also used to find the
|
||||
parent pages when using the child_of and descendant_of filters as well.
|
||||
"""
|
||||
return Page.objects.all()
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
|
||||
# Hide root page
|
||||
# TODO: Add "include_root" flag
|
||||
queryset = queryset.exclude(depth=1).defer_streamfields().specific()
|
||||
|
||||
return queryset
|
||||
|
||||
def get_type_info(self):
|
||||
types = OrderedDict()
|
||||
|
||||
for name, model in self.seen_types.items():
|
||||
types[name] = OrderedDict(
|
||||
[
|
||||
("verbose_name", model._meta.verbose_name),
|
||||
("verbose_name_plural", model._meta.verbose_name_plural),
|
||||
]
|
||||
)
|
||||
|
||||
return types
|
||||
|
||||
def listing_view(self, request):
|
||||
response = super().listing_view(request)
|
||||
response.data["__types"] = self.get_type_info()
|
||||
return response
|
||||
|
||||
def detail_view(self, request, pk):
|
||||
response = super().detail_view(request, pk)
|
||||
response.data["__types"] = self.get_type_info()
|
||||
return response
|
||||
|
||||
def action_view(self, request, pk, action_name):
|
||||
instance = self.get_object()
|
||||
|
||||
if action_name not in self.actions:
|
||||
raise Http404(f"unrecognised action '{action_name}'")
|
||||
|
||||
action = self.actions[action_name](self, request)
|
||||
action_data = action.serializer(data=request.data)
|
||||
|
||||
if not action_data.is_valid():
|
||||
return Response(action_data.errors, status=400)
|
||||
|
||||
return action.execute(instance, action_data.data)
|
||||
|
||||
@classmethod
|
||||
def get_urlpatterns(cls):
|
||||
"""
|
||||
This returns a list of URL patterns for the endpoint
|
||||
"""
|
||||
urlpatterns = super().get_urlpatterns()
|
||||
urlpatterns.extend(
|
||||
[
|
||||
path(
|
||||
"<int:pk>/action/<str:action_name>/",
|
||||
cls.as_view({"post": "action_view"}),
|
||||
name="action",
|
||||
),
|
||||
]
|
||||
)
|
||||
return urlpatterns
|
||||
Reference in New Issue
Block a user