def add_tree(self, count, root=None, depth=1): CMS_GTE_35 = hasattr(Page, 'node') for node in range(0, count): new_page = Page( created_by='script', changed_by='script', in_navigation=True, template='INHERIT', ) if CMS_GTE_35: parent_node = root.node if root else None new_page.set_tree_node(site=self.site, target=parent_node, position='last-child') new_page.save() else: new_page.site = self.site new_page.parent_id = getattr(root, 'pk', None) # This saves the page new_page = Page.add_root(instance=new_page) if root: new_page = new_page.move(target=root.reload(), pos='last-child') try: node_path = new_page.node.path except AttributeError: node_path = new_page.path for language in self.languages: new_page.title_set.create( language=language, title=node_path, slug=node_path, path='/'.join(self.path_regex.findall(node_path)), ) new_page.update_languages(self.languages) if self.base_page: for ph in self.base_page.placeholders.all(): new_ph = new_page.placeholders.create(slot=ph.slot) for language in self.languages: plugins = ph.get_plugins_list(language) if plugins: ph.copy_plugins(new_ph, language) else: new_page.rescan_placeholders() self.stdout.write("Created page %s" % node_path) if depth <= self.max_depth and bool(random.getrandbits(1)): self.add_tree(count=self.max_count_children, root=new_page, depth=depth + 1)
def copy_pages(): pages = PagesPage.objects.order_by('tree_id', 'lft', ) # remove all the previous pages CMSPage.objects.all().delete() parents = {} for page in pages: cmspage = CMSPage() # replicate the language independent structure information # thanks to the common ancestor we can reuse exactly the same tree # information cmspage.pk = page.pk cmspage.creation_date = page.creation_date cmspage.publication_date = page.publication_date cmspage.publication_end_date = page.publication_end_date cmspage.changed_date = page.last_modification_date cmspage.template = 'django_' + page.template cmspage.level = page.level cmspage.lft = page.lft cmspage.rght = page.rght cmspage.tree_id = page.tree_id cmspage.site_id = 1 if page.parent_id in parents: cmspage.parent = parents[page.parent_id] cmspage.save(no_signals=True) cmspage.rescan_placeholders() parents[cmspage.pk] = cmspage # replicate the language dependent data for language in page.get_languages(): cmstitle = Title() cmstitle.language = language cmstitle.title = page.title(language) cmstitle.slug = page.slug(language) cmstitle.page = cmspage cmstitle.update_path() cmstitle.save() contents = page.content_by_language(language) for content in contents: if content.type in ('subtitle', 'text', 'right-column'): placeholder = cmspage.placeholders.get(slot=content.type) # For the main placeholders we need to scan whether content # is markdown or plain HTML # This is a very naif check, but does the trick in this # context if content.body.find('<p>') > -1: add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body) else: add_plugin(placeholder, plugin_type='MarkItUpPlugin', language=language, body=content.body) elif content.type not in ('slug', 'title'): # Fallback import placeholder = cmspage.placeholders.get(slot=content.type) add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body)
def copy_pages(): pages = PagesPage.objects.order_by( 'tree_id', 'lft', ) # remove all the previous pages CMSPage.objects.all().delete() parents = {} for page in pages: cmspage = CMSPage() # replicate the language independent structure information # thanks to the common ancestor we can reuse exactly the same tree # information cmspage.pk = page.pk cmspage.creation_date = page.creation_date cmspage.publication_date = page.publication_date cmspage.publication_end_date = page.publication_end_date cmspage.changed_date = page.last_modification_date cmspage.template = 'django_' + page.template cmspage.level = page.level cmspage.lft = page.lft cmspage.rght = page.rght cmspage.tree_id = page.tree_id cmspage.site_id = 1 if page.parent_id in parents: cmspage.parent = parents[page.parent_id] cmspage.save(no_signals=True) cmspage.rescan_placeholders() parents[cmspage.pk] = cmspage # replicate the language dependent data for language in page.get_languages(): cmstitle = Title() cmstitle.language = language cmstitle.title = page.title(language) cmstitle.slug = page.slug(language) cmstitle.page = cmspage cmstitle.update_path() cmstitle.save() contents = page.content_by_language(language) for content in contents: if content.type in ('subtitle', 'text', 'right-column'): placeholder = cmspage.placeholders.get(slot=content.type) # For the main placeholders we need to scan whether content # is markdown or plain HTML # This is a very naif check, but does the trick in this # context if content.body.find('<p>') > -1: add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body) else: add_plugin(placeholder, plugin_type='MarkItUpPlugin', language=language, body=content.body) elif content.type not in ('slug', 'title'): # Fallback import placeholder = cmspage.placeholders.get(slot=content.type) add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body)