Initial commit

This commit is contained in:
2024-08-27 20:33:44 +02:00
commit 1f1832267d
14794 changed files with 1599592 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
from django.apps import AppConfig
class WagtailSnippetsTestsAppConfig(AppConfig):
default_auto_field = "django.db.models.AutoField"
name = "wagtail.test.streamfield_migrations"
label = "streamfield_migration_tests"
verbose_name = "Wagtail StreamField migration tests"

View File

@@ -0,0 +1,71 @@
import factory
from factory.django import DjangoModelFactory
from wagtail.test.utils import wagtail_factories
from . import models
class SimpleStructBlockFactory(wagtail_factories.StructBlockFactory):
char1 = "Char Block 1"
char2 = "Char Block 2"
class Meta:
model = models.SimpleStructBlock
class SimpleStreamBlockFactory(wagtail_factories.StreamBlockFactory):
char1 = "Char Block 1"
char2 = "Char Block 2"
class Meta:
model = models.SimpleStreamBlock
class NestedStructBlockFactory(wagtail_factories.StructBlockFactory):
char1 = "Char Block 1"
struct1 = factory.SubFactory(SimpleStructBlockFactory)
stream1 = factory.SubFactory(SimpleStreamBlockFactory)
list1 = wagtail_factories.ListBlockFactory(wagtail_factories.CharBlockFactory)
class Meta:
model = models.NestedStructBlock
class NestedStreamBlockFactory(wagtail_factories.StreamBlockFactory):
char1 = "Char Block 1"
struct1 = factory.SubFactory(SimpleStructBlockFactory)
stream1 = factory.SubFactory(SimpleStreamBlockFactory)
list1 = wagtail_factories.ListBlockFactory(wagtail_factories.CharBlockFactory)
class Meta:
model = models.NestedStreamBlock
class BaseStreamBlockFactory(wagtail_factories.StreamBlockFactory):
char1 = "Char Block 1"
char2 = "Char Block 2"
simplestruct = factory.SubFactory(SimpleStructBlockFactory)
simplestream = factory.SubFactory(SimpleStreamBlockFactory)
simplelist = wagtail_factories.ListBlockFactory(wagtail_factories.CharBlockFactory)
nestedstruct = factory.SubFactory(NestedStructBlockFactory)
nestedstream = factory.SubFactory(NestedStreamBlockFactory)
nestedlist_struct = wagtail_factories.ListBlockFactory(SimpleStructBlockFactory)
nestedlist_stream = wagtail_factories.ListBlockFactory(SimpleStreamBlockFactory)
class Meta:
model = models.BaseStreamBlock
class SampleModelFactory(DjangoModelFactory):
content = wagtail_factories.StreamFieldFactory(BaseStreamBlockFactory)
class Meta:
model = models.SampleModel
class SamplePageFactory(wagtail_factories.PageFactory):
content = wagtail_factories.StreamFieldFactory(BaseStreamBlockFactory)
class Meta:
model = models.SamplePage

View File

