def handle(self, *args, **options): """ Repairs the tree """ self.stdout.write('fixing page tree') TreeNode.fix_tree() root_nodes = TreeNode.objects.filter(parent__isnull=True) last = None try: first = root_nodes.order_by('path')[0] except IndexError: first = None for node in root_nodes.order_by('site__pk', 'path'): if last: last.refresh_from_db() node.refresh_from_db() node.move(target=last, pos='right') elif first and first.pk != node.pk: node.move(target=first, pos='left') last = node for root in root_nodes.order_by('site__pk', 'path'): self._update_descendants_tree(root) self.stdout.write('fixing plugin tree') CMSPlugin.fix_tree() self.stdout.write('all done')
def get_root_nodes(self): # TODO: this needs to avoid using the pages accessor directly nodes = TreeNode.get_root_nodes() return nodes.exclude( cms_pages__is_page_type=not (self.page.is_page_type))