Browse Source

Merge pull request #119 from wagtail/118_nobasepagefieldmixin

Remove BasePageFieldsMixin
Edd Baldry 8 years ago
parent
commit
998d5f4c02

+ 44 - 39
bakerydemo/base/models.py

@@ -18,35 +18,6 @@ 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.'
-    )
-    body = StreamField(
-        BaseStreamBlock(), verbose_name="Page body", blank=True
-    )
-
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction', classname="full"),
-        ImageChooserPanel('image'),
-        StreamFieldPanel('body'),
-    ]
-
-    class Meta:
-        abstract = True
-
-
 @register_snippet
 @register_snippet
 class People(ClusterableModel):
 class People(ClusterableModel):
     """
     """
@@ -112,14 +83,30 @@ class FooterText(models.Model):
         verbose_name_plural = 'Footer Text'
         verbose_name_plural = 'Footer Text'
 
 
 
 
-class StandardPage(Page, BasePageFieldsMixin):
+class StandardPage(Page):
     """
     """
     A fairly generic site page, to be used for About, etc.
     A fairly generic site page, to be used for About, etc.
-    Defines no fields of its own - just a wrapper for the fields defined in BasePageFieldsMixin.
     """
     """
 
 
-    # Inherit the content panels from BasePageFieldsMixin
-    content_panels = BasePageFieldsMixin.content_panels + []
+    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.'
+    )
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Page body", blank=True
+    )
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction', classname="full"),
+        StreamFieldPanel('body'),
+        ImageChooserPanel('image'),
+    ]
 
 
 
 
 class HomePage(Page):
 class HomePage(Page):
