Skip to content

Commit

Permalink
feat: add sponsors section
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanashraf7 committed Oct 24, 2023
1 parent 339c67b commit c3fd2c6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cms/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ class InstructorBlock(blocks.StructBlock):
)


class SponsorBlock(blocks.StructBlock):
"""
Block class that defines a instructor
"""

name = blocks.CharBlock(max_length=100, help_text="Name of the sponsor.")
image = ImageChooserBlock(
help_text="Profile image size must be at least 300x300 pixels."
)
title = blocks.CharBlock(
max_length=255, help_text="A brief description about the sponsor."
)

class InstructorSectionBlock(blocks.StructBlock):
"""
Block class that defines a instrcutors section
Expand All @@ -48,6 +61,26 @@ class InstructorSectionBlock(blocks.StructBlock):
)


class SponsorSectionBlock(blocks.StructBlock):
"""
Block class that defines a instrcutors section
"""

heading = blocks.CharBlock(
max_length=255, help_text="The heading to display for this section on the page."
)
subhead = blocks.RichTextBlock(
help_text="The subhead to display for this section on the page."
)
heading_singular = blocks.CharBlock(
max_length=100, help_text="Heading that will highlight the sponsor point."
)
members = blocks.StreamBlock(
[("sponsor", SponsorBlock())],
help_text="The sponsors to display in this section",
)


class ThreeColumnImageTextBlock(blocks.StructBlock):
"""
A generic custom block used to input heading, sub-heading, body and image.
Expand Down
32 changes: 32 additions & 0 deletions cms/migrations/0036_add_sponsors_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.16 on 2023-10-24 10:56

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0023_add_choose_permissions'),
('wagtailcore', '0066_collection_management_permissions'),
('cms', '0035_rename_admissions_format_to_location'),
]

operations = [
migrations.CreateModel(
name='SponsorsSection',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('heading', wagtail.core.fields.RichTextField(default='Sponsors', help_text='The heading to display on this section.')),
('sections', wagtail.core.fields.StreamField([('section', wagtail.core.blocks.StructBlock([('heading', wagtail.core.blocks.CharBlock(help_text='The heading to display for this section on the page.', max_length=255)), ('subhead', wagtail.core.blocks.RichTextBlock(help_text='The subhead to display for this section on the page.')), ('heading_singular', wagtail.core.blocks.CharBlock(help_text='Heading that will highlight the sponsor point.', max_length=100)), ('members', wagtail.core.blocks.StreamBlock([('sponsor', wagtail.core.blocks.StructBlock([('name', wagtail.core.blocks.CharBlock(help_text='Name of the sponsor.', max_length=100)), ('image', wagtail.images.blocks.ImageChooserBlock(help_text='Profile image size must be at least 300x300 pixels.')), ('title', wagtail.core.blocks.CharBlock(help_text='A brief description about the sponsor.', max_length=255))]))], help_text='The sponsors to display in this section'))]))], help_text='The Sponsor to display in this section')),
('banner_image', models.ForeignKey(help_text='Image that will display as a banner at the top of the section, must be at least 750x505 pixels.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]
32 changes: 32 additions & 0 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from cms.blocks import (
ResourceBlock,
InstructorSectionBlock,
SponsorSectionBlock,
ThreeColumnImageTextBlock,
AlumniBlock,
TitleLinksBlock,
Expand Down Expand Up @@ -223,6 +224,11 @@ def instructors(self):
"""Gets the faculty members page"""
return self._get_child_page_of_type(InstructorsSection)

@property
def sponsors(self):
"""Gets the sponsors page"""
return self._get_child_page_of_type(SponsorsSection)

@property
def alumni(self):
"""Gets the faculty members page"""
Expand All @@ -242,6 +248,7 @@ def admissions_section(self):
"ThreeColumnImageTextSection",
"ProgramDescriptionSection",
"InstructorsSection",
"SponsorsSection",
"AlumniSection",
"LearningResourceSection",
"AdmissionsSection",
Expand Down Expand Up @@ -280,6 +287,7 @@ def get_context(self, request, *args, **kwargs):
"admissions_section": self.admissions_section,
"alumni": self.alumni,
"instructors": self.instructors,
"sponsors": self.sponsors,
"learning_resources": self.learning_resources,
"program_description_section": self.program_description_section,
"three_column_image_text_section": self.three_column_image_text_section,
Expand Down Expand Up @@ -445,6 +453,30 @@ class InstructorsSection(BootcampRunChildPage):
StreamFieldPanel("sections"),
]

class SponsorsSection(BootcampRunChildPage):
"""SponsorsPage representing a "Bootcamp Sponsors" section on a product page"""

banner_image = models.ForeignKey(
Image,
null=True,
on_delete=models.SET_NULL,
related_name="+",
help_text="Image that will display as a banner at the top of the section, must be at least 750x505 pixels.",
)
heading = RichTextField(
default="Sponsors",
blank=False,
help_text="The heading to display on this section.",
)
sections = StreamField(
[("section", SponsorSectionBlock())],
help_text="The Sponsor to display in this section",
)
content_panels = [
ImageChooserPanel("banner_image"),
FieldPanel("heading"),
StreamFieldPanel("sections"),
]

class AdmissionsSection(BootcampRunChildPage):
"""
Expand Down
1 change: 1 addition & 0 deletions cms/templates/product_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h3>{{ page.bootcamp_run.start_date|date }} - {{ page.bootcamp_run.end_date|date
{% if program_description_section %} {% include "partials/program-description.html" with page=program_description_section %} {% endif %}
{% if admissions_section %}{% include "partials/admissions-section.html" with page=admissions_section %}{% endif %}
{% if instructors %} {% include "partials/instructor.html" with page=instructors %} {% endif %}
{% if sponsors %} {% include "partials/instructor.html" with page=sponsors %} {% endif %}
{% if alumni %} {% include "partials/alumni.html" with page=alumni %} {% endif %}
{% if learning_resources %} {% include "partials/learning-resources.html" with page=learning_resources %} {% endif %}
</div>
Expand Down

0 comments on commit c3fd2c6

Please sign in to comment.