Skip to content

Commit

Permalink
[#1316] Added banner title and desciption, split off banner image and…
Browse files Browse the repository at this point in the history
… texts
  • Loading branch information
vaszig committed May 10, 2023
1 parent ff8ec54 commit 0c60c62
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 72 deletions.
22 changes: 15 additions & 7 deletions src/open_inwoner/cms/banner/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

from .forms import BannerForm
from .models import Banner
from .forms import BannerImageForm, BannerTextForm
from .models import BannerImage, BannerText


@plugin_pool.register_plugin
class BannerPlugin(CMSPluginBase):
model = Banner
form = BannerForm
name = _("Banner Plugin")
render_template = "cms/banner/banner_plugin.html"
class BannerImagePlugin(CMSPluginBase):
model = BannerImage
form = BannerImageForm
name = _("Banner Image Plugin")
render_template = "cms/banner/banner_image_plugin.html"


@plugin_pool.register_plugin
class BannerTextPlugin(CMSPluginBase):
model = BannerText
form = BannerTextForm
name = _("Banner Text Plugin")
render_template = "cms/banner/banner_text_plugin.html"
14 changes: 10 additions & 4 deletions src/open_inwoner/cms/banner/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import forms

from .models import Banner
from .models import BannerImage, BannerText


class BannerForm(forms.ModelForm):
class BannerImageForm(forms.ModelForm):
class Meta:
model = Banner
fields = ("name", "title", "description", "image", "image_height")
model = BannerImage
fields = ("name", "image", "image_height")

def clean(self):
cleaned_data = super().clean()
Expand All @@ -15,3 +15,9 @@ def clean(self):
image_height = cleaned_data.get("image_height")
if image and image_height is None:
cleaned_data["image_height"] = int(image.height)


class BannerTextForm(forms.ModelForm):
class Meta:
model = BannerText
fields = ("name", "title", "description")
38 changes: 0 additions & 38 deletions src/open_inwoner/cms/banner/migrations/0003_auto_20230509_1038.py

This file was deleted.

117 changes: 117 additions & 0 deletions src/open_inwoner/cms/banner/migrations/0003_auto_20230510_1355.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Generated by Django 3.2.15 on 2023-05-10 11:55

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import filer.fields.image


class Migration(migrations.Migration):
dependencies = [
("cms", "0022_auto_20180620_1551"),
migrations.swappable_dependency(settings.FILER_IMAGE_MODEL),
("banner", "0002_banner_image_height"),
]

operations = [
migrations.CreateModel(
name="BannerImage",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
related_name="banner_bannerimage",
serialize=False,
to="cms.cmsplugin",
),
),
(
"name",
models.CharField(
help_text="The name of the image (this will not be shown on the page)",
max_length=250,
verbose_name="Name",
),
),
(
"image_height",
models.PositiveIntegerField(
blank=True,
help_text='The image custom height as number in pixels. Example: "720" and not "720px".Leave this field empty if you want the original height of the image to be applied.',
null=True,
verbose_name="Custom image height",
),
),
(
"image",
filer.fields.image.FilerImageField(
blank=True,
help_text="Banner image",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to=settings.FILER_IMAGE_MODEL,
verbose_name="Banner image",
),
),
],
options={
"abstract": False,
},
bases=("cms.cmsplugin",),
),
migrations.CreateModel(
name="BannerText",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
related_name="banner_bannertext",
serialize=False,
to="cms.cmsplugin",
),
),
(
"name",
models.CharField(
help_text="The name of the text block (this will not be shown on the page)",
max_length=250,
verbose_name="Name",
),
),
(
"title",
models.CharField(
blank=True,
help_text="The title of the text block",
max_length=250,
null=True,
verbose_name="Title",
),
),
(
"description",
models.TextField(
blank=True,
help_text="The description of the text block",
null=True,
verbose_name="Description",
),
),
],
options={
"abstract": False,
},
bases=("cms.cmsplugin",),
),
migrations.DeleteModel(
name="Banner",
),
]
41 changes: 28 additions & 13 deletions src/open_inwoner/cms/banner/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@
from filer.fields.image import FilerImageField


class Banner(CMSPlugin):
name = models.CharField(_("Name"), max_length=250, default="")
title = models.CharField(
_("Title"),
null=True,
blank=True,
class BannerImage(CMSPlugin):
name = models.CharField(
_("Name"),
max_length=250,
help_text=_("Title to be shown along with the banner."),
)
description = models.TextField(
verbose_name=_("Description"),
null=True,
blank=True,
help_text=_("Description to be shown along with the banner."),
help_text=_("The name of the image (this will not be shown on the page)"),
)
image = FilerImageField(
verbose_name=_("Banner image"),
Expand All @@ -40,3 +31,27 @@ class Banner(CMSPlugin):

def __str__(self):
return self.name


class BannerText(CMSPlugin):
name = models.CharField(
_("Name"),
max_length=250,
help_text=_("The name of the text block (this will not be shown on the page)"),
)
title = models.CharField(
_("Title"),
null=True,
blank=True,
max_length=250,
help_text=_("The title of the text block"),
)
description = models.TextField(
verbose_name=_("Description"),
null=True,
blank=True,
help_text=_("The description of the text block"),
)

def __str__(self):
return self.name
3 changes: 2 additions & 1 deletion src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@
# "LinkPlugin": ["TextPlugin"],
# },
},
"banner": {"plugins": ["BannerPlugin"], "name": _("Banner")},
"banner_image": {"plugins": ["BannerImagePlugin"], "name": _("Banner Image")},
"banner_text": {"plugins": ["BannerTextPlugin"], "name": _("Banner Text")},
}

#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% load i18n sekizai_tags %}

{% if instance.image %}
<aside class="banner" aria-hidden="true">
<img class="main-image" src="{{ instance.image.file.url }}" alt={{ instance.title|default:_("Header image") }} height="{{instance.image_height}}">
Expand Down
6 changes: 6 additions & 0 deletions src/open_inwoner/templates/cms/banner/banner_text_plugin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if instance.title %}
<h1 class="h1">{{ instance.title }} {{ request.user.get_full_name }}</h1>
{% endif %}
{% if instance.description %}
<p class="p">{{ instance.description|linebreaksbr }}</p>
{% endif %}
14 changes: 7 additions & 7 deletions src/open_inwoner/templates/cms/fullwidth.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block header_image %}
{% if request.user.is_authenticated %}
{% placeholder 'banner' %}
{% placeholder 'banner_image' %}
{% else %}
<aside class="banner" aria-hidden="true">
<img class="main-image" src="{{ hero_image_login }}" alt="Header image">
Expand All @@ -13,12 +13,12 @@

{% block content %}
{% if not request.user.is_authenticated %}
{% block user_content %}
<div class="grid__welcome">
<h1 class="h1">{{configurable_text.home_page.home_welcome_title}}</h1>
<p class="p">{{configurable_text.home_page.home_welcome_intro|linebreaksbr}}</p>
</div>
{% endblock %}
<div class="grid__welcome">
<h1 class="h1">{{configurable_text.home_page.home_welcome_title}}</h1>
<p class="p">{{configurable_text.home_page.home_welcome_intro|linebreaksbr}}</p>
</div>
{% else %}
{% placeholder 'banner_text' %}
{% endif %}

<div class="debug-cms-block">
Expand Down

0 comments on commit 0c60c62

Please sign in to comment.