Skip to content
Snippets Groups Projects
Commit 5052d576 authored by Alexa Valentová's avatar Alexa Valentová
Browse files

migrate uniweb blocks with new counterparts

parent ed4ee222
No related branches found
No related tags found
2 merge requests!1047Uniweb redesign,!1045Uniweb redesign, minor district redesign fixes
Pipeline #18824 passed
......@@ -1162,28 +1162,6 @@ class PictureListBlock(ColorBlock):
template = "styleguide2/includes/molecules/lists/image_list.html"
class ButtonBlock(blocks.StructBlock):
text = blocks.CharBlock(label="Nadpis")
url = blocks.URLBlock(
label="Odkaz",
help_text="Pokud je odkaz vyplněný, není nutno vyplňovat stránku.",
required=False,
)
page = blocks.PageChooserBlock(
label="Stránka",
help_text="Pokud je stránka vyplněná, není nutno vyplňovat odkaz.",
required=False,
)
class Meta:
label = "Tlačítko"
icon = "link-external"
group = "ostatní"
template = "uniweb/blocks/button.html"
DEFAULT_CONTENT_BLOCKS = [
(
"text",
......
This diff is collapsed.
# Generated by Django 5.0.6 on 2024-06-26 10:35
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('uniweb', '0070_alter_uniwebarticlepage_content'),
]
operations = [
]
from django.db import migrations
from wagtail.blocks import StreamBlock, StructBlock
def migrate_button_blocks(apps, schema_editor):
model_fields = {
"UniwebHomePage": ["content"],
"UniwebFlexiblePage": ["content"],
"UniwebFormPage": ["content_before", "content_after", "content_landing"],
}
def process_block(block):
# Perform your block transformation logic here
# For example, replace some blocks with different blocks
if block.block_type == 'button':
new_block_value = {
"title": block.value["text"],
"color": "pirati-yellow",
"hoveractive": False,
"page": block.value["page"],
"link": block.value["url"],
"align": "auto"
}
new_block = ("new_button", new_block_value)
return new_block
elif block.block_type == 'title':
new_block_value = {
"headline": block.value,
"tag": "h1",
"style": "head-alt-xl",
"align": "auto"
}
new_block = ("headline", new_block_value)
return new_block
elif block.block_type == 'advanced_title':
new_block_value = {
"headline": block.value["title"],
"tag": "h1",
"style": "head-alt-xl",
"align": "auto" if block.value["align"] != "center" else "center"
}
new_block = ("headline", new_block_value)
return new_block
elif block.block_type == 'gallery':
new_block_value = {
"gallery_items": []
}
for item in block.value:
new_block_value["gallery_items"].append(item)
new_block = ("new_gallery", new_block_value)
return new_block
return (block.block_type, block.value)
for model_name, fields in model_fields.items():
model = apps.get_model("uniweb", model_name)
for instance in model.objects.all():
for field in fields:
new_values = []
for block in getattr(instance, field):
new_block = process_block(block)
new_values.append(new_block)
# Clean the old field (e.g., instance.content = [])
setattr(instance, field, [])
# Put all the values back in the field, maintaining the order
stream_value = [(block_type, value) for block_type, value in new_values]
setattr(instance, field, stream_value)
instance.save()
class Migration(migrations.Migration):
dependencies = [
('uniweb', '0071_alter_uniwebflexiblepage_content_and_more'),
]
operations = [
migrations.RunPython(migrate_button_blocks),
]
This diff is collapsed.
......@@ -271,31 +271,6 @@ CONTENT_STREAM_BLOCKS = [
("chart", ChartBlock()),
# cards
("cards", FlipCardsBlock(template="uniweb/blocks/flip_cards.html")), # Unfinished
# TO BE MIGRATED
("button", ButtonBlock()),
(
"title",
blocks.CharBlock(
label="nadpis",
icon="title",
group="nadpisy",
template="uniweb/blocks/title.html",
),
),
("advanced_title", AdvancedTitleBlock()),
(
"gallery",
blocks.ListBlock(
ImageChooserBlock(label="obrázek"),
label="galerie",
icon="image",
group="ostatní",
template="uniweb/blocks/gallery.html",
),
),
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment