ソースを参照

Merge pull request #47 from wagtail/41-abstract-base-page

Create abstract base class for common fields
Scot Hacker 8 年 前
コミット
dc93606135

+ 31 - 0
bakerydemo/base/migrations/0009_auto_20170218_1114.py

@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-18 11:14
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0008_auto_20170211_2232'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='aboutpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='About image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='gallerypage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Listing image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='homepage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Homepage image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+    ]

+ 21 - 0
bakerydemo/base/migrations/0010_auto_20170218_1119.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-18 11:19
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0009_auto_20170218_1114'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='gallerypage',
+            name='choices',
+            field=models.ForeignKey(blank=True, help_text='Select the image collection for this gallery.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='wagtailcore.Collection'),
+        ),
+    ]

+ 26 - 0
bakerydemo/base/migrations/0011_auto_20170220_0111.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-20 01:11
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0010_auto_20170218_1119'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='gallerypage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='gallerypage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+    ]

+ 31 - 19
bakerydemo/base/models.py

@@ -21,6 +21,31 @@ from wagtail.wagtailsnippets.models import register_snippet
 from .blocks import BaseStreamBlock
 from .blocks import BaseStreamBlock
 
 
 
 
+class BasePageFieldsMixin(models.Model):
+    """
+    An abstract base class for common fields
+    """
+    introduction = models.TextField(
+        help_text='Text to describe the page',
+        blank=True)
+    image = models.ForeignKey(
+        'wagtailimages.Image',
+        null=True,
+        blank=True,
+        on_delete=models.SET_NULL,
+        related_name='+',
+        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
+    )
+
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction', classname="full"),
+        ImageChooserPanel('image'),
+    ]
+
+    class Meta:
+        abstract = True
+
+
 @register_snippet
 @register_snippet
 class People(ClusterableModel):
 class People(ClusterableModel):
     """
     """
@@ -113,7 +138,7 @@ class AboutPage(Page):
         blank=True,
         blank=True,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name='+',
         related_name='+',
