Skip to content

Commit

Permalink
✨(demo) add footer as static placeholder in demo site
Browse files Browse the repository at this point in the history
Now that the footer has to be built in a static placeholder, we
need to explicitly declare it in the demo site.
  • Loading branch information
sampaccoud committed Nov 23, 2019
1 parent 9575eeb commit a9e2b55
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/richie/apps/demo/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,46 @@
}
SINGLECOLUMN_CONTENT.update(getattr(settings, "RICHIE_DEMO_SINGLECOLUMN_CONTENT", {}))

FOOTER_CONTENT = {
"en": [
{
"items": [
{"name": "About", "internal_link": "annex__about"},
{"name": "Sitemap", "internal_link": "annex__sitemap"},
]
},
{
"title": "Richie community",
"items": [
{"name": "Website", "external_link": "https://richie.education"},
{
"name": "Github",
"external_link": "https://github.com/openfun/richie",
},
],
},
],
"fr": [
{
"items": [
{"name": "A propos", "internal_link": "annex__about"},
{"name": "Plan du site", "internal_link": "annex__sitemap"},
]
},
{
"title": "Communauté Richie",
"items": [
{"name": "Site web", "external_link": "https://richie.education"},
{
"name": "Github",
"external_link": "https://github.com/openfun/richie",
},
],
},
],
}
FOOTER_CONTENT.update(getattr(settings, "FOOTER_CONTENT", {}))

SITEMAP_PAGE_PARAMS = {
"blogposts": {"max_depth": 1},
"courses": {"max_depth": 1},
Expand Down
38 changes: 38 additions & 0 deletions src/richie/apps/demo/management/commands/create_demo_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import factory
from cms.api import add_plugin
from cms.models import StaticPlaceholder

from richie.apps.core.factories import create_text_plugin, image_getter
from richie.apps.core.helpers import recursive_page_creation
Expand All @@ -25,6 +26,7 @@
)

from ...defaults import (
FOOTER_CONTENT,
HOMEPAGE_CONTENT,
ICONS_INFO,
LEVELS_INFO,
Expand Down Expand Up @@ -81,6 +83,42 @@ def create_demo_site():
# Create pages as described in PAGES_INFOS
pages_created = recursive_page_creation(site, PAGES_INFO)

# Create the footer links
footer_static_ph = StaticPlaceholder.objects.get_or_create(code="footer")[0]
for footer_placeholder in [footer_static_ph.draft, footer_static_ph.public]:
for language, content in FOOTER_CONTENT.items():
# Create the <ul> section to carry the list of links
section_plugin = add_plugin(
footer_placeholder,
plugin_type="SectionPlugin",
language=language,
template="richie/section/section_list.html",
)

# One column per content object
for footer_info in content:
column_plugin = add_plugin(
footer_placeholder,
plugin_type="SectionPlugin",
language=language,
target=section_plugin,
template="richie/section/section_list.html",
title=footer_info.get("title"),
)
for item_info in footer_info.get("items", []):
if "internal_link" in item_info:
item_info = item_info.copy()
item_info["internal_link"] = pages_created[
item_info["internal_link"]
]
add_plugin(
footer_placeholder,
plugin_type="LinkPlugin",
language=language,
target=column_plugin,
**item_info,
)

# Create some licences
licences = LicenceFactory.create_batch(
NB_OBJECTS["licences"], logo__file__from_path=pick_image("licence")()
Expand Down
2 changes: 1 addition & 1 deletion tests/apps/demo/test_commands_create_demo_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def test_commands_create_demo_site_method(self, *_):
self.assertEqual(models.Person.objects.count(), 2)
self.assertEqual(models.Licence.objects.count(), 1)
self.assertEqual(models.Program.objects.count(), 2)
self.assertEqual(CMSPlugin.objects.count(), 504)
self.assertEqual(CMSPlugin.objects.count(), 532)

0 comments on commit a9e2b55

Please sign in to comment.