|
@@ -1,13 +1,20 @@
|
|
|
+from abc import ABC, abstractmethod
|
|
|
from wagtail.blocks.migrations.utils import formatted_list_child_generator
|
|
|
from django.utils.deconstruct import deconstructible
|
|
|
|
|
|
|
|
|
-class BaseBlockOperation:
|
|
|
+class BaseBlockOperation(ABC):
|
|
|
def __init__(self):
|
|
|
pass
|
|
|
|
|
|
+ @abstractmethod
|
|
|
def apply(self, block_value):
|
|
|
- raise NotImplementedError
|
|
|
+ pass
|
|
|
+
|
|
|
+ @property
|
|
|
+ @abstractmethod
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
@deconstructible
|
|
@@ -37,6 +44,10 @@ class RenameStreamChildrenOperation(BaseBlockOperation):
|
|
|
mapped_block_value.append(child_block)
|
|
|
return mapped_block_value
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "rename_{}_to_{}".format(self.old_name, self.new_name)
|
|
|
+
|
|
|
|
|
|
@deconstructible
|
|
|
class RenameStructChildrenOperation(BaseBlockOperation):
|
|
@@ -65,6 +76,10 @@ class RenameStructChildrenOperation(BaseBlockOperation):
|
|
|
mapped_block_value[child_key] = child_value
|
|
|
return mapped_block_value
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "rename_{}_to_{}".format(self.old_name, self.new_name)
|
|
|
+
|
|
|
|
|
|
@deconstructible
|
|
|
class RemoveStreamChildrenOperation(BaseBlockOperation):
|
|
@@ -89,6 +104,10 @@ class RemoveStreamChildrenOperation(BaseBlockOperation):
|
|
|
if child_block["type"] != self.name
|
|
|
]
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "remove_{}".format(self.name)
|
|
|
+
|
|
|
|
|
|
@deconstructible
|
|
|
class RemoveStructChildrenOperation(BaseBlockOperation):
|
|
@@ -113,6 +132,10 @@ class RemoveStructChildrenOperation(BaseBlockOperation):
|
|
|
if child_key != self.name
|
|
|
}
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "remove_{}".format(self.name)
|
|
|
+
|
|
|
|
|
|
class StreamChildrenToListBlockOperation(BaseBlockOperation):
|
|
|
"""Combines StreamBlock children of the given type into a new ListBlock
|
|
@@ -151,6 +174,10 @@ class StreamChildrenToListBlockOperation(BaseBlockOperation):
|
|
|
new_temp_blocks.append({**block, "type": "item"})
|
|
|
self.temp_blocks = new_temp_blocks
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "{}_to_list_block_{}".format(self.block_name, self.list_block_name)
|
|
|
+
|
|
|
|
|
|
class StreamChildrenToStreamBlockOperation(BaseBlockOperation):
|
|
|
"""Combines StreamBlock children of the given types into a new StreamBlock
|
|
@@ -183,6 +210,10 @@ class StreamChildrenToStreamBlockOperation(BaseBlockOperation):
|
|
|
mapped_block_value.append(new_stream_block)
|
|
|
return mapped_block_value
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "{}_to_stream_block".format("_".join(self.block_names))
|
|
|
+
|
|
|
|
|
|
class AlterBlockValueOperation(BaseBlockOperation):
|
|
|
"""Alters the value of each block to the given value
|
|
@@ -198,6 +229,10 @@ class AlterBlockValueOperation(BaseBlockOperation):
|
|
|
def apply(self, block_value):
|
|
|
return self.new_value
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "alter_block_value"
|
|
|
+
|
|
|
|
|
|
class StreamChildrenToStructBlockOperation(BaseBlockOperation):
|
|
|
"""Move each StreamBlock child of the given type inside a new StructBlock
|
|
@@ -266,6 +301,10 @@ class StreamChildrenToStructBlockOperation(BaseBlockOperation):
|
|
|
mapped_block_value.append(child_block)
|
|
|
return mapped_block_value
|
|
|
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "{}_to_struct_block_{}".format(self.block_name, self.struct_block_name)
|
|
|
+
|
|
|
|
|
|
class ListChildrenToStructBlockOperation(BaseBlockOperation):
|
|
|
def __init__(self, block_name):
|
|
@@ -282,3 +321,7 @@ class ListChildrenToStructBlockOperation(BaseBlockOperation):
|
|
|
{**child_block, "value": {self.block_name: child_block["value"]}}
|
|
|
)
|
|
|
return mapped_block_value
|
|
|
+
|
|
|
+ @property
|
|
|
+ def operation_name_fragment(self):
|
|
|
+ return "list_block_items_to_{}".format(self.block_name)
|