From 8df2d053056bc852de24afc2e90881567a0c9e5e Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Fri, 5 Jan 2018 15:21:43 +0000 Subject: [PATCH] Add the optional header image to all pages --- .../migrations/0002_formpage_header_image.py | 22 +++++++++++++++ opentech/forms/models.py | 5 ++-- .../migrations/0003_homepage_header_image.py | 22 +++++++++++++++ opentech/home/models.py | 5 ++-- .../news/migrations/0002_add_header_image.py | 27 +++++++++++++++++++ opentech/news/models.py | 5 ++-- .../migrations/0002_add_header_image.py | 27 +++++++++++++++++++ opentech/people/models.py | 3 +-- .../migrations/0002_add_header_image.py | 27 +++++++++++++++++++ opentech/standardpages/models.py | 9 +++---- opentech/templates/base.html | 4 +-- opentech/utils/models.py | 13 +++++++++ 12 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 opentech/forms/migrations/0002_formpage_header_image.py create mode 100644 opentech/home/migrations/0003_homepage_header_image.py create mode 100644 opentech/news/migrations/0002_add_header_image.py create mode 100644 opentech/people/migrations/0002_add_header_image.py create mode 100644 opentech/standardpages/migrations/0002_add_header_image.py diff --git a/opentech/forms/migrations/0002_formpage_header_image.py b/opentech/forms/migrations/0002_formpage_header_image.py new file mode 100644 index 000000000..2bd9e0202 --- /dev/null +++ b/opentech/forms/migrations/0002_formpage_header_image.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-05 15:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ('forms', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='formpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + ] diff --git a/opentech/forms/models.py b/opentech/forms/models.py index baceb3b6b..0ca50f6cd 100644 --- a/opentech/forms/models.py +++ b/opentech/forms/models.py @@ -2,7 +2,6 @@ from django.db import models from modelcluster.fields import ParentalKey -from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import RichTextField from wagtail.wagtailadmin.edit_handlers import ( FieldPanel, FieldRowPanel, @@ -27,11 +26,11 @@ class FormPage(WagtailCaptchaEmailForm, BasePage): thank_you_text = RichTextField(blank=True, help_text="Text displayed to the user on successful submission of the form") action_text = models.CharField(max_length=32, blank=True, help_text="Form action text. Defaults to \"Submit\"") - search_fields = Page.search_fields + [ + search_fields = BasePage.search_fields + [ index.SearchField('introduction'), ] - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ FieldPanel('introduction'), InlinePanel('form_fields', label="Form fields"), FieldPanel('action_text'), diff --git a/opentech/home/migrations/0003_homepage_header_image.py b/opentech/home/migrations/0003_homepage_header_image.py new file mode 100644 index 000000000..8059999f9 --- /dev/null +++ b/opentech/home/migrations/0003_homepage_header_image.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-05 15:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ('home', '0002_create_homepage'), + ] + + operations = [ + migrations.AddField( + model_name='homepage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + ] diff --git a/opentech/home/models.py b/opentech/home/models.py index 66b29108b..f99f2b6e5 100644 --- a/opentech/home/models.py +++ b/opentech/home/models.py @@ -1,7 +1,6 @@ from django.db import models from wagtail.wagtailadmin.edit_handlers import FieldPanel -from wagtail.wagtailcore.models import Page from wagtail.wagtailsearch import index from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel @@ -15,11 +14,11 @@ class HomePage(BasePage): strapline = models.CharField(blank=True, max_length=255) call_to_action = models.ForeignKey('utils.CallToActionSnippet', blank=True, null=True, on_delete=models.SET_NULL, related_name='+') - search_fields = Page.search_fields + [ + search_fields = BasePage.search_fields + [ index.SearchField('strapline'), ] - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ FieldPanel('strapline'), SnippetChooserPanel('call_to_action'), ] diff --git a/opentech/news/migrations/0002_add_header_image.py b/opentech/news/migrations/0002_add_header_image.py new file mode 100644 index 000000000..1cce5bc5f --- /dev/null +++ b/opentech/news/migrations/0002_add_header_image.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-05 15:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ('news', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='newsindex', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + migrations.AddField( + model_name='newspage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + ] diff --git a/opentech/news/models.py b/opentech/news/models.py index 4dae687ff..978efefa0 100644 --- a/opentech/news/models.py +++ b/opentech/news/models.py @@ -5,7 +5,6 @@ from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from modelcluster.fields import ParentalKey -from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import StreamField from wagtail.wagtailadmin.edit_handlers import ( StreamFieldPanel, FieldPanel, InlinePanel @@ -62,12 +61,12 @@ class NewsPage(BasePage): introduction = models.TextField(blank=True) body = StreamField(StoryBlock()) - search_fields = Page.search_fields + [ + search_fields = BasePage.search_fields + [ index.SearchField('introduction'), index.SearchField('body') ] - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ FieldPanel('publication_date'), FieldPanel('introduction'), StreamFieldPanel('body'), diff --git a/opentech/people/migrations/0002_add_header_image.py b/opentech/people/migrations/0002_add_header_image.py new file mode 100644 index 000000000..ead04a815 --- /dev/null +++ b/opentech/people/migrations/0002_add_header_image.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-05 15:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ('people', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='personindexpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + migrations.AddField( + model_name='personpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + ] diff --git a/opentech/people/models.py b/opentech/people/models.py index 2f99acbeb..af91d665a 100644 --- a/opentech/people/models.py +++ b/opentech/people/models.py @@ -5,7 +5,6 @@ from django.conf import settings from modelcluster.fields import ParentalKey -from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import StreamField from wagtail.wagtailadmin.edit_handlers import ( FieldPanel, @@ -97,7 +96,7 @@ class PersonPage(BasePage): biography = StreamField(StoryBlock(), blank=True) email = models.EmailField(blank=True) - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ MultiFieldPanel([ FieldPanel('first_name'), FieldPanel('last_name'), diff --git a/opentech/standardpages/migrations/0002_add_header_image.py b/opentech/standardpages/migrations/0002_add_header_image.py new file mode 100644 index 000000000..25aede1e6 --- /dev/null +++ b/opentech/standardpages/migrations/0002_add_header_image.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-01-05 15:03 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('images', '0001_initial'), + ('standardpages', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='indexpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + migrations.AddField( + model_name='informationpage', + name='header_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'), + ), + ] diff --git a/opentech/standardpages/models.py b/opentech/standardpages/models.py index 5f206e1f8..754aa1fca 100644 --- a/opentech/standardpages/models.py +++ b/opentech/standardpages/models.py @@ -9,7 +9,6 @@ from wagtail.wagtailadmin.edit_handlers import ( ) from wagtail.wagtailcore.fields import StreamField -from wagtail.wagtailcore.models import Page from wagtail.wagtailsearch import index from opentech.utils.blocks import StoryBlock @@ -27,12 +26,12 @@ class InformationPage(BasePage): introduction = models.TextField(blank=True) body = StreamField(StoryBlock()) - search_fields = Page.search_fields + [ + search_fields = BasePage.search_fields + [ index.SearchField('introduction'), index.SearchField('body'), ] - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ FieldPanel('introduction'), StreamFieldPanel('body'), InlinePanel('related_pages', label="Related pages"), @@ -42,11 +41,11 @@ class InformationPage(BasePage): class IndexPage(BasePage): introduction = models.TextField(blank=True) - content_panels = Page.content_panels + [ + content_panels = BasePage.content_panels + [ FieldPanel('introduction'), ] - search_fields = Page.search_fields + [ + search_fields = BasePage.search_fields + [ index.SearchField('introduction'), ] diff --git a/opentech/templates/base.html b/opentech/templates/base.html index 137faddc1..691d4eafc 100644 --- a/opentech/templates/base.html +++ b/opentech/templates/base.html @@ -69,7 +69,8 @@ {% wagtailuserbar %} {# {% if page.header_image %} #} - <!-- <header class="header header--standard header--has-bg-image" style="background-image:url('')"> --> + {% image page.header_image original as header_image %} + <header class="header header--standard header--has-bg-image" style="background-image:url('{{ header_image.url }}')"> {# {% else %} #} <header class="header header--standard"> {# {% endif %} #} @@ -167,4 +168,3 @@ {% block extra_js %}{% endblock %} </body> </html> - diff --git a/opentech/utils/models.py b/opentech/utils/models.py index 07ff50bc2..e863bc647 100644 --- a/opentech/utils/models.py +++ b/opentech/utils/models.py @@ -239,9 +239,22 @@ class SystemMessagesSettings(BaseSetting): class BasePage(SocialFields, ListingFields, Page): show_in_menus_default = True + header_image = models.ForeignKey( + 'images.CustomImage', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + class Meta: abstract = True + + content_panels = Page.content_panels + [ + ImageChooserPanel('header_image') + ] + promote_panels = ( Page.promote_panels + SocialFields.promote_panels + -- GitLab