8000 Moved placeholders from Page to Title model by Aiky30 · Pull Request #6442 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Moved placeholders from Page to Title model #6442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Title -> Placeholder migrations working succesfully
  • Loading branch information
Andrew Aikman authored and czpython committed Jul 11, 2018
commit 5f662f4468a208379f74d5c3c36f1862edf47e16
44 changes: 39 additions & 5 deletions cms/migrations/0023_title_placeholders_data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,68 @@
from django.db import migrations, models

"""

Title id 1
Title id 2
Page id 1
Placeholder 1
- Placeholder 1
- Plugin 1 lang 1
- Plugin 5 lang 2
Placeholder 2
- Placeholder 2
- Plugin 3 lang 1
- Plugin 4 lang 1

Title id 1
- Page 1
- Placeholder 1
- Plugin 1 lang 1
- Placeholder 2
- Plugin 3 lang 1
- Plugin 4 lang 1
- Page 2
- Placeholder 1
- Plugin 5 lang 2
"""


def forwards(apps, schema_editor):

Page = apps.get_model('cms', 'Page')
Plugin = apps.get_model('cms', 'CMSPlugin')
Placeholder = apps.get_model('cms', 'Placeholder')
# 1. Create a placeholder for each language the page is tied to (title_set)
# 2. Move all plugins for each language into their respective placeholder
# 3. Clean away the existing placeholders???

page_list = Page.objects.all().prefetch_related('title_set')

#TODO: 1 Replicate placeholder structure for each title
#TODO: 2 Move placeholder plugins to the new placeholder, use language here to filter by title!!
#TODO: 3 Delete previous placeholders

for page in page_list:
# Get all titles registered to the page
title_set = page.title_set.all()
# Get the pages placeholders
placeholders = page.placeholders.all()
# Add each placeholder on the page template to the title
for title in title_set:
placeholders = page.placeholders.all()
# FIXME: USE SET?????
title.placeholders.add(*list(placeholders))
# Get a list of the plugins attached to this placeholder for this language
for placeholder in placeholders:

# Get all of the plugins for this placeholder
placeholder_plugins = Plugin.objects.filter(placeholder_id=placeholder.pk, language=title.language)

# Clone the placeholder
placeholder.pk=None
placeholder.save()

title.placeholders.add(placeholder)

# Move the plugins to the relevant placeholder
for plugin in placeholder_plugins:
plugin.placeholder_id = placeholder.pk
plugin.save()

#except Exception:
# warnings.warn(u'Placeholder migration failure.')
Expand Down
0