Skip to content

Commit

Permalink
feat: add sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanashraf7 committed Oct 27, 2023
1 parent 339c67b commit c90007d
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 16 deletions.
45 changes: 37 additions & 8 deletions cms/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
from wagtail.core.blocks import StructValue


class ResourceBlock(blocks.StructBlock):
Expand All @@ -16,22 +17,28 @@ class ResourceBlock(blocks.StructBlock):

class InstructorBlock(blocks.StructBlock):
"""
Block class that defines a instructor
Block class that defines a instructor or sponsor
"""

name = blocks.CharBlock(max_length=100, help_text="Name of the instructor.")
name = blocks.CharBlock(max_length=100, help_text="Name of the instructor/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 instructor."
max_length=255, help_text="A brief description about the instructor/sponsor."
)


class InstructorSectionBlock(blocks.StructBlock):
"""
Block class that defines a instrcutors section
"""
class InstructorSponsorItems(StructValue):
"""Custom value for StructBlock so that it can return Instructors or Sponsors"""

def instructor_sponsor_items(self):
"""Return possible items for Instructors or Sponsors to be displayed to the user"""
return self.get("members") or self.get("sponsors")


class InstructorSponsorBlock(blocks.StructBlock):
"""Parent Block class for sponsors and instructors"""

heading = blocks.CharBlock(
max_length=255, help_text="The heading to display for this section on the page."
Expand All @@ -40,14 +47,36 @@ class InstructorSectionBlock(blocks.StructBlock):
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 instructor point."
max_length=100,
help_text="Heading that will highlight the instructor or sponsor point.",
)

class Meta:
value_class = InstructorSponsorItems


class InstructorSectionBlock(InstructorSponsorBlock):
"""
Block class that defines an instrcutor section
"""

members = blocks.StreamBlock(
[("member", InstructorBlock())],
help_text="The instructors to display in this section",
)


class SponsorSectionBlock(InstructorSponsorBlock):
"""
Block class that defines a sponsor section
"""

sponsors = blocks.StreamBlock(
[("sponsor", InstructorBlock())],
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
26 changes: 26 additions & 0 deletions cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ThreeColumnImageTextBlock,
InstructorSectionBlock,
InstructorBlock,
SponsorSectionBlock,
)
from klasses.factories import BootcampRunFactory

Expand Down Expand Up @@ -140,6 +141,18 @@ class Meta:
model = InstructorSectionBlock


class SponsorSectionBlockFactory(wagtail_factories.StructBlockFactory):
"""SponsorSectionBlockFactory factory class"""

heading = factory.fuzzy.FuzzyText(prefix="Heading ")
sub_heading = factory.fuzzy.FuzzyText(prefix="Sub Heading ")
heading_singular = factory.fuzzy.FuzzyText(prefix="Heading Singular ")
sponsors = factory.SubFactory(InstructorBlockFactory)

class Meta:
model = SponsorSectionBlock


class ProgramDescriptionSectionFactory(wagtail_factories.PageFactory):
"""ProgramDescriptionSection factory class"""

Expand Down Expand Up @@ -268,6 +281,19 @@ class Meta:
model = models.InstructorsSection


class SponsorSectionFactory(wagtail_factories.PageFactory):
"""InstructorSectionFactory factory class"""

banner_image = factory.SubFactory(wagtail_factories.ImageFactory)
heading = factory.fuzzy.FuzzyText(prefix="heading ")
sections = wagtail_factories.StreamFieldFactory(
{"section": InstructorSectionBlockFactory}
)

class Meta:
model = models.SponsorsSection


class AdmissionSectionFactory(wagtail_factories.PageFactory):
"""AdmissionSectionFactory factory class"""

Expand Down
197 changes: 197 additions & 0 deletions cms/migrations/0036_add_sponsors_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Generated by Django 3.2.16 on 2023-10-25 22:48

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.AlterField(
model_name="instructorssection",
name="sections",
field=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 instructor or sponsor point.",
max_length=100,
),
),
(
"members",
wagtail.core.blocks.StreamBlock(
[
(
"member",
wagtail.core.blocks.StructBlock(
[
(
"name",
wagtail.core.blocks.CharBlock(
help_text="Name of the instructor/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 instructor/sponsor.",
max_length=255,
),
),
]
),
)
],
help_text="The instructors to display in this section",
),
),
]
),
)
],
help_text="The instructor to display in this section",
),
),
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 instructor or sponsor point.",
max_length=100,
),
),
(
"sponsors",
wagtail.core.blocks.StreamBlock(
[
(
"sponsor",
wagtail.core.blocks.StructBlock(
[
(
"name",
wagtail.core.blocks.CharBlock(
help_text="Name of the instructor/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 instructor/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",),
),
]
Loading

0 comments on commit c90007d

Please sign in to comment.