@@ -235,10 +222,10 @@ class HomePage(Page):
                 ])
                 ])
             ], heading="Hero section"),
             ], heading="Hero section"),
         MultiFieldPanel([
         MultiFieldPanel([
-                ImageChooserPanel('promo_image'),
-                FieldPanel('promo_title'),
-                FieldPanel('promo_text'),
-            ], heading="Promo section"),
+            ImageChooserPanel('promo_image'),
+            FieldPanel('promo_title'),
+            FieldPanel('promo_text'),
+        ], heading="Promo section"),
         StreamFieldPanel('body'),
         StreamFieldPanel('body'),
         MultiFieldPanel([
         MultiFieldPanel([
             MultiFieldPanel([
             MultiFieldPanel([
@@ -260,10 +247,25 @@ class HomePage(Page):
         return self.title
         return self.title
 
 
 
 
-class GalleryPage(BasePageFieldsMixin, Page):
+class GalleryPage(Page):
     """
     """
     This is a page to list locations from the selected Collection
     This is a page to list locations from the selected Collection
     """
     """
+
+    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.'
+    )
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Page body", blank=True
+    )
     collection = models.ForeignKey(
     collection = models.ForeignKey(
         Collection,
         Collection,
         limit_choices_to=~models.Q(name__in=['Root']),
         limit_choices_to=~models.Q(name__in=['Root']),
@@ -273,7 +275,10 @@ class GalleryPage(BasePageFieldsMixin, Page):
         help_text='Select the image collection for this gallery.'
         help_text='Select the image collection for this gallery.'
     )
     )
 
 
-    content_panels = BasePageFieldsMixin.content_panels + [
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction', classname="full"),
+        StreamFieldPanel('body'),
+        ImageChooserPanel('image'),
         FieldPanel('collection'),
         FieldPanel('collection'),
     ]
     ]
 
 

+ 19 - 0
bakerydemo/blog/migrations/0002_remove_blogindexpage_body.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-03-26 22:25
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('blog', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='blogindexpage',
+            name='body',
+        ),
+    ]

+ 36 - 8
bakerydemo/blog/models.py

@@ -10,13 +10,14 @@ from modelcluster.fields import ParentalKey
 from taggit.models import Tag, TaggedItemBase
 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 FieldPanel, InlinePanel
+from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel, StreamFieldPanel
+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.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.models import BasePageFieldsMixin
+from bakerydemo.base.blocks import BaseStreamBlock
 
 
 
 
 class BlogPeopleRelationship(Orderable, models.Model):
 class BlogPeopleRelationship(Orderable, models.Model):
@@ -39,24 +40,39 @@ class BlogPageTag(TaggedItemBase):
     content_object = ParentalKey('BlogPage', related_name='tagged_items')
     content_object = ParentalKey('BlogPage', related_name='tagged_items')
 
 
 
 
-class BlogPage(BasePageFieldsMixin, Page):
+class BlogPage(Page):
     """
     """
     A Blog Page (Post)
     A Blog Page (Post)
     """
     """
+    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.'
+    )
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Page body", blank=True
+    )
     subtitle = models.CharField(blank=True, max_length=255)
     subtitle = models.CharField(blank=True, max_length=255)
     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)
 
 
-    content_panels = BasePageFieldsMixin.content_panels + [
+    content_panels = Page.content_panels + [
+        FieldPanel('subtitle', classname="full"),
+        FieldPanel('introduction', classname="full"),
+        ImageChooserPanel('image'),
+        StreamFieldPanel('body'),
         FieldPanel('date_published'),
         FieldPanel('date_published'),
         InlinePanel(
         InlinePanel(
             'blog_person_relationship', label="Author(s)",
             'blog_person_relationship', label="Author(s)",
             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'),
@@ -95,7 +111,7 @@ class BlogPage(BasePageFieldsMixin, Page):
     subpage_types = []
     subpage_types = []
 
 
 
 
-class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
+class BlogIndexPage(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
@@ -104,6 +120,18 @@ class BlogIndexPage(BasePageFieldsMixin, 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.
     """
     """
 
 
+    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.'
+    )
+
     # What pages types can live under this page type?
     # What pages types can live under this page type?
     subpage_types = ['BlogPage']
     subpage_types = ['BlogPage']
 
 

+ 19 - 0
bakerydemo/breads/migrations/0002_remove_breadsindexpage_body.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-03-26 22:25
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('breads', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='breadsindexpage',
+            name='body',
+        ),
+    ]

+ 34 - 6
bakerydemo/breads/models.py

@@ -4,13 +4,14 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 
 
 from modelcluster.fields import ParentalManyToManyField
 from modelcluster.fields import ParentalManyToManyField
 
 
-from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel
+from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, StreamFieldPanel
+from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.models import Page
 from wagtail.wagtailcore.models import Page
 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 wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 
 
-from bakerydemo.base.models import BasePageFieldsMixin
+from bakerydemo.base.blocks import BaseStreamBlock
 
 
 
 
 @register_snippet
 @register_snippet
@@ -67,11 +68,24 @@ class BreadType(models.Model):
         verbose_name_plural = "Bread types"
         verbose_name_plural = "Bread types"
 
 
 
 
-class BreadPage(BasePageFieldsMixin, Page):
+class BreadPage(Page):
     """
     """
     Detail view for a specific bread
     Detail view for a specific bread
     """
     """
-
+    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.'
+    )
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Page body", blank=True
+    )
     origin = models.ForeignKey(
     origin = models.ForeignKey(
         Country,
         Country,
         on_delete=models.SET_NULL,
         on_delete=models.SET_NULL,
@@ -87,7 +101,10 @@ class BreadPage(BasePageFieldsMixin, Page):
     )
     )
     ingredients = ParentalManyToManyField('BreadIngredient', blank=True)
     ingredients = ParentalManyToManyField('BreadIngredient', blank=True)
 
 
-    content_panels = BasePageFieldsMixin.content_panels + [
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction', classname="full"),
+        ImageChooserPanel('image'),
+        StreamFieldPanel('body'),
         FieldPanel('origin'),
         FieldPanel('origin'),
         FieldPanel('bread_type'),
         FieldPanel('bread_type'),
         MultiFieldPanel(
         MultiFieldPanel(
@@ -110,13 +127,24 @@ class BreadPage(BasePageFieldsMixin, Page):
     parent_page_types = ['BreadsIndexPage']
     parent_page_types = ['BreadsIndexPage']
 
 
 
 
-class BreadsIndexPage(BasePageFieldsMixin, Page):
+class BreadsIndexPage(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 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.'
+    )
     subpage_types = ['BreadPage']
     subpage_types = ['BreadPage']
 
 
     def get_breads(self):
     def get_breads(self):

+ 19 - 0
bakerydemo/locations/migrations/0002_remove_locationsindexpage_body.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-03-26 21:57
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='locationsindexpage',
+            name='body',
+        ),
+    ]

+ 34 - 4
bakerydemo/locations/models.py

@@ -6,12 +6,14 @@ from django.db import models
 
 
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
 
 
-from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
+from wagtail.wagtailcore.fields import StreamField
+from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel, StreamFieldPanel
+
 from wagtail.wagtailcore.models import Orderable, Page
 from wagtail.wagtailcore.models import Orderable, Page
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsearch import index
 from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 
 
-from bakerydemo.base.models import BasePageFieldsMixin
+from bakerydemo.base.blocks import BaseStreamBlock
 from bakerydemo.locations.choices import DAY_CHOICES
 from bakerydemo.locations.choices import DAY_CHOICES
 
 
 
 
@@ -74,10 +76,23 @@ class LocationOperatingHours(Orderable, OperatingHours):
     )
     )
 
 
 
 
-class LocationsIndexPage(BasePageFieldsMixin, Page):
+class LocationsIndexPage(Page):
     """
     """
     Index page for locations
     Index page for locations
     """
     """
+
+    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.'
+    )
+
     subpage_types = ['LocationPage']
     subpage_types = ['LocationPage']
 
 
     def children(self):
     def children(self):
@@ -96,10 +111,24 @@ class LocationsIndexPage(BasePageFieldsMixin, Page):
     ]
     ]
 
 
 
 
-class LocationPage(BasePageFieldsMixin, Page):
+class LocationPage(Page):
     """
     """
     Detail for a specific bakery location.
     Detail for a specific bakery location.
     """
     """
+    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.'
+    )
+    body = StreamField(
+        BaseStreamBlock(), verbose_name="Page body", blank=True
+    )
     address = models.TextField()
     address = models.TextField()
     lat_long = models.CharField(
     lat_long = models.CharField(
         max_length=36,
         max_length=36,
@@ -125,6 +154,7 @@ class LocationPage(BasePageFieldsMixin, Page):
         FieldPanel('title', classname="full"),
         FieldPanel('title', classname="full"),
         FieldPanel('introduction', classname="full"),
         FieldPanel('introduction', classname="full"),
         ImageChooserPanel('image'),
         ImageChooserPanel('image'),
+        StreamFieldPanel('body'),
         FieldPanel('address', classname="full"),
         FieldPanel('address', classname="full"),
         FieldPanel('lat_long'),
         FieldPanel('lat_long'),
         InlinePanel('hours_of_operation', label="Hours of Operation"),
         InlinePanel('hours_of_operation', label="Hours of Operation"),