-        help_text='Location image'
+        help_text='About image'
     )
     )
 
 
     body = StreamField(
     body = StreamField(
@@ -156,7 +181,7 @@ class HomePage(Page):
         blank=True,
         blank=True,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name='+',
         related_name='+',
-        help_text='Location image'
+        help_text='Homepage image'
     )
     )
 
 
     body = StreamField(
     body = StreamField(
@@ -172,9 +197,9 @@ class HomePage(Page):
         return self.title
         return self.title
 
 
 
 
-class GalleryPage(Page):
+class GalleryPage(BasePageFieldsMixin, Page):
     """
     """
-    This is a page to list all the locations on the site
+    This is a page to list locations from the selected Collection
     """
     """
     choices = models.ForeignKey(
     choices = models.ForeignKey(
         Collection,
         Collection,
@@ -182,24 +207,11 @@ class GalleryPage(Page):
         null=True,
         null=True,
         blank=True,
         blank=True,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
-    )
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+',
-        help_text='Location listing image'
+        help_text='Select the image collection for this gallery.'
     )
     )
 
 
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
-
-    content_panels = Page.content_panels + [
+    content_panels = BasePageFieldsMixin.content_panels + [
         FieldPanel('choices'),
         FieldPanel('choices'),
-        ImageChooserPanel('image'),
-        FieldPanel('introduction')
     ]
     ]
 
 
     # parent_page_types = [
     # parent_page_types = [

+ 21 - 0
bakerydemo/blog/migrations/0004_auto_20170218_1103.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-18 11:03
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('blog', '0003_auto_20170211_2120'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='blogindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Listing image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+    ]

+ 36 - 0
bakerydemo/blog/migrations/0005_auto_20170220_0111.py

@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-20 01:11
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('blog', '0004_auto_20170218_1103'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='blogindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='blogindexpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+        migrations.AlterField(
+            model_name='blogpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='blogpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+    ]

+ 8 - 40
bakerydemo/blog/models.py

@@ -11,15 +11,15 @@ from taggit.models import Tag, TaggedItemBase
 
 
 from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
 from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
 from wagtail.wagtailadmin.edit_handlers import (
 from wagtail.wagtailadmin.edit_handlers import (
-    FieldPanel, InlinePanel, StreamFieldPanel, MultiFieldPanel
+    FieldPanel, InlinePanel, StreamFieldPanel
 )
 )
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.models import Page, Orderable
 from wagtail.wagtailcore.models import Page, Orderable
-from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
 from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
 
 
 from bakerydemo.base.blocks import BaseStreamBlock
 from bakerydemo.base.blocks import BaseStreamBlock
+from bakerydemo.base.models import BasePageFieldsMixin
 
 
 
 
 class BlogPeopleRelationship(Orderable, models.Model):
 class BlogPeopleRelationship(Orderable, models.Model):
@@ -42,35 +42,18 @@ class BlogPageTag(TaggedItemBase):
     content_object = ParentalKey('BlogPage', related_name='tagged_items')
     content_object = ParentalKey('BlogPage', related_name='tagged_items')
 
 
 
 
-class BlogPage(Page):
+class BlogPage(BasePageFieldsMixin, Page):
     """
     """
     A Blog Page (Post)
     A Blog Page (Post)
     """
     """
     subtitle = models.CharField(blank=True, max_length=255)
     subtitle = models.CharField(blank=True, max_length=255)
-    introduction = models.CharField(blank=True, max_length=255)
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+',
-        help_text='Location image'
-    )
-
     tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
     tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
-
     date_published = models.DateField("Date article published", blank=True, null=True)
     date_published = models.DateField("Date article published", blank=True, null=True)
-
     body = StreamField(
     body = StreamField(
         BaseStreamBlock(), verbose_name="Blog post", blank=True
         BaseStreamBlock(), verbose_name="Blog post", blank=True
     )
     )
 
 
-    content_panels = Page.content_panels + [
-        MultiFieldPanel([
-            FieldPanel('subtitle'),
-            FieldPanel('introduction'),
-        ]),
-        ImageChooserPanel('image'),
+    content_panels = BasePageFieldsMixin.content_panels + [
         StreamFieldPanel('body'),
         StreamFieldPanel('body'),
         FieldPanel('date_published'),
         FieldPanel('date_published'),
         InlinePanel(
         InlinePanel(
@@ -78,6 +61,9 @@ class BlogPage(Page):
             panels=None, min_num=1),
             panels=None, min_num=1),
         FieldPanel('tags'),
         FieldPanel('tags'),
     ]
     ]
+    # Inject subtitle panel after title field
+    title_index = next((i for i, panel in enumerate(content_panels) if panel.field_name == 'title'), -1)  # noqa
+    content_panels.insert(title_index + 1, FieldPanel('subtitle'))
 
 
     search_fields = Page.search_fields + [
     search_fields = Page.search_fields + [
         index.SearchField('title'),
         index.SearchField('title'),
@@ -116,7 +102,7 @@ class BlogPage(Page):
     subpage_types = []
     subpage_types = []
 
 
 
 
-class BlogIndexPage(RoutablePageMixin, Page):
+class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
     """
     """
     Index page for blogs.
     Index page for blogs.
     We need to alter the page model's context to return the child page objects - the
     We need to alter the page model's context to return the child page objects - the
@@ -125,24 +111,6 @@ class BlogIndexPage(RoutablePageMixin, Page):
     RoutablePageMixin is used to allow for a custom sub-URL for tag views.
     RoutablePageMixin is used to allow for a custom sub-URL for tag views.
     """
     """
 
 
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+',
-        help_text='Location listing image'
-    )
-
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
-
-    content_panels = Page.content_panels + [
-        ImageChooserPanel('image'),
-        FieldPanel('introduction')
-    ]
-
     # What pages types can live under this page type?
     # What pages types can live under this page type?
     subpage_types = ['BlogPage']
     subpage_types = ['BlogPage']
 
 

+ 21 - 0
bakerydemo/breads/migrations/0003_auto_20170218_1102.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-18 11:02
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('breads', '0002_auto_20170217_0853'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='breadsindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Listing image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+    ]

+ 44 - 0
bakerydemo/breads/migrations/0004_auto_20170220_0111.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-20 01:11
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import wagtail.wagtailcore.blocks
+import wagtail.wagtailcore.fields
+import wagtail.wagtailembeds.blocks
+import wagtail.wagtailimages.blocks
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('breads', '0003_auto_20170218_1102'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='breadpage',
+            name='description',
+        ),
+        migrations.AddField(
+            model_name='breadpage',
+            name='body',
+            field=wagtail.wagtailcore.fields.StreamField((('heading_block', wagtail.wagtailcore.blocks.StructBlock((('heading_text', wagtail.wagtailcore.blocks.CharBlock(classname='title', required=True)), ('size', wagtail.wagtailcore.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a header size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))))), ('paragraph_block', wagtail.wagtailcore.blocks.RichTextBlock(icon='fa-paragraph', template='blocks/paragraph_block.html')), ('image_block', wagtail.wagtailcore.blocks.StructBlock((('image', wagtail.wagtailimages.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.wagtailcore.blocks.CharBlock(required=False)), ('attribution', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('block_quote', wagtail.wagtailcore.blocks.StructBlock((('text', wagtail.wagtailcore.blocks.TextBlock()), ('attribute_name', wagtail.wagtailcore.blocks.CharBlock(blank=True, label='e.g. Guy Picciotto', required=False))))), ('embed_block', wagtail.wagtailembeds.blocks.EmbedBlock(help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='fa-s15', template='blocks/embed_block.html'))), blank=True, verbose_name='Describe the bread'),
+        ),
+        migrations.AddField(
+            model_name='breadpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+        migrations.AlterField(
+            model_name='breadsindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='breadsindexpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+    ]

+ 12 - 38
bakerydemo/breads/models.py

@@ -1,14 +1,15 @@
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.db import models
 from django.db import models
 
 
 from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
 from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.models import Page
 from wagtail.wagtailcore.models import Page
 
 
-from wagtail.wagtailcore import blocks
-from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsnippets.models import register_snippet
 from wagtail.wagtailsnippets.models import register_snippet
-from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+
+from bakerydemo.base.blocks import BaseStreamBlock
+from bakerydemo.base.models import BasePageFieldsMixin
 
 
 
 
 @register_snippet
 @register_snippet
@@ -46,7 +47,7 @@ class BreadType(models.Model):
         verbose_name_plural = "Bread types"
         verbose_name_plural = "Bread types"
 
 
 
 
-class BreadPage(Page):
+class BreadPage(BasePageFieldsMixin, Page):
     """
     """
     Detail view for a specific bread
     Detail view for a specific bread
     """
     """
@@ -57,10 +58,9 @@ class BreadPage(Page):
         null=True,
         null=True,
         blank=True,
         blank=True,
     )
     )
-    description = StreamField([
-        ('heading', blocks.CharBlock(classname="full title")),
-        ('paragraph', blocks.RichTextBlock()),
-    ])
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Describe the bread", blank=True
+    )
     bread_type = models.ForeignKey(
     bread_type = models.ForeignKey(
         'breads.BreadType',
         'breads.BreadType',
         null=True,
         null=True,
@@ -68,26 +68,16 @@ class BreadPage(Page):
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
         related_name='+'
         related_name='+'
     )
     )
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        on_delete=models.SET_NULL,
-        null=True,
-        blank=True,
-        related_name='+',
-        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
-    )
 
 
-    content_panels = [
-        FieldPanel('title'),
+    content_panels = BasePageFieldsMixin.content_panels + [
+        StreamFieldPanel('body'),
         FieldPanel('origin'),
         FieldPanel('origin'),
         FieldPanel('bread_type'),
         FieldPanel('bread_type'),
-        ImageChooserPanel('image'),
-        StreamFieldPanel('description'),
     ]
     ]
 
 
     search_fields = Page.search_fields + [
     search_fields = Page.search_fields + [
         index.SearchField('title'),
         index.SearchField('title'),
-        index.SearchField('description'),
+        index.SearchField('body'),
     ]
     ]
 
 
     parent_page_types = ['BreadsIndexPage']
     parent_page_types = ['BreadsIndexPage']
@@ -95,31 +85,15 @@ class BreadPage(Page):
     api_fields = ['title', 'bread_type', 'origin', 'image']
     api_fields = ['title', 'bread_type', 'origin', 'image']
 
 
 
 
-class BreadsIndexPage(Page):
+class BreadsIndexPage(BasePageFieldsMixin, Page):
     """
     """
     Index page for breads. We don't have any fields within our model but we need
     Index page for breads. We don't have any fields within our model but we need
     to alter the page model's context to return the child page objects - the
     to alter the page model's context to return the child page objects - the
     BreadPage - so that it works as an index page
     BreadPage - so that it works as an index page
     """
     """
 
 
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+',
-        help_text='Location listing image'
-    )
     subpage_types = ['BreadPage']
     subpage_types = ['BreadPage']
 
 
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction'),
-        ImageChooserPanel('image'),
-    ]
-
     def get_context(self, request):
     def get_context(self, request):
         context = super(BreadsIndexPage, self).get_context(request)
         context = super(BreadsIndexPage, self).get_context(request)
 
 

+ 21 - 0
bakerydemo/locations/migrations/0006_auto_20170218_1102.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-18 11:02
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0005_locationsindexpage_introduction'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='locationsindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Listing image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+    ]

+ 16 - 0
bakerydemo/locations/migrations/0010_merge_20170220_0111.py

@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-20 01:11
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0009_auto_20170219_0942'),
+        ('locations', '0006_auto_20170218_1102'),
+    ]
+
+    operations = [
+    ]

+ 36 - 0
bakerydemo/locations/migrations/0011_auto_20170220_0111.py

@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-20 01:11
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0010_merge_20170220_0111'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='locationpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='locationpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+        migrations.AlterField(
+            model_name='locationsindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AlterField(
+            model_name='locationsindexpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the page'),
+        ),
+    ]

+ 15 - 38
bakerydemo/locations/models.py

@@ -11,12 +11,10 @@ from wagtail.wagtailadmin.edit_handlers import (
     InlinePanel,
     InlinePanel,
     StreamFieldPanel)
     StreamFieldPanel)
 from wagtail.wagtailcore.models import Orderable, Page
 from wagtail.wagtailcore.models import Orderable, Page
-from wagtail.wagtailimages.edit_handlers import (
-    ImageChooserPanel,
-    )
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsearch import index
 
 
+from bakerydemo.base.models import BasePageFieldsMixin
 from bakerydemo.base.blocks import BaseStreamBlock
 from bakerydemo.base.blocks import BaseStreamBlock
 
 
 
 
