ソースを参照

Merge master and resolve merge conflicts

Edd Baldry 8 年 前
コミット
326d11b181

+ 44 - 41
bakerydemo/base/models.py

@@ -23,38 +23,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.'
-    )
-    # The StreamField is defined within base/blocks.py
-    body = StreamField(
-        BaseStreamBlock(), verbose_name="Page body", blank=True
-    )
-    # The content_panels makes the fields accessible to the editor within the
-    # admin area. If you don't include a field here it won't be displayed
-    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):
     """
     """
@@ -129,14 +97,31 @@ class FooterText(models.Model):
         verbose_name_plural = 'Footer Text'
         verbose_name_plural = 'Footer Text'
 
 
 
 
-class StandardPage(Page, BasePageFieldsMixin):
+class StandardPage(Page):
     """
     """
     A generic content page. On this demo site we use it for an about page but
     A generic content page. On this demo site we use it for an about page but
     could be used for any type of page content.
     could be used for any type of page content.
     """
     """
 
 
-    # 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):
@@ -270,10 +255,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([
@@ -295,13 +280,28 @@ 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. We use a Q
     This is a page to list locations from the selected Collection. We use a Q
     object to list any Collection created (/admin/collections/) even if they
     object to list any Collection created (/admin/collections/) even if they
     contain no items. It's unlikely to be useful for many production settings
     contain no items. It's unlikely to be useful for many production settings
     but is intended to show the extensibility of aspect of Wagtail
     but is intended to show the extensibility of aspect of Wagtail
     """
     """
+
+    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']),
@@ -311,7 +311,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 - 10
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):
@@ -47,7 +48,7 @@ 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
     A Blog Page
 
 
@@ -55,22 +56,37 @@ class BlogPage(BasePageFieldsMixin, Page):
     ParentalKey's related_name in BlogPeopleRelationship. More docs:
     ParentalKey's related_name in BlogPeopleRelationship. More docs:
     http://docs.wagtail.io/en/v1.9/topics/pages.html#inline-models
     http://docs.wagtail.io/en/v1.9/topics/pages.html#inline-models
     """
     """
+    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_published = models.DateField(
         "Date article published", blank=True, null=True
         "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'),
@@ -115,7 +131,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,
     We need to alter the page model's context to return the child page objects,
@@ -124,13 +140,24 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
     RoutablePageMixin is used to allow for a custom sub-URL for the tag views
     RoutablePageMixin is used to allow for a custom sub-URL for the tag views
     defined above.
     defined above.
     """
     """
+    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 + [
     content_panels = Page.content_panels + [
         FieldPanel('introduction', classname="full"),
         FieldPanel('introduction', classname="full"),
         ImageChooserPanel('image'),
         ImageChooserPanel('image'),
     ]
     ]
 
 
-    # Defines what pages types can live under this page type
+    # Defines that only BlogPage objects can live under this index page
     subpage_types = ['BlogPage']
     subpage_types = ['BlogPage']
 
 
     # Defines a function to access the children of the page (e.g. BlogPage
     # Defines a function to access the children of the page (e.g. BlogPage
@@ -148,7 +175,6 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
             '-date_published')
             '-date_published')
         return context
         return context
 
 
-
     # This defines a Custom view that utilizes Tags. This view will return all
     # This defines a Custom view that utilizes Tags. This view will return all
     # related BlogPages for a given Tag or redirect back to the BlogIndexPage.
     # related BlogPages for a given Tag or redirect back to the BlogIndexPage.
     # More information on RoutablePages is at
     # More information on RoutablePages is at

+ 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',
+        ),
+    ]

+ 47 - 15
bakerydemo/breads/models.py

@@ -4,13 +4,16 @@ 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
@@ -80,11 +83,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,
@@ -92,9 +108,9 @@ class BreadPage(BasePageFieldsMixin, Page):
         blank=True,
         blank=True,
     )
     )
 
 
-    # We include related_name='+' to avoid name collisions on relationships. 
-    # e.g. there are two FooPage models in two different apps, 
-    # and they both have a FK to bread_type, they'll both try to create a 
+    # We include related_name='+' to avoid name collisions on relationships.
+    # e.g. there are two FooPage models in two different apps,
+    # and they both have a FK to bread_type, they'll both try to create a
     # relationship called `foopage_objects` that will throw a valueError on
     # relationship called `foopage_objects` that will throw a valueError on
     # collision.
     # collision.
     bread_type = models.ForeignKey(
     bread_type = models.ForeignKey(
@@ -106,7 +122,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(
@@ -129,7 +148,7 @@ class BreadPage(BasePageFieldsMixin, Page):
     parent_page_types = ['BreadsIndexPage']
     parent_page_types = ['BreadsIndexPage']
 
 
 
 
-class BreadsIndexPage(BasePageFieldsMixin, Page):
+class BreadsIndexPage(Page):
     """
     """
     Index page for breads.
     Index page for breads.
 
 
@@ -138,6 +157,24 @@ class BreadsIndexPage(BasePageFieldsMixin, Page):
     to be discrete functions to make it easier to follow
     to be discrete functions to make it easier to follow
     """
     """
 
 
+    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'),
+    ]
+
     # Can only have BreadPage children
     # Can only have BreadPage children
     subpage_types = ['BreadPage']
     subpage_types = ['BreadPage']
 
 
@@ -168,7 +205,7 @@ class BreadsIndexPage(BasePageFieldsMixin, Page):
         return pages
         return pages
 
 
     # Returns the above to the get_context method that is used to populate the
     # Returns the above to the get_context method that is used to populate the
-    # template
+    # template
     def get_context(self, request):
     def get_context(self, request):
         context = super(BreadsIndexPage, self).get_context(request)
         context = super(BreadsIndexPage, self).get_context(request)
 
 
@@ -178,8 +215,3 @@ class BreadsIndexPage(BasePageFieldsMixin, Page):
         context['breads'] = breads
         context['breads'] = breads
 
 
         return context
         return context
-
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction', classname="full"),
-        ImageChooserPanel('image'),
-    ]

+ 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',
+        ),
+    ]

+ 33 - 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
 
 
 
 
@@ -81,10 +83,22 @@ class LocationOperatingHours(Orderable, OperatingHours):
     )
     )
 
 
 
 
-class LocationsIndexPage(BasePageFieldsMixin, Page):
+class LocationsIndexPage(Page):
     """
     """
     A Page model that creates an index page (a listview)
     A Page model that creates an index page (a listview)
     """
     """
+    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.'
+    )
+
     # Only LocationPage objects can be added underneath this index page
     # Only LocationPage objects can be added underneath this index page
     subpage_types = ['LocationPage']
     subpage_types = ['LocationPage']
 
 
@@ -110,10 +124,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,
@@ -139,6 +167,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"),