kopia lustrzana https://github.com/wagtail/wagtail
Make CreatePageAliasAction class and implement execute method
rodzic
3d032c9589
commit
ae76ebe92d
|
@ -9,18 +9,7 @@ from wagtail.core.models.i18n import TranslatableMixin
|
|||
logger = logging.getLogger("wagtail.core")
|
||||
|
||||
|
||||
def create_alias(
|
||||
page,
|
||||
*,
|
||||
recursive=False,
|
||||
parent=None,
|
||||
update_slug=None,
|
||||
update_locale=None,
|
||||
user=None,
|
||||
log_action="wagtail.create_alias",
|
||||
reset_translation_key=True,
|
||||
_mpnode_attrs=None
|
||||
):
|
||||
class CreatePageAliasAction:
|
||||
"""
|
||||
Creates an alias of the given page.
|
||||
|
||||
|
@ -46,6 +35,43 @@ def create_alias(
|
|||
:type reset_translation_key: boolean, optional
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
page,
|
||||
*,
|
||||
recursive=False,
|
||||
parent=None,
|
||||
update_slug=None,
|
||||
update_locale=None,
|
||||
user=None,
|
||||
log_action="wagtail.create_alias",
|
||||
reset_translation_key=True,
|
||||
_mpnode_attrs=None
|
||||
):
|
||||
self.page = page
|
||||
self.recursive = recursive
|
||||
self.parent = parent
|
||||
self.update_slug = update_slug
|
||||
self.update_locale = update_locale
|
||||
self.user = user
|
||||
self.log_action = log_action
|
||||
self.reset_translation_key = reset_translation_key
|
||||
self._mpnode_attrs = _mpnode_attrs
|
||||
|
||||
def _create_alias(
|
||||
self,
|
||||
page,
|
||||
*,
|
||||
recursive,
|
||||
parent,
|
||||
update_slug,
|
||||
update_locale,
|
||||
user,
|
||||
log_action,
|
||||
reset_translation_key,
|
||||
_mpnode_attrs
|
||||
):
|
||||
|
||||
specific_page = page.specific
|
||||
|
||||
# FIXME: Switch to the same fields that are excluded from copy
|
||||
|
@ -108,7 +134,9 @@ def create_alias(
|
|||
else:
|
||||
if parent:
|
||||
if recursive and (parent == page or parent.is_descendant_of(page)):
|
||||
raise Exception("You cannot copy a tree branch recursively into itself")
|
||||
raise Exception(
|
||||
"You cannot copy a tree branch recursively into itself"
|
||||
)
|
||||
alias = parent.add_child(instance=alias)
|
||||
else:
|
||||
alias = page.add_sibling(instance=alias)
|
||||
|
@ -176,3 +204,16 @@ def create_alias(
|
|||
alias.save(clean=False, update_fields=["numchild"])
|
||||
|
||||
return alias
|
||||
|
||||
def execute(self):
|
||||
return self._create_alias(
|
||||
self.page,
|
||||
recursive=self.recursive,
|
||||
parent=self.parent,
|
||||
update_slug=self.update_slug,
|
||||
update_locale=self.update_locale,
|
||||
user=self.user,
|
||||
log_action=self.log_action,
|
||||
reset_translation_key=self.reset_translation_key,
|
||||
_mpnode_attrs=self._mpnode_attrs,
|
||||
)
|
||||
|
|
|
@ -52,7 +52,7 @@ from wagtail.core.actions.delete_page import DeletePageAction
|
|||
from wagtail.core.actions.move_page import MovePageAction
|
||||
from wagtail.core.actions.publish_page_revision import PublishPageRevisionAction
|
||||
from wagtail.core.actions.unpublish_page import UnpublishPageAction
|
||||
from wagtail.core.actions.create_alias import create_alias as _create_alias
|
||||
from wagtail.core.actions.create_alias import CreatePageAliasAction
|
||||
from wagtail.core.fields import StreamField
|
||||
from wagtail.core.forms import TaskStateCommentForm
|
||||
from wagtail.core.log_actions import log
|
||||
|
@ -1467,7 +1467,7 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
|
|||
reset_translation_key=True,
|
||||
_mpnode_attrs=None
|
||||
):
|
||||
return _create_alias(
|
||||
return CreatePageAliasAction(
|
||||
self,
|
||||
recursive=recursive,
|
||||
parent=parent,
|
||||
|
@ -1477,7 +1477,7 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
|
|||
log_action=log_action,
|
||||
reset_translation_key=reset_translation_key,
|
||||
_mpnode_attrs=_mpnode_attrs,
|
||||
)
|
||||
).execute()
|
||||
|
||||
create_alias.alters_data = True
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue