Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Add WIP script to create legacy pages
Browse files Browse the repository at this point in the history
Add json data from existing (legacy) site
Add django_extensions and six to requirements
Run script with './manage.py runscript create_pages'
  • Loading branch information
jgmize committed Jan 7, 2015
1 parent d4958cd commit cfe27d6
Show file tree
Hide file tree
Showing 21 changed files with 35,405 additions and 0 deletions.
56 changes: 56 additions & 0 deletions legacy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
import os

from django.utils.text import slugify

from feincms.module.page.models import Page


def load(language='english'):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'json', '{}.json'.format(language))) as f:
return json.load(f)


def add_richtext(page, text):
if text:
page.richtextentry_set.create(
text='<p>{}</p>'.format(text), parent=page, region='main')


def add_blocks(page, blocks):
for block in blocks or []:
add_richtext(page, block['title'])
for component in block['components']:
add_richtext(page, component['title'])
add_richtext(page, component['body'])
# TODO: upload media, use different content type
if component['component'] == 'graphic':
add_richtext(page, component['graphic']['alt'])
elif component['component'] in ('reveal', 'hotgraphic'):
add_richtext(page, component['graphic']['title'])
add_richtext(page, component['graphic'].get('body'))
for item in component.get('items', []):
add_richtext(page, item['title'])
add_richtext(page, item.get('body'))
add_richtext(page, item.get('strapline'))




def create_page(title, body='', parent=None, override_url='', blocks=None):
page = Page.objects.create(
title=title, slug=slugify(title), parent=parent,
override_url=override_url)
add_richtext(page, body)
add_blocks(page, blocks)
return page


def create_pages():
# all content for the legacy site is in a single 'topic'
topic = load()['modules'][0]['topics'][0]
home_page = create_page(topic['title'], topic['body'], override_url='/')
for page in topic['pages']:
create_page(page['title'], page.get('body'), parent=home_page,
blocks=page['articles'][0]['blocks'])
1 change: 1 addition & 0 deletions legacy/json/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fetched from http://masterfirefoxos.mozilla.org/course/ on 2014-12-26
2,210 changes: 2,210 additions & 0 deletions legacy/json/bangladesh.json

Large diffs are not rendered by default.

2,209 changes: 2,209 additions & 0 deletions legacy/json/croatian.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/czech.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/english 7-16-14.json

Large diffs are not rendered by default.

2,201 changes: 2,201 additions & 0 deletions legacy/json/english.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/german.json

Large diffs are not rendered by default.

2,209 changes: 2,209 additions & 0 deletions legacy/json/greek.json

Large diffs are not rendered by default.

2,201 changes: 2,201 additions & 0 deletions legacy/json/hindi.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/hungarian.json

Large diffs are not rendered by default.

2,209 changes: 2,209 additions & 0 deletions legacy/json/italian.json

Large diffs are not rendered by default.

2,216 changes: 2,216 additions & 0 deletions legacy/json/polish.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/portuguese.json

Large diffs are not rendered by default.

2,210 changes: 2,210 additions & 0 deletions legacy/json/serbian.json

Large diffs are not rendered by default.

2,209 changes: 2,209 additions & 0 deletions legacy/json/spanish.json

Large diffs are not rendered by default.

2,211 changes: 2,211 additions & 0 deletions legacy/json/spanish_LA.json

Large diffs are not rendered by default.

2,201 changes: 2,201 additions & 0 deletions legacy/json/tamil.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions masterfirefoxos/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'feincms',
'feincms.module.page',
'feincms.module.medialibrary',
'django_extensions',
'django_stackato',

# Project specific apps
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ feedparser==5.1.3
# sha256: CJ37xCfPCbXyVzLjbQe-Nz1rL97SbK7cG4s0Qfgc6ec
django-stackato==1.0

<<<<<<< HEAD
# sha256: KN0LkNKbOGr7VS78TjVciJ9GOc6TZYp4cqIVDs4ou4k
py==1.4.26

Expand All @@ -124,3 +125,9 @@ coverage

# sha256: ShTGfVIP2p1CsNphNGOFeMquHTdLm7Ri2N4AWH26dkw
cov-core

# sha256: -s_gx8zq_Uno9-RyERKUVmYF_f3cIwEdoGzDpGAcn30
six==1.8.0

# sha256: Mfw1XHE1TVYJWPhskeGAvivHbGHBiaqG6Gm0nbOrDfU
django-extensions==1.4.9
4 changes: 4 additions & 0 deletions scripts/create_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from legacy import create_pages


run = create_pages

0 comments on commit cfe27d6

Please sign in to comment.