Skip to content

Commit

Permalink
Merge pull request #1099 from ecds/feature/custom-bg-image
Browse files Browse the repository at this point in the history
Allow custom background image via wagtail
  • Loading branch information
blms authored Oct 14, 2024
2 parents ba684b1 + cf12564 commit 209b259
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
27 changes: 27 additions & 0 deletions apps/cms/migrations/0008_homepage_background_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.25 on 2024-10-14 17:20

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


class Migration(migrations.Migration):

dependencies = [
("wagtailimages", "0025_alter_image_file_alter_rendition_file"),
("cms", "0007_homepage_featured_video"),
]

operations = [
migrations.AddField(
model_name="homepage",
name="background_image",
field=models.ForeignKey(
blank=True,
help_text="Optional background image for the site header",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.image",
),
),
]
10 changes: 10 additions & 0 deletions apps/cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ class HomePage(Page):
collections = Collection.objects.all()[:8]
volumes = Manifest.objects.all()[:8]

background_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
help_text="Optional background image for the site header",
)

featured_story_title = models.CharField(
help_text="Title of the featured story", blank=True, max_length=255
)
Expand Down Expand Up @@ -286,6 +295,7 @@ class HomePage(Page):

content_panels = Page.content_panels + [
FieldPanel('tagline', classname="full"),
FieldPanel('background_image', classname="full"),
FieldPanel('content_display', classname="full"),
AutocompletePanel('featured_collections', target_model="kollections.Collection"),
FieldPanel('featured_collections_sort_order', classname="full"),
Expand Down
2 changes: 1 addition & 1 deletion apps/templates/_home/_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="uk-navbar-left">
<div class="uk-logo">
<div><a class="brand-logo" href="/">{{ request.site.name }}</a></div>
<div class="brand-tagline">built on <a class="brand-readux">Readux</a></div>
<div class="brand-tagline">built on <a class="brand-readux" href="https://readux.io/">Readux</a></div>
</div>

{% main_menu add_sub_menus_inline=True %}
Expand Down
12 changes: 5 additions & 7 deletions apps/templates/cms/home_page.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{% extends "base.html" %}
{% load static %}
{% load readux_templatetags %}
{% load wagtailcore_tags %}
{% load has_user_annotations %}
{% load user_annotation_count %}
{% load sass_tags %}
{% load has_user_annotations readux_templatetags sass_tags static user_annotation_count wagtailcore_tags wagtailimages_tags %}

{% block extra_css %}
{% endblock %}

{% block content %}

{% if request.path == '/' %}
<div class="landing">
<div class="landing"{% if page.background_image %}
{% image page.background_image scale-100 as bgimg %}
style="background: url({{ bgimg.url }}) no-repeat center center fixed; background-size: cover;"
{% endif %} >
<div class="overlay"></div>
<div class="content">
{% include '_home/_nav.html' %}
Expand Down

0 comments on commit 209b259

Please sign in to comment.