Skip to content

Commit

Permalink
tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav committed Dec 12, 2024
1 parent 875bf26 commit db01854
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cms/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class CustomTabBlock(blocks.StructBlock):
max_length=50,
help="Displayed as the tab name",
)
href_slug = blocks.CharBlock(
help="id of this element for scrolling on the page. One word or more connected with a dash."
)
content = blocks.RichTextBlock()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.16 on 2024-12-12 19:43

from django.db import migrations
import wagtail.fields


class Migration(migrations.Migration):

dependencies = [
('cms', '0043_coursepage_custom_tab'),
]

operations = [
migrations.RemoveField(
model_name='coursepage',
name='custom_tab',
),
migrations.AddField(
model_name='coursepage',
name='custom_tabs',
field=wagtail.fields.StreamField([('custom_tab', 3)], blank=True, block_lookup={0: ('wagtail.blocks.CharBlock', (), {'help': 'Displayed as the tab name', 'max_length': 50}), 1: ('wagtail.blocks.CharBlock', (), {'help': 'id of this element for scrolling on the page. One word or more connected with a dash.'}), 2: ('wagtail.blocks.RichTextBlock', (), {}), 3: ('wagtail.blocks.StructBlock', [[('title', 0), ('href_slug', 1), ('content', 2)]], {})}, help_text='This is the custom tab for this course.'),
),
]
8 changes: 6 additions & 2 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ class CoursePage(ProductPage):
help_text="The topics for this course page.",
)

custom_tab = StreamField(
custom_tabs = StreamField(
StreamBlock([("custom_tab", CustomTabBlock())], max_num=5),
blank=True,
help_text="This is the custom tab for this course.",
Expand Down Expand Up @@ -1247,6 +1247,9 @@ def get_context(self, request, *args, **kwargs):
else None
)
custom_tabs = []
if self.custom_tab:
for tab in self.custom_tab:
custom_tabs.append({"title": tab.value["title"], "content": tab.value["content"]})
return {
**super().get_context(request, *args, **kwargs),
**get_base_context(request),
Expand All @@ -1257,12 +1260,13 @@ def get_context(self, request, *args, **kwargs):
"can_access_edx_course": can_access_edx_course,
"finaid_price": finaid_price,
"product": product,
"custom_tabs": custom_tabs,
}

content_panels = [ # noqa: RUF005
FieldPanel("course"),
FieldPanel("topics"),
FieldPanel("custom_tab"),
FieldPanel("custom_tabs"),
] + ProductPage.content_panels


Expand Down
13 changes: 9 additions & 4 deletions cms/templates/product_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ <h1>{{ page.title }}</h1>
{% if page.prerequisites %}<li class="nav-item"><a class="nav-link" href="#prerequisites">Prerequisites</a></li>{% endif %}
{% if instructors %}<li class="nav-item"><a class="nav-link" href="#instructors">Instructors</a></li>{% endif %}
{% if page.faq_url %}<li class="nav-item"><a class="nav-link" href="{{page.faq_url}}" target="_blank">FAQs</a></li>{% endif %}
{% if page.custom_tab %}
{% for tab in page.custom_tab %}
<li class="nav-item"><a class="nav-link dropdown-item" href="#">{{ tab }}</a></li>
{% if custom_tabs %}
{% for tab in custom_tabs %}
<li class="nav-item"><a class="nav-link" href="#">{{ tab.title }}</a></li>
{% endfor %}
{% endif %}
{% endif %}
</ul>
</nav>
{# Mobile only #}
Expand All @@ -100,6 +100,11 @@ <h1>{{ page.title }}</h1>
{% if page.prerequisites %}<li class="nav-item"><a class="nav-link dropdown-item" href="#prerequisites">Prerequisites</a></li>{% endif %}
{% if instructors %}<li class="nav-item"><a class="nav-link dropdown-item" href="#instructors">Instructors</a></li>{% endif %}
{% if page.faq_url %}<li class="nav-item"><a class="nav-link dropdown-item" href="{{page.faq_url}}" target="_blank">FAQs</a></li>{% endif %}
{% if custom_tabs %}
{% for tab in custom_tabs %}
<li class="nav-item"><a class="nav-link dropdown-item" href="#">{{ tab.title }}</a></li>
{% endfor %}
{% endif %}
</ul>
</div>
</nav>
Expand Down

0 comments on commit db01854

Please sign in to comment.