add sections overview plugin
This commit is contained in:
parent
9dcec2fa62
commit
9623f7105b
4 changed files with 114 additions and 1 deletions
|
|
@ -3,7 +3,12 @@ from django.utils.translation import gettext_lazy as _
|
|||
from cms.plugin_base import CMSPluginBase
|
||||
from cms.plugin_pool import plugin_pool
|
||||
|
||||
from .models import PLUGIN_TEMPLATES, GovernmentPlansCMSPlugin
|
||||
from .models import (
|
||||
PLUGIN_TEMPLATES,
|
||||
GovernmentPlanSection,
|
||||
GovernmentPlansCMSPlugin,
|
||||
GovernmentPlanSectionsCMSPlugin,
|
||||
)
|
||||
|
||||
|
||||
@plugin_pool.register_plugin
|
||||
|
|
@ -22,3 +27,24 @@ class GovernmentPlansPlugin(CMSPluginBase):
|
|||
context["request"], published_only=False
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
@plugin_pool.register_plugin
|
||||
class GovernmentPlanSectionsPlugin(CMSPluginBase):
|
||||
name = _("Government plan sections")
|
||||
model = GovernmentPlanSectionsCMSPlugin
|
||||
render_template = "froide_govplan/plugins/sections.html"
|
||||
|
||||
def render(self, context, instance, placeholder):
|
||||
context = super().render(context, instance, placeholder)
|
||||
|
||||
if instance.government:
|
||||
sections = GovernmentPlanSection.objects.filter(
|
||||
government=instance.government
|
||||
)
|
||||
else:
|
||||
sections = GovernmentPlanSection.objects.all()
|
||||
|
||||
context["sections"] = sections
|
||||
|
||||
return context
|
||||
|
|
|
|||
45
froide_govplan/migrations/0006_sections_cms_plugin.py
Normal file
45
froide_govplan/migrations/0006_sections_cms_plugin.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Generated by Django 3.2.12 on 2022-03-14 12:10
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("cms", "0022_auto_20180620_1551"),
|
||||
("froide_govplan", "0005_governmentplansection"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="GovernmentPlanSectionsCMSPlugin",
|
||||
fields=[
|
||||
(
|
||||
"cmsplugin_ptr",
|
||||
models.OneToOneField(
|
||||
auto_created=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
parent_link=True,
|
||||
primary_key=True,
|
||||
related_name="froide_govplan_governmentplansectionscmsplugin",
|
||||
serialize=False,
|
||||
to="cms.cmsplugin",
|
||||
),
|
||||
),
|
||||
(
|
||||
"government",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="froide_govplan.government",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
bases=("cms.cmsplugin",),
|
||||
),
|
||||
]
|
||||
|
|
@ -435,3 +435,12 @@ if CMSPlugin:
|
|||
if self.count == 0:
|
||||
return plans[self.offset :]
|
||||
return plans[self.offset : self.offset + self.count]
|
||||
|
||||
class GovernmentPlanSectionsCMSPlugin(CMSPlugin):
|
||||
"""
|
||||
CMS Plugin for displaying plan sections
|
||||
"""
|
||||
|
||||
government = models.ForeignKey(
|
||||
Government, null=True, blank=True, on_delete=models.SET_NULL
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
{% load thumbnail %}
|
||||
|
||||
<style>
|
||||
{% for section in sections %}
|
||||
#govsection-{{ section.pk }}::after {
|
||||
background-image: url('{% thumbnail section.image 350x150 crop subject_location=instance.picture.subject_location %}');
|
||||
}
|
||||
{% endfor %}
|
||||
</style>
|
||||
|
||||
<div class="row">
|
||||
{% for section in sections %}
|
||||
<div class="col col-12 col-md-4 d-flex mb-3">
|
||||
<a href="{{ section.get_absolute_url }}" class="d-flex w-100 text-body text-decoration-none">
|
||||
<div class="box-card border-blue mb-4">
|
||||
<div>
|
||||
<div class="box-card-header tight-margin d-flex align-items-center has-background p-3 p-md-4 bg-blue-20" id="govsection-{{ section.pk }}">
|
||||
<h3 class="h5 m-0">{{ section.title }}</h3>
|
||||
<div class="ml-auto">
|
||||
<div class="box-card-icon position-static bg-white">
|
||||
<i class="fa fa-{{ section.icon }}"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-grow-1 tight-margin p-3 p-md-4 cms-plugin cms-plugin-87888">
|
||||
progress bar
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue