import json

from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from cms.models import Placeholder
from cms.api import create_page, add_plugin, publish_page


placeholder = {}

with open('starting_page.json') as data_file:
    content = json.load(data_file)

try:
    # try to get a feature template with fallback
    template = settings.CMS_TEMPLATES[1][0]
    if template != 'feature.html':
        template = settings.CMS_TEMPLATES[0][0]
except IndexError:
    template = settings.CMS_TEMPLATES[0][0]

lang = settings.LANGUAGES[0][0]
page = create_page(_('Home'), template, lang)
placeholder['main'] = page.placeholders.get(slot='content')

try:
    # try to get a feature placeholder
    placeholder_feature = page.placeholders.get(slot='feature')
    p = add_plugin(placeholder_feature, 'TextPlugin', lang,
                   body=content['feature'])
except Placeholder.DoesNotExist:
    # fallback, add it to the
    add_plugin(placeholder['main'], 'TextPlugin', lang, body=content['feature'])
    pass

# Add main content to a MultiColumnPlugin
multi_columns_plugin = add_plugin(placeholder['main'], 'MultiColumnPlugin', lang)
for column_content in content['main']:
    col = add_plugin(placeholder['main'], 'ColumnPlugin', lang,
                     target=multi_columns_plugin, **{'width': '33%'})
    add_plugin(placeholder['main'], 'TextPlugin', lang, body=column_content,
               target=col)

# In order to publish the page there needs to be at least one user
if User.objects.count() > 0:
    try:
        publish_page(page, User.objects.all()[0], lang)
    except TypeError:
        # supporting old cms versions
        publish_page(page, User.objects.all()[0])

@@ -1,16 +1,73 @@
-import json%0A
+from distutils.version import LooseVersion%0Aimport json%0A%0Aimport django
 %0Afro
@@ -197,16 +197,41 @@
 y as _%0A%0A
+%0Adef create_pages():%0A    
 from cms
@@ -257,16 +257,20 @@
 eholder%0A
+    
 from cms
@@ -320,17 +320,20 @@
 h_page%0A%0A
-%0A
+    
 placehol
@@ -342,16 +342,20 @@
 r = %7B%7D%0A%0A
+    
 with ope
@@ -396,16 +396,20 @@
 le:%0A    
+ 
+   
 content 
@@ -432,16 +432,20 @@
 _file)%0A%0A
+    
 try:%0A   
@@ -437,32 +437,36 @@
 )%0A%0A    try:%0A    
+   
+ 
 # try to get a f
@@ -495,16 +495,20 @@
 allback%0A
+    
     temp
@@ -543,16 +543,20 @@
 S%5B1%5D%5B0%5D%0A
+    
     if t
@@ -582,32 +582,36 @@
 .html':%0A        
+ 
+   
 template = setti
@@ -634,16 +634,20 @@
 S%5B0%5D%5B0%5D%0A
+    
 except I
@@ -657,24 +657,28 @@
 xError:%0A    
+   
+ 
 template = s
@@ -706,16 +706,20 @@
 %5B0%5D%5B0%5D%0A%0A
+    
 lang = s
@@ -742,16 +742,20 @@
 S%5B0%5D%5B0%5D%0A
+    
 page = c
@@ -792,16 +792,20 @@
 , lang)%0A
+    
 placehol
@@ -857,16 +857,20 @@
 tent')%0A%0A
+    
 try:%0A   
@@ -866,24 +866,28 @@
    try:%0A    
+  
+  
 # try to get
@@ -905,24 +905,28 @@
 placeholder%0A
+    
     placehol
@@ -977,16 +977,20 @@
 ature')%0A
+    
     p = 
@@ -1060,16 +1060,20 @@
         
+    
 body=con
@@ -1089,16 +1089,20 @@
 ture'%5D)%0A
+    
 except P
@@ -1130,16 +1130,20 @@
 st:%0A    
+  
+  
 # fallba
@@ -1160,16 +1160,20 @@
  to the%0A
+    
     add_
@@ -1253,14 +1253,22 @@
     
+   
+ 
 pass%0A%0A
+    
 # Ad
@@ -1305,16 +1305,20 @@
 nPlugin%0A
+    
 multi_co
@@ -1391,16 +1391,20 @@
 , lang)%0A
+    
 for colu
@@ -1434,16 +1434,20 @@
 main'%5D:%0A
+    
     col 
@@ -1519,24 +1519,28 @@
             
+  
+  
 target=multi
@@ -1576,16 +1576,20 @@
 '33%25'%7D)%0A
+    
     add_
@@ -1657,16 +1657,20 @@
 ontent,%0A
+    
         
@@ -1689,16 +1689,20 @@
 t=col)%0A%0A
+    
 # In ord
@@ -1760,16 +1760,20 @@
 ne user%0A
+    
 if User.
@@ -1793,29 +1793,37 @@
 () %3E 0:%0A    
+ 
+   
 try:%0A
+    
         publ
@@ -1866,24 +1866,28 @@
 , lang)%0A    
+   
+ 
 except TypeE
@@ -1888,24 +1888,28 @@
  TypeError:%0A
+    
         # su
@@ -1934,32 +1934,36 @@
 ersions%0A        
+    
 publish_page(pag
@@ -1988,8 +1988,143 @@
 l()%5B0%5D)%0A
+%0Aif __name__ == '__main__':%0A    if LooseVersion(django.get_version()) %3E= LooseVersion('1.7'):%0A        django.setup()%0A    create_pages()

Fix starting page for Django 1.7