Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Created October 5, 2011 11:27
Show Gist options
  • Select an option

  • Save maxpeterson/1264235 to your computer and use it in GitHub Desktop.

Select an option

Save maxpeterson/1264235 to your computer and use it in GitHub Desktop.
Management command to migrate structure.page to feincms
from django.core.management.base import BaseCommand
from django.conf import settings
from incuna.structure.models import Page as StructurePage
from feincms.module.page.models import Page as FeinPage
from feincms.content.richtext.models import RichTextContent
def migrate_pages(structure_pages, template, region, parent=None, **options):
"""
Migrate the structure pages and their children (recursively)
"""
for structure_page in structure_pages:
if 'verbosity' in options and int(options['verbosity']) > 1:
print "migrating %s" % (structure_page,)
fein_page = FeinPage(title=structure_page.name,
slug=structure_page.slug,
in_navigation=structure_page.menus.all().count()>0,
override_url=structure_page.override_url or "",
active=True,
template_key=template,
)
if hasattr(fein_page, 'meta_description'):
fein_page.meta_description = structure_page.meta_description or ""
if hasattr(fein_page, '_page_title'):
fein_page._page_title = structure_page.html_title or ""
fein_page.insert_at(parent, position='first-child', commit=True)
fein_page.richtextcontent_set.create(parent=fein_page,
text=structure_page.body,
region=region)
migrate_pages(structure_page.children().reverse(), template, region, fein_page, **options)
class Command(BaseCommand):
help = 'Migrate from structure pages to FeinCMS.'
args = '[template] [region]'
def handle(self, template=None, region=None, **options):
if template is None:
template = FeinPage._feincms_templates.keys()[0]
if region is None:
region = FeinPage._feincms_templates[template].regions[0].key
if 'verbosity' in options and int(options['verbosity']) > 1:
print "Migrating using template '%(template)s' and region '%(region)s'" % ({'template': template, 'region': region})
migrate_pages(StructurePage.objects.filter(parent__isnull=True), template, region, **options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment