From 6fb084a3c82627f8dd723adb6db0384b915de7ad Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 16 Dec 2016 18:36:42 +0000 Subject: [PATCH] normalise images / metadata and add post date --- .../migrations/0002_auto_20161216_1753.py | 24 ++++++++++++++ .../migrations/0003_auto_20161216_1822.py | 24 ++++++++++++++ project/blog/models.py | 14 -------- project/common/models.py | 23 +++++++++++++ .../home/migrations/0002_homepage_image.py | 22 +++++++++++++ .../migrations/0003_homepage_post_date.py | 20 ++++++++++++ .../migrations/0002_auto_20161216_1753.py | 32 +++++++++++++++++++ .../migrations/0003_auto_20161216_1822.py | 25 +++++++++++++++ project/pages/models.py | 4 +-- .../migrations/0002_auto_20161216_1753.py | 24 ++++++++++++++ .../migrations/0003_projectpage_post_date.py | 20 ++++++++++++ project/projects/models.py | 11 ------- templates/common/header.html | 6 ++-- 13 files changed, 219 insertions(+), 30 deletions(-) create mode 100644 project/blog/migrations/0002_auto_20161216_1753.py create mode 100644 project/blog/migrations/0003_auto_20161216_1822.py create mode 100644 project/home/migrations/0002_homepage_image.py create mode 100644 project/home/migrations/0003_homepage_post_date.py create mode 100644 project/pages/migrations/0002_auto_20161216_1753.py create mode 100644 project/pages/migrations/0003_auto_20161216_1822.py create mode 100644 project/projects/migrations/0002_auto_20161216_1753.py create mode 100644 project/projects/migrations/0003_projectpage_post_date.py diff --git a/project/blog/migrations/0002_auto_20161216_1753.py b/project/blog/migrations/0002_auto_20161216_1753.py new file mode 100644 index 0000000..64ff8ff --- /dev/null +++ b/project/blog/migrations/0002_auto_20161216_1753.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 17:53 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='blogpage', + old_name='main_image', + new_name='image', + ), + migrations.RemoveField( + model_name='blogpage', + name='intro', + ), + ] diff --git a/project/blog/migrations/0003_auto_20161216_1822.py b/project/blog/migrations/0003_auto_20161216_1822.py new file mode 100644 index 0000000..15052de --- /dev/null +++ b/project/blog/migrations/0003_auto_20161216_1822.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 18:22 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0002_auto_20161216_1753'), + ] + + operations = [ + migrations.RemoveField( + model_name='blogpage', + name='date', + ), + migrations.AddField( + model_name='blogpage', + name='post_date', + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/project/blog/models.py b/project/blog/models.py index 7756e7d..8537df9 100644 --- a/project/blog/models.py +++ b/project/blog/models.py @@ -2,32 +2,18 @@ from django.db import models from project.common.blocks import build_stream_field from wagtail.wagtailcore.models import Page from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel -from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index from project.common.models import Entity class BlogPage(Entity): - main_image = models.ForeignKey( - 'wagtailimages.Image', - null=True, - blank=True, - on_delete=models.SET_NULL, - related_name='+' - ) - date = models.DateField("Post date") - intro = models.CharField(max_length=250) body = build_stream_field() search_fields = Page.search_fields + [ - index.SearchField('intro'), index.SearchField('body'), ] content_panels = Page.content_panels + [ - FieldPanel('date'), - ImageChooserPanel('main_image'), - FieldPanel('intro'), StreamFieldPanel('body'), ] diff --git a/project/common/models.py b/project/common/models.py index fb26ccd..3fe2440 100644 --- a/project/common/models.py +++ b/project/common/models.py @@ -1,5 +1,7 @@ from wagtail.wagtailcore.models import Page from django.db import models +from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin @@ -8,6 +10,27 @@ class Entity(MetadataPageMixin, Page): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) + post_date = models.DateTimeField(null=True, blank=True) + image = models.ForeignKey( + 'wagtailimages.Image', + null=True, + blank=True, + related_name='+', + on_delete=models.SET_NULL + ) + + promote_panels = [ + MultiFieldPanel([ + FieldPanel('slug'), + FieldPanel('seo_title'), + FieldPanel('post_date'), + FieldPanel('search_description'), + ImageChooserPanel('image'), + ], 'Common page configuration'), + ] + + def get_meta_image(self): + return self.image class Meta: abstract = True diff --git a/project/home/migrations/0002_homepage_image.py b/project/home/migrations/0002_homepage_image.py new file mode 100644 index 0000000..268e84c --- /dev/null +++ b/project/home/migrations/0002_homepage_image.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 17:53 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0015_fill_filter_spec_field'), + ('home', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='homepage', + name='image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'), + ), + ] diff --git a/project/home/migrations/0003_homepage_post_date.py b/project/home/migrations/0003_homepage_post_date.py new file mode 100644 index 0000000..ae14dea --- /dev/null +++ b/project/home/migrations/0003_homepage_post_date.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 18:22 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('home', '0002_homepage_image'), + ] + + operations = [ + migrations.AddField( + model_name='homepage', + name='post_date', + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/project/pages/migrations/0002_auto_20161216_1753.py b/project/pages/migrations/0002_auto_20161216_1753.py new file mode 100644 index 0000000..5a68c8c --- /dev/null +++ b/project/pages/migrations/0002_auto_20161216_1753.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 17:53 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0015_fill_filter_spec_field'), + ('pages', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='sectionindexpage', + old_name='intro', + new_name='body', + ), + migrations.AddField( + model_name='sectionindexpage', + name='image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'), + ), + migrations.AddField( + model_name='simplecontentpage', + name='image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'), + ), + ] diff --git a/project/pages/migrations/0003_auto_20161216_1822.py b/project/pages/migrations/0003_auto_20161216_1822.py new file mode 100644 index 0000000..46b3c22 --- /dev/null +++ b/project/pages/migrations/0003_auto_20161216_1822.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 18:22 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('pages', '0002_auto_20161216_1753'), + ] + + operations = [ + migrations.AddField( + model_name='sectionindexpage', + name='post_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AddField( + model_name='simplecontentpage', + name='post_date', + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/project/pages/models.py b/project/pages/models.py index 59ceb3c..8b6a536 100644 --- a/project/pages/models.py +++ b/project/pages/models.py @@ -15,10 +15,10 @@ class SimpleContentPage(Entity): class SectionIndexPage(Entity): - intro = RichTextField(blank=True) + body = RichTextField(blank=True) hide_list = models.BooleanField(default=False) content_panels = Page.content_panels + [ - FieldPanel('intro', classname="full"), + FieldPanel('body', classname="full"), FieldPanel('hide_list') ] diff --git a/project/projects/migrations/0002_auto_20161216_1753.py b/project/projects/migrations/0002_auto_20161216_1753.py new file mode 100644 index 0000000..04236a6 --- /dev/null +++ b/project/projects/migrations/0002_auto_20161216_1753.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 17:53 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='projectpage', + old_name='main_image', + new_name='image', + ), + migrations.RemoveField( + model_name='projectpage', + name='summary', + ), + ] diff --git a/project/projects/migrations/0003_projectpage_post_date.py b/project/projects/migrations/0003_projectpage_post_date.py new file mode 100644 index 0000000..68ed713 --- /dev/null +++ b/project/projects/migrations/0003_projectpage_post_date.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-16 18:22 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0002_auto_20161216_1753'), + ] + + operations = [ + migrations.AddField( + model_name='projectpage', + name='post_date', + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/project/projects/models.py b/project/projects/models.py index 5a03170..8b7d9bf 100644 --- a/project/projects/models.py +++ b/project/projects/models.py @@ -4,7 +4,6 @@ from project.common.blocks import build_stream_field from wagtail.wagtailcore.models import Page from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel -from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index from project.common.models import Entity @@ -22,14 +21,6 @@ def validate_url(value): class ProjectPage(Entity): - main_image = models.ForeignKey( - 'wagtailimages.Image', - null=True, - blank=True, - on_delete=models.SET_NULL, - related_name='+' - ) - summary = models.CharField(max_length=500) body = build_stream_field() project_url = models.URLField(validators=[validate_url], blank=True) download_url = models.URLField(validators=[validate_url], blank=True) @@ -49,8 +40,6 @@ class ProjectPage(Entity): ] content_panels = Page.content_panels + [ - ImageChooserPanel('main_image'), - FieldPanel('summary'), StreamFieldPanel('body'), FieldPanel('download_url'), FieldPanel('project_url'), diff --git a/templates/common/header.html b/templates/common/header.html index 9cb8abd..d29dcf0 100644 --- a/templates/common/header.html +++ b/templates/common/header.html @@ -1,10 +1,10 @@ {% load wagtailimages_tags %} -{% image page.main_image original as main_image %} +{% image page.image original as header_image %} -