Skip to content
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

fix: Add --fix-paths option to ./manage.py cms fix-tree #7744

Merged
merged 4 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions cms/management/commands/subcommands/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ def get_descendants(root):


class FixTreeCommand(SubcommandsCommand):
help_string = 'Repairing Materialized Path Tree for Pages'
help_string = 'Repairing Materialized Path Tree for Pages and Plugins'
command_name = 'fix-tree'

def add_arguments(self, parser):
parser.add_argument(
'--fix-paths',
action='store_true',
default=False,
help='Fix paths for pages and plugins - takes a long time',
)

def handle(self, *args, **options):
"""
Repairs the tree
"""
fix_paths = options.get('fix_paths', False)
self.stdout.write('fixing page tree')
TreeNode.fix_tree()
TreeNode.fix_tree(fix_paths=fix_paths)

root_nodes = TreeNode.objects.filter(parent__isnull=True)

Expand All @@ -54,7 +63,7 @@ def handle(self, *args, **options):
self._update_descendants_tree(root)

self.stdout.write('fixing plugin tree')
CMSPlugin.fix_tree()
CMSPlugin.fix_tree(fix_paths=fix_paths)
self.stdout.write('all done')

def _update_descendants_tree(self, root):
Expand Down
4 changes: 2 additions & 2 deletions cms/models/pluginmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ def copy_plugin(self, target_placeholder, target_language, parent_cache, no_sign
return new_plugin

@classmethod
def fix_tree(cls, destructive=False):
def fix_tree(cls, **kwargs):
"""
Fixes the plugin tree by first calling treebeard fix_tree and the
recalculating the correct position property for each plugin.
"""
from cms.utils.plugins import reorder_plugins

super().fix_tree(destructive)
super().fix_tree(**kwargs)
for placeholder in Placeholder.objects.all():
for language, __ in settings.LANGUAGES:
order = CMSPlugin.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'Django>=3.2',
'django-classy-tags>=0.7.2',
'django-formtools>=2.1',
'django-treebeard>=4.3',
'django-treebeard>=4.3,!=4.5',
'django-sekizai>=0.7',
'djangocms-admin-style>=1.2',
'packaging',
Expand Down