@@ -0,0 +1,337 @@
# Generated by Django 4.0.3 on 2022-09-02 03:18
from django.db import migrations, models
import django.db.models.deletion
import wagtail.blocks
import wagtail.fields
class Migration(migrations.Migration):
initial = True
dependencies = [
# changed dependency to last wagtail3 migration
("wagtailcore", "0069_log_entry_jsonfield"),
]
operations = [
migrations.CreateModel(
name="SampleModel",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"content",
wagtail.fields.StreamField(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
(
"simplestruct",
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
),
),
(
"simplestream",
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
),
),
(
"simplelist",
wagtail.blocks.ListBlock(wagtail.blocks.CharBlock()),
),
(
"nestedstruct",
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
(
"stream1",
wagtail.blocks.StreamBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"struct1",
wagtail.blocks.StructBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"list1",
wagtail.blocks.ListBlock(
wagtail.blocks.CharBlock()
),
),
]
),
),
(
"nestedstream",
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
(
"stream1",
wagtail.blocks.StreamBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"struct1",
wagtail.blocks.StructBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"list1",
wagtail.blocks.ListBlock(
wagtail.blocks.CharBlock()
),
),
]
),
),
(
"nestedlist_struct",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
)
),
),
(
"nestedlist_stream",
wagtail.blocks.ListBlock(
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
)
),
),
],
use_json_field=True,
),
),
],
),
migrations.CreateModel(
name="SamplePage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
(
"content",
wagtail.fields.StreamField(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
(
"simplestruct",
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
),
),
(
"simplestream",
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
),
),
(
"simplelist",
wagtail.blocks.ListBlock(wagtail.blocks.CharBlock()),
),
(
"nestedstruct",
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
(
"stream1",
wagtail.blocks.StreamBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"struct1",
wagtail.blocks.StructBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"list1",
wagtail.blocks.ListBlock(
wagtail.blocks.CharBlock()
),
),
]
),
),
(
"nestedstream",
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
(
"stream1",
wagtail.blocks.StreamBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"struct1",
wagtail.blocks.StructBlock(
[
(
"char1",
wagtail.blocks.CharBlock(),
),
(
"char2",
wagtail.blocks.CharBlock(),
),
]
),
),
(
"list1",
wagtail.blocks.ListBlock(
wagtail.blocks.CharBlock()
),
),
]
),
),
(
"nestedlist_struct",
wagtail.blocks.ListBlock(
wagtail.blocks.StructBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
)
),
),
(
"nestedlist_stream",
wagtail.blocks.ListBlock(
wagtail.blocks.StreamBlock(
[
("char1", wagtail.blocks.CharBlock()),
("char2", wagtail.blocks.CharBlock()),
]
)
),
),
],
use_json_field=True,
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page",),
),
]

View File

@@ -0,0 +1,49 @@
from django.db import models
from wagtail.blocks import CharBlock, ListBlock, StreamBlock, StructBlock
from wagtail.fields import StreamField
from wagtail.models import Page
class SimpleStructBlock(StructBlock):
char1 = CharBlock()
char2 = CharBlock()
class SimpleStreamBlock(StreamBlock):
char1 = CharBlock()
char2 = CharBlock()
class NestedStructBlock(StructBlock):
char1 = CharBlock()
stream1 = SimpleStreamBlock()
struct1 = SimpleStructBlock()
list1 = ListBlock(CharBlock())
class NestedStreamBlock(StreamBlock):
char1 = CharBlock()
stream1 = SimpleStreamBlock()
struct1 = SimpleStructBlock()
list1 = ListBlock(CharBlock())
class BaseStreamBlock(StreamBlock):
char1 = CharBlock()
char2 = CharBlock()
simplestruct = SimpleStructBlock()
simplestream = SimpleStreamBlock()
simplelist = ListBlock(CharBlock())
nestedstruct = NestedStructBlock()
nestedstream = NestedStreamBlock()
nestedlist_struct = ListBlock(SimpleStructBlock())
nestedlist_stream = ListBlock(SimpleStreamBlock())
class SampleModel(models.Model):
content = StreamField(BaseStreamBlock())
class SamplePage(Page):
content = StreamField(BaseStreamBlock())

View File

@@ -0,0 +1,43 @@
from django.db import connection
from django.db.migrations import Migration
from django.db.migrations.loader import MigrationLoader
from wagtail.blocks.migrations.migrate_operation import MigrateStreamData
class MigrationTestMixin:
model = None
default_operation_and_block_path = []
app_name = None
def init_migration(self, revisions_from=None, operations_and_block_path=None):
migration = Migration(
"test_migration", "wagtail_streamfield_migration_toolkit_test"
)
migration_operation = MigrateStreamData(
app_name=self.app_name,
model_name=self.model.__name__,
field_name="content",
operations_and_block_paths=operations_and_block_path
or self.default_operation_and_block_path,
revisions_from=revisions_from,
)
migration.operations = [migration_operation]
return migration
def apply_migration(
self,
revisions_from=None,
operations_and_block_path=None,
):
migration = self.init_migration(
revisions_from=revisions_from,
operations_and_block_path=operations_and_block_path,
)
loader = MigrationLoader(connection=connection)
loader.build_graph()
project_state = loader.project_state()
schema_editor = connection.schema_editor(atomic=migration.atomic)
migration.apply(project_state, schema_editor)