Skip to content

Commit

Permalink
Merge pull request #954 from okfn/902/make-frontpage-dynamic
Browse files Browse the repository at this point in the history
Make front page dynamic
  • Loading branch information
shashigharti authored Sep 19, 2023
2 parents 68a93a7 + d796161 commit 25dc9dc
Show file tree
Hide file tree
Showing 33 changed files with 623 additions and 443 deletions.
19 changes: 18 additions & 1 deletion foundation/okfplugins/feature_block/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
from cms.plugin_pool import plugin_pool
from django.utils.translation import gettext_lazy as _
from .forms import FeatureBlockForm
from .models import FeatureBlock
from .models import FeatureBlock, FeatureBlockContainer


@plugin_pool.register_plugin
class FeatureBlockContainerPlugin(CMSPluginBase):
model = FeatureBlockContainer
module = "OKF v2"

cache = False
allow_children = True
render_template = "feature_block_container_plugin.html"
name = _("Feature Block Container")
child_classes = ["FeatureBlockPlugin"]

def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)

return context


@plugin_pool.register_plugin
Expand Down
2 changes: 1 addition & 1 deletion foundation/okfplugins/feature_block/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


class FeatureBlockForm(ModelForm):
image = SvgAndImageFormField()
image = SvgAndImageFormField(required=False)
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@


class Migration(migrations.Migration):

dependencies = [
('feature_block', '0006_alter_featureblock_block_type'),
("feature_block", "0006_alter_featureblock_block_type"),
]

operations = [
migrations.AlterField(
model_name='featureblock',
name='block_type',
field=models.CharField(choices=[('yellow', 'Yellow'), ('white', 'White'), ('transparent_title', 'Transparent with Title'), ('transparent', 'Transparent'), ('background_rounded', 'Rounded corners'), ('blue', 'Blue Background'), ('yellow', 'Yellow Background'), ('purple', 'Purple Background')], default='yellow', max_length=20),
model_name="featureblock",
name="block_type",
field=models.CharField(
choices=[
("yellow", "Yellow"),
("white", "White"),
("transparent_title", "Transparent with Title"),
("transparent", "Transparent"),
("background_rounded", "Rounded corners"),
("blue", "Blue Background"),
("yellow", "Yellow Background"),
("purple", "Purple Background"),
],
default="yellow",
max_length=20,
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("cms", "0022_auto_20180620_1551"),
("feature_block", "0007_alter_featureblock_block_type"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.3 on 2023-08-09 09:36

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("feature_block", "0009_alter_featureblock_block_type"),
]

operations = [
migrations.AlterField(
model_name="featureblock",
name="block_type",
field=models.CharField(
choices=[
("yellow", "Yellow"),
("white", "White"),
("transparent_title", "Transparent with Title"),
("transparent_no_title", "Transparent without Title"),
("background_rounded", "Rounded corners"),
("header_background", "Header Background"),
("blue", "Blue Background"),
("yellow", "Yellow Background"),
("purple", "Purple Background"),
],
default="yellow",
max_length=20,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.3 on 2023-08-14 06:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("cms", "0022_auto_20180620_1551"),
("feature_block", "0010_alter_featureblock_block_type"),
]

operations = [
migrations.CreateModel(
name="FeatureBlockContainer",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
related_name="%(app_label)s_%(class)s",
serialize=False,
to="cms.cmsplugin",
),
),
("title", models.CharField(max_length=200)),
],
options={
"abstract": False,
},
bases=("cms.cmsplugin",),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Django 4.2.3 on 2023-08-22 08:07

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("feature_block", "0010_featureblock_text_color"),
("feature_block", "0011_featureblockcontainer"),
]

operations = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.3 on 2023-08-22 08:52

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("feature_block", "0012_merge_20230822_0807"),
]

operations = [
migrations.AlterField(
model_name="featureblock",
name="block_type",
field=models.CharField(
choices=[
("yellow_box", "Yellow Box"),
("white_box", "White Box"),
("transparent_title", "Transparent with Title"),
("transparent_no_title", "Transparent without Title"),
("background_rounded", "Rounded corners"),
("header_background", "Header Background"),
("blue", "Blue Background"),
("yellow", "Yellow Background"),
("purple", "Purple Background"),
],
default="yellow",
max_length=20,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.3 on 2023-09-13 07:39

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("feature_block", "0013_alter_featureblock_block_type"),
]

operations = [
migrations.AddField(
model_name="featureblockcontainer",
name="show_title",
field=models.BooleanField(default=False),
),
]
16 changes: 11 additions & 5 deletions foundation/okfplugins/feature_block/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
("yellow_box", "Yellow Box"),
("white_box", "White Box"),
("transparent_title", "Transparent with Title"),
("transparent", "Transparent"),
("transparent_no_title", "Transparent without Title"),
("background_rounded", "Rounded corners"),
("header_background", "Header Background"),
("blue", "Blue Background"),
("yellow", "Yellow Background"),
("purple", "Purple Background"),
)


TEXT_COLOR_CHOICES = (
("black", "Black"),
("white", "White")
)
TEXT_COLOR_CHOICES = (("black", "Black"), ("white", "White"))


class FeatureBlockContainer(CMSPlugin):
title = models.CharField(max_length=200)
show_title = models.BooleanField(default=False)

def __str__(self):
return self.title


class FeatureBlock(CMSPlugin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<section class="sect sect-features -tighten-1 mb-20">
<div class="sect__content">
{% if instance.show_title %}
<h2 class="mb-20 text-h1 text-center font-bold leading-none">{{ instance.title | safe }}</h2>
{% endif %}
<div class="grid grid-cols-1 md:grid-cols-3 gap-10 lg:gap-16 mx-auto">
{% for instance in instance.child_plugin_instances %}
{% include 'feature_block_plugin.html' with instance=instance %}
{% endfor %}
</div>
</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- White Box -->
{% if instance.block_type == 'white_box'%}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="relative block px-4 lg:px-8 pt-5 lg:pt-10 pb-28 border-3 border-black bg-white bg-opacity-30 group">
Expand All @@ -12,9 +13,27 @@ <h3 class="title block mb-8 font-bold text-2xl">{{ instance.title }}</h3>
{% else %}
</div>
{% endif %}

<!-- Yellow Box-->
{% elif instance.block_type == 'yellow_box' %}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="content-grid__item">
{% else %}
<div class="content-grid__item">
{% endif %}
<h3 class="title block mb-8 font-bold text-2xl">{{ instance.title }}</h3>
<p>{{ instance.text }}</p>
<time class="date" date-time="{{ instance.date_number }}">{{ instance.date }}</time>
{% if instance.url and instance.url != '' %}
</a>
{% else %}
</div>
{% endif %}

<!-- Transparent Title -->
{% elif instance.block_type == 'transparent_title' %}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="feature-item -center">
<a href="{{ instance.url }}" class="feature-item -center">
{% else %}
<div class="feature-item -center">
{% endif %}
Expand All @@ -36,49 +55,53 @@ <h3 class="title block mb-8 font-bold text-2xl">{{ instance.title }}</h3>
{% else %}
</div>
{% endif %}
{% elif instance.block_type == 'transparent' %}

<!-- Transparent Without Title -->
{% elif instance.block_type == 'transparent_no_title' %}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="feature-item">
{% else %}
<div class="feature-item">
{% endif %}
<figure class="">
<img src="{% if instance.image %}{{ instance.image.url}}{% endif %}" alt="">
</figure>
<span class="description">{{ instance.text}}</span>
<figure class="">
<img src="{% if instance.image %}{{ instance.image.url}}{% endif %}" alt="">
</figure>
<span class="description">{{ instance.text}}</span>
{% if instance.url and instance.url != '' %}
<em class="link-arrow-curved">
Learn more
</em>
<em class="link-arrow-curved">
Learn more
</em>
</a>
{% else %}
</div>
{% endif %}

<!-- Background Rounded -->
{% elif instance.block_type == 'background_rounded' %}
<a href="{{ instance.url }}" class="content-grid__item-rounded relative flex items-center justify-center p-4 group aspect-square rounded-[2rem] overflow-hidden">
<h3 class="relative z-10 title block font-bold text-2xl"> {{ instance.title }} </h3>
<div class="image absolute inset-0 z-0">
<img src="{% if instance.image %}{{ instance.image.url}}{% endif %}" alt="OKFN" class="w-full h-full object-cover">
</div>
</a>
{% elif instance.block_type == 'yellow_box' %}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="content-grid__item">
{% else %}
<div class="content-grid__item">
{% endif %}
<h3 class="title block mb-8 font-bold text-2xl">{{ instance.title }}</h3>
<p>{{ instance.text }}</p>
<time class="date" date-time="{{ instance.date_number }}">{{ instance.date }}</time>
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="content-grid__item-rounded relative flex items-center justify-center p-4 group aspect-square rounded-[2rem] overflow-hidden">
<h3 class="relative z-10 title block font-bold text-2xl"> {{ instance.title }} </h3>
<div class="image absolute inset-0 z-0">
<img src="{% if instance.image %}{{ instance.image.url}}{% endif %}" alt="OKFN" class="w-full h-full object-cover">
</div>
</a>
{% else %}
</div>
{% endif %}

<!-- Blue/Purple/Yellow Background -->
{% elif instance.block_type == 'blue' or instance.block_type == 'purple' or instance.block_type == 'yellow'%}
<a href="{{ instance.url }}" class="content-grid__item-background relative flex items-center justify-center p-4 group aspect-square -has-bg-circle -bg-circle-full {% if instance.block_type != 'blue'%}-bg-circle-okfn-{{ instance.block_type }} {% endif %} text-{{ instance.text_color }}">
<h3 class="title relative z-10 title block font-bold text-2xl"> {{ instance.title }} </h3>
</a>
<a href="{{ instance.url }}" class="content-grid__item-background relative flex items-center justify-center p-4 group aspect-square -has-bg-circle -bg-circle-full {% if instance.block_type != 'blue'%}-bg-circle-okfn-{{ instance.block_type }} {% endif %} text-{{ instance.text_color }}">
<h3 class="title relative z-10 title block font-bold text-2xl"> {{ instance.title }} </h3>
</a>

<!-- Header Only with Blue Background -->
{% elif instance.block_type == 'header_background' %}
<a href="{{ instance.url }}" class="relative flex items-center -has-bg-circles min-h-[25rem] px-4 lg:px-8 py-5 lg:py-10 pb-28 border-3 border-black bg-white bg-opacity-30 group">
<h3 class="title block w-full font-bold text-lg text-center">
{{ instance.title }}
<span class="block font-mono">{{ instance.text }}</span>
</h3>
<span class="link-arrow-curved absolute left-8 bottom-8 group-hover:drop-shadow-okfn">Learn more</span>
</a>

<!-- Default -->
{% else %}
{% if instance.url and instance.url != '' %}
<a href="{{ instance.url }}" class="content-grid__item">
Expand All @@ -94,4 +117,4 @@ <h3 class="title block mb-8 font-bold text-2xl">{{ instance.title }}</h3>
</div>
{% endif %}

{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("cms", "0022_auto_20180620_1551"),
("gallery", "0001_initial"),
Expand Down
Loading

0 comments on commit 25dc9dc

Please sign in to comment.