Skip to content

Commit

Permalink
Fix starting page script for django CMS 3.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jun 30, 2019
1 parent 144145e commit e366661
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
9 changes: 7 additions & 2 deletions djangocms_installer/share/starting_page.py
Expand Up @@ -47,12 +47,17 @@ def create_pages():
target=col)

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


if __name__ == '__main__':
Expand Down
38 changes: 35 additions & 3 deletions tests/django.py
Expand Up @@ -560,19 +560,51 @@ def test_starting_page(self):
django.setup_database(config_data)
django.load_starting_page(config_data)
project_db = sqlite3.connect(os.path.join(config_data.project_directory, 'test.db'))
project_db.row_factory = sqlite3.Row

# Check loaded data
query = project_db.execute('SELECT * FROM cms_page')
row = query.fetchone()
self.assertTrue('fullwidth.html' in row)
self.assertTrue(row['is_home'])
self.assertEqual('fullwidth.html', row['template'])

query = project_db.execute('SELECT * FROM cms_title')
row = query.fetchone()
self.assertTrue('Home' in row)
self.assertEqual('Home', row['title'])

query = project_db.execute('SELECT * FROM cms_cmsplugin')
row = query.fetchone()
self.assertTrue('TextPlugin' in row)
self.assertEqual('TextPlugin', row['plugin_type'])

@unittest.skipIf(sys.version_info[:2] not in ((2, 7), (3, 4), (3, 5), (3, 6), (3, 7),),
reason='django 1.11 only supports python 2.7, 3.4, 3.5, 3.6 and 3.7,')
def test_starting_page_36(self):
config_data = config.parse(['--db=sqlite://localhost/test.db',
'-q', '-u', '--django-version=1.11',
'--cms-version=3.6', '--starting-page=yes',
'-p' + self.project_dir, 'cms_project'])
install.requirements(config_data.requirements)
django.create_project(config_data)
django.patch_settings(config_data)
django.copy_files(config_data)
django.setup_database(config_data)
django.load_starting_page(config_data)
project_db = sqlite3.connect(os.path.join(config_data.project_directory, 'test.db'))
project_db.row_factory = sqlite3.Row

# Check loaded data
query = project_db.execute('SELECT * FROM cms_page')
row = query.fetchone()
self.assertTrue(row['is_home'])
self.assertEqual('fullwidth.html', row['template'])

query = project_db.execute('SELECT * FROM cms_title')
row = query.fetchone()
self.assertEqual('Home', row['title'])

query = project_db.execute('SELECT * FROM cms_cmsplugin')
row = query.fetchone()
self.assertEqual('TextPlugin', row['plugin_type'])

@unittest.skipIf(sys.version_info[:2] not in ((2, 7), (3, 4), (3, 5), (3, 6), (3, 7),),
reason='django 1.8 only supports python 2.7, 3.4, 3.5, 3.6 and 3.7,')
Expand Down

0 comments on commit e366661

Please sign in to comment.