@@ -57,7 +55,7 @@ class OperatingHours(models.Model):
         "Closed?",
         "Closed?",
         blank=True,
         blank=True,
         help_text='Tick if location is closed on this day'
         help_text='Tick if location is closed on this day'
-        )
+    )
 
 
     panels = [
     panels = [
         FieldPanel('day'),
         FieldPanel('day'),
@@ -70,10 +68,18 @@ class OperatingHours(models.Model):
         abstract = True
         abstract = True
 
 
     def __str__(self):
     def __str__(self):
+        if self.opening_time:
+            opening = self.opening_time.strftime('%H:%M')
+        else:
+            opening = '--'
+        if self.closing_time:
+            closed = self.opening_time.strftime('%H:%M')
+        else:
+            closed = '--'
         return '{}: {} - {} {}'.format(
         return '{}: {} - {} {}'.format(
             self.day,
             self.day,
-            self.opening_time.strftime('%H:%M'),
-            self.closing_time.strftime('%H:%M'),
+            opening,
+            closed,
             settings.TIME_ZONE
             settings.TIME_ZONE
         )
         )
 
 
@@ -88,29 +94,12 @@ class LocationOperatingHours(Orderable, OperatingHours):
     )
     )
 
 
 
 
-class LocationsIndexPage(Page):
+class LocationsIndexPage(BasePageFieldsMixin, Page):
     """
     """
     Index page for locations
     Index page for locations
     """
     """
-
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+',
-        help_text='Location listing image'
-    )
     subpage_types = ['LocationPage']
     subpage_types = ['LocationPage']
 
 
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction'),
-        ImageChooserPanel('image'),
-    ]
-
     def get_context(self, request):
     def get_context(self, request):
         context = super(LocationsIndexPage, self).get_context(request)
         context = super(LocationsIndexPage, self).get_context(request)
         context['locations'] = LocationPage.objects.descendant_of(
         context['locations'] = LocationPage.objects.descendant_of(
@@ -119,21 +108,11 @@ class LocationsIndexPage(Page):
         return context
         return context
 
 
 
 
-class LocationPage(Page):
+class LocationPage(BasePageFieldsMixin, Page):
     """
     """
     Detail for a specific bakery location.
     Detail for a specific bakery location.
     """
     """
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
     address = models.TextField()
     address = models.TextField()
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+'
-    )
     lat_long = models.CharField(
     lat_long = models.CharField(
         max_length=36,
         max_length=36,
         help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
         help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
@@ -160,12 +139,10 @@ class LocationPage(Page):
     ]
     ]
 
 
     # Editor panels configuration
     # Editor panels configuration
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction', classname="full"),
+    content_panels = BasePageFieldsMixin.content_panels + [
         StreamFieldPanel('body'),
         StreamFieldPanel('body'),
         FieldPanel('address', classname="full"),
         FieldPanel('address', classname="full"),
         FieldPanel('lat_long'),
         FieldPanel('lat_long'),
-        ImageChooserPanel('image'),
         InlinePanel('hours_of_operation', label="Hours of Operation"),
         InlinePanel('hours_of_operation', label="Hours of Operation"),
     ]
     ]
 
 

+ 1 - 1
bakerydemo/templates/breads/bread_page.html

@@ -9,5 +9,5 @@
 
 
     <p>{{ page.origin }}</p>
     <p>{{ page.origin }}</p>
     <p>{{ page.bread_type }}</p>
     <p>{{ page.bread_type }}</p>
-    {{ page.description }}
+    {{ page.body }}
 {% endblock content %}
 {% endblock content %}

+ 3 - 4
bakerydemo/templates/locations/locations_index_page.html

@@ -17,13 +17,12 @@
             <div class="col-md-6 location-list-item">
             <div class="col-md-6 location-list-item">
                 <a href="{% pageurl location %}">
                 <a href="{% pageurl location %}">
                 <h1 class="location-list-title">
                 <h1 class="location-list-title">
-                
-        
+
                     {% image location.image fill-660x270-c75 as image %}
                     {% image location.image fill-660x270-c75 as image %}
                     <img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.alt }}" class="" />
                     <img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}" alt="{{ image.alt }}" class="" />
-                    
+
                     <span class="title">{{ location.title }}</span>
                     <span class="title">{{ location.title }}</span>
-                
+
                 </h1></a>
                 </h1></a>
                     <address>{{ location.address }}</address>
                     <address>{{ location.address }}</address>
                     <a href="https://google.com/maps/?q={{ location.lat_long }}" class="btn">Map</a>
                     <a href="https://google.com/maps/?q={{ location.lat_long }}" class="btn">Map</a>