Skip to content

Commit

Permalink
[#1316] Removed name fields and made image and title required
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed May 11, 2023
1 parent 1caa33f commit e474442
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/open_inwoner/cms/banner/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class BannerImageForm(forms.ModelForm):
class Meta:
model = BannerImage
fields = ("name", "image", "image_height")
fields = ("image", "image_height")

def clean(self):
cleaned_data = super().clean()
Expand All @@ -20,4 +20,4 @@ def clean(self):
class BannerTextForm(forms.ModelForm):
class Meta:
model = BannerText
fields = ("name", "title", "description")
fields = ("title", "description")
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.15 on 2023-05-10 11:55
# Generated by Django 3.2.15 on 2023-05-11 09:25

from django.conf import settings
from django.db import migrations, models
Expand All @@ -8,8 +8,8 @@

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

Expand All @@ -29,14 +29,6 @@ class Migration(migrations.Migration):
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(
Expand All @@ -49,9 +41,7 @@ class Migration(migrations.Migration):
(
"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",
Expand All @@ -78,21 +68,11 @@ class Migration(migrations.Migration):
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",
),
),
Expand Down
20 changes: 4 additions & 16 deletions src/open_inwoner/cms/banner/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from django.db import models
from django.utils.translation import ugettext_lazy as _

Expand All @@ -6,15 +8,8 @@


class BannerImage(CMSPlugin):
name = models.CharField(
_("Name"),
max_length=250,
help_text=_("The name of the image (this will not be shown on the page)"),
)
image = FilerImageField(
verbose_name=_("Banner image"),
null=True,
blank=True,
on_delete=models.PROTECT,
help_text=_("Banner image"),
)
Expand All @@ -30,19 +25,12 @@ class BannerImage(CMSPlugin):
)

def __str__(self):
return self.name
return os.path.basename(self.image.file.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"),
)
Expand All @@ -54,4 +42,4 @@ class BannerText(CMSPlugin):
)

def __str__(self):
return self.name
return self.title
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% 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}}">
<img class="main-image" src="{{ instance.image.file.url }}" alt="Header image" height="{{instance.image_height}}">
</aside>
{% endif %}
5 changes: 2 additions & 3 deletions src/open_inwoner/templates/cms/banner/banner_text_plugin.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% if instance.title %}
<h1 class="h1">{{ instance.title }} {{ request.user.get_full_name }}</h1>
{% endif %}
<h1 class="h1">{{ instance.title }} {{ request.user.get_full_name }}</h1>

{% if instance.description %}
<p class="p">{{ instance.description|linebreaksbr }}</p>
{% endif %}

0 comments on commit e474442

Please sign in to comment.