-
Notifications
You must be signed in to change notification settings - Fork 51
fix: Allow for later adding of django CMS versioning #185
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
658b22e
fix: Allow for later adding of django CMS versioning
fsbraun 4e62d3b
fix typo
fsbraun 8f8625d
More clarity in the readme
fsbraun 8f6b3bb
Update README.rst
fsbraun 0b53a75
Apply suggestions from code review
fsbraun 0e03da5
chore: Update version and Changelog
fsbraun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 2 additions & 42 deletions
44
src/djangocms_snippet/migrations/0010_cms4_grouper_version_data_migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,25 @@ | ||
from django.apps import apps as global_apps | ||
from django.conf import settings | ||
from django.contrib.contenttypes.management import create_contenttypes | ||
from django.db import migrations | ||
|
||
|
||
try: | ||
from djangocms_versioning.constants import DRAFT, PUBLISHED | ||
|
||
djangocms_versioning_installed = True | ||
except ImportError: | ||
djangocms_versioning_installed = False | ||
|
||
djangocms_versioning_config_enabled = getattr( | ||
settings, 'DJANGOCMS_SNIPPET_VERSIONING_ENABLED', True | ||
) | ||
|
||
|
||
def cms4_grouper_version_migration(apps, schema_editor): | ||
create_contenttypes(global_apps.get_app_config("djangocms_snippet")) | ||
|
||
db_alias = schema_editor.connection.alias | ||
|
||
|
||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
Snippet = apps.get_model('djangocms_snippet', 'Snippet') | ||
SnippetGrouper = apps.get_model('djangocms_snippet', 'SnippetGrouper') | ||
User = apps.get_model(*settings.AUTH_USER_MODEL.split('.')) | ||
|
||
snippet_contenttype = ContentType.objects.get(app_label='djangocms_snippet', model='snippet') | ||
snippet_queryset = Snippet.objects.all() | ||
|
||
# Get a migration user to create a version. | ||
if djangocms_versioning_config_enabled and djangocms_versioning_installed and len(snippet_queryset): | ||
Version = apps.get_model('djangocms_versioning', 'Version') | ||
migration_user = User.objects.get(id=getattr(settings, "DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID", 1)) | ||
snippet_queryset = Snippet.objects.using(db_alias).all() | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for snippet in snippet_queryset: | ||
grouper = SnippetGrouper.objects.create() | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
snippet.snippet_grouper = grouper | ||
snippet.save() | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Create initial Snippet Versions if versioning is enabled and installed. | ||
# Publish the snippet because all snippets were assumed published before | ||
if djangocms_versioning_config_enabled and djangocms_versioning_installed: | ||
Version.objects.create( | ||
created_by=migration_user, | ||
state=PUBLISHED, | ||
number=1, | ||
object_id=snippet.pk, | ||
content_type=snippet_contenttype, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
# ('cms', '0034_remove_pagecontent_placeholders'), # Run after the CMS4 migrations | ||
('djangocms_snippet', '0009_auto_20210915_0445'), | ||
] | ||
|
||
if djangocms_versioning_installed: | ||
dependencies += [('djangocms_versioning', '0015_version_modified'), ] | ||
|
||
operations = [ | ||
migrations.RunPython(cms4_grouper_version_migration) | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.