Skip to content

Commit

Permalink
Manual placeholder selection in migration 0044
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed May 6, 2024
1 parent f087119 commit 537bc23
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions djangocms_blog/migrations/0044_copy_plugins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cms.utils.placeholder import get_placeholder_from_slot
from django.contrib.auth import get_user_model
from django.db import migrations

Expand Down Expand Up @@ -45,17 +46,27 @@ def move_plugins_to_blog_content(apps, schema_editor):
state=PUBLISHED if post.publish else DRAFT,
)
translation.delete()

# Resolve placeholders
post_media = get_placeholder_from_slot(post.placeholders, "media")
post_content = get_placeholder_from_slot(post.placeholders, "content")
post_liveblog = get_placeholder_from_slot(post.placeholders, "liveblog")

content_media = get_placeholder_from_slot(content.placeholders, "media")
content_content = get_placeholder_from_slot(content.placeholders, "content")
content_liveblog = get_placeholder_from_slot(content.placeholders, "liveblog")

# Move plugins to post content placeholders
if post.media:
media_plugins = post.media.cmsplugin_set.filter(language=translation.language_code)
media_plugins.update(placeholder=content.media)
if post.content:
if post_media:
media_plugins = post_media.cmsplugin_set.filter(language=translation.language_code)
media_plugins.update(placeholder=content_media)
if post_content:
print("Moving content plugins...")
content_plugins = post.content.cmsplugin_set.filter(language=translation.language_code)
content_plugins.update(placeholder=content.content)
if post.liveblog:
live_plugins = post.liveblog.cmsplugin_set.filter(language=translation.language_code)
live_plugins.update(placeholder=content.liveblog)
content_plugins = post_content.cmsplugin_set.filter(language=translation.language_code)
content_plugins.update(placeholder=content_content)
if post_liveblog:
live_plugins = post_liveblog.cmsplugin_set.filter(language=translation.language_code)
live_plugins.update(placeholder=content_liveblog)


def move_plugins_back_to_blog(apps, schema_editor):
Expand Down

0 comments on commit 537bc23

Please sign in to comment.