Przeglądaj źródła

Work on #41; adding BasePageFieldsMixin to more pages

David Ray 8 lat temu
rodzic
commit
407af8d2f6

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

+ 4 - 4
bakerydemo/base/models.py

@@ -26,7 +26,7 @@ class BasePageFieldsMixin(models.Model):
     An abstract base class for common fields
     """
     introduction = models.TextField(
-        help_text='Text to describe the index page',
+        help_text='Text to describe the page',
         blank=True)
     image = models.ForeignKey(
         'wagtailimages.Image',
@@ -34,11 +34,11 @@ class BasePageFieldsMixin(models.Model):
         blank=True,
         on_delete=models.SET_NULL,
         related_name='+',
-        help_text='Listing image'
+        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
     )
 
     content_panels = Page.content_panels + [
-        FieldPanel('introduction'),
+        FieldPanel('introduction', classname="full"),
         ImageChooserPanel('image'),
     ]
 
@@ -199,7 +199,7 @@ class HomePage(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(
         Collection,

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

@@ -0,0 +1,40 @@
+# -*- 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.RemoveField(
+            model_name='blogpage',
+            name='subtitle',
+        ),
+        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'),
+        ),
+    ]

+ 3 - 22
bakerydemo/blog/models.py

@@ -11,11 +11,10 @@ from taggit.models import Tag, TaggedItemBase
 
 from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
 from wagtail.wagtailadmin.edit_handlers import (
-    FieldPanel, InlinePanel, StreamFieldPanel, MultiFieldPanel
+    FieldPanel, InlinePanel, StreamFieldPanel
 )
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailcore.models import Page, Orderable
-from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailsearch import index
 from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
 
@@ -43,35 +42,17 @@ class BlogPageTag(TaggedItemBase):
     content_object = ParentalKey('BlogPage', related_name='tagged_items')
 
 
-class BlogPage(Page):
+class BlogPage(BasePageFieldsMixin, Page):
     """
     A Blog Page (Post)
     """
-    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)
-
     date_published = models.DateField("Date article published", blank=True, null=True)
-
     body = StreamField(
         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'),
         FieldPanel('date_published'),
         InlinePanel(

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

+ 8 - 20
bakerydemo/breads/models.py

@@ -5,11 +5,10 @@ from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
 from wagtail.wagtailcore.fields import StreamField
 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.wagtailsnippets.models import register_snippet
 
+from bakerydemo.base.blocks import BaseStreamBlock
 from bakerydemo.base.models import BasePageFieldsMixin
 
 
@@ -48,7 +47,7 @@ class BreadType(models.Model):
         verbose_name_plural = "Bread types"
 
 
-class BreadPage(Page):
+class BreadPage(BasePageFieldsMixin, Page):
     """
     Detail view for a specific bread
     """
@@ -59,10 +58,9 @@ class BreadPage(Page):
         null=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(
         'breads.BreadType',
         null=True,
@@ -70,26 +68,16 @@ class BreadPage(Page):
         on_delete=models.SET_NULL,
         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('bread_type'),
-        ImageChooserPanel('image'),
-        StreamFieldPanel('description'),
     ]
 
     search_fields = Page.search_fields + [
         index.SearchField('title'),
-        index.SearchField('description'),
+        index.SearchField('body'),
     ]
 
     parent_page_types = ['BreadsIndexPage']

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

+ 13 - 20
bakerydemo/locations/models.py

@@ -11,9 +11,6 @@ from wagtail.wagtailadmin.edit_handlers import (
     InlinePanel,
     StreamFieldPanel)
 from wagtail.wagtailcore.models import Orderable, Page
-from wagtail.wagtailimages.edit_handlers import (
-    ImageChooserPanel,
-    )
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailsearch import index
 
@@ -58,7 +55,7 @@ class OperatingHours(models.Model):
         "Closed?",
         blank=True,
         help_text='Tick if location is closed on this day'
-        )
+    )
 
     panels = [
         FieldPanel('day'),
@@ -71,10 +68,18 @@ class OperatingHours(models.Model):
         abstract = True
 
     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(
             self.day,
-            self.opening_time.strftime('%H:%M'),
-            self.closing_time.strftime('%H:%M'),
+            opening,
+            closed,
             settings.TIME_ZONE
         )
 
@@ -103,21 +108,11 @@ class LocationsIndexPage(BasePageFieldsMixin, Page):
         return context
 
 
-class LocationPage(Page):
+class LocationPage(BasePageFieldsMixin, Page):
     """
     Detail for a specific bakery location.
     """
-    introduction = models.TextField(
-        help_text='Text to describe the index page',
-        blank=True)
     address = models.TextField()
-    image = models.ForeignKey(
-        'wagtailimages.Image',
-        null=True,
-        blank=True,
-        on_delete=models.SET_NULL,
-        related_name='+'
-    )
     lat_long = models.CharField(
         max_length=36,
         help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
@@ -144,12 +139,10 @@ class LocationPage(Page):
     ]
 
     # Editor panels configuration
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction', classname="full"),
+    content_panels = BasePageFieldsMixin.content_panels + [
         StreamFieldPanel('body'),
         FieldPanel('address', classname="full"),
         FieldPanel('lat_long'),
-        ImageChooserPanel('image'),
         InlinePanel('hours_of_operation', label="Hours of Operation"),
     ]
 

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

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

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

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