Browse Source

Fixes #41; create abstrat base class for common fields

David Ray 8 năm trước cách đây
mục cha
commit
b8090a1ccf

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

+ 30 - 18
bakerydemo/base/models.py

@@ -21,6 +21,31 @@ from wagtail.wagtailsnippets.models import register_snippet
 from .blocks import BaseStreamBlock
 
 
+class CommonPageFieldsMixin(models.Model):
+    """
+    An abstract base class for common fields
+    """
+    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='Listing image'
+    )
+
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction'),
+        ImageChooserPanel('image'),
+    ]
+
+    class Meta:
+        abstract = True
+
+
 @register_snippet
 class People(ClusterableModel):
     """
@@ -113,7 +138,7 @@ class AboutPage(Page):
         blank=True,
         on_delete=models.SET_NULL,
         related_name='+',
-        help_text='Location image'
+        help_text='About image'
     )
 
     body = StreamField(
@@ -156,7 +181,7 @@ class HomePage(Page):
         blank=True,
         on_delete=models.SET_NULL,
         related_name='+',
-        help_text='Location image'
+        help_text='Homepage image'
     )
 
     body = StreamField(
@@ -172,7 +197,7 @@ class HomePage(Page):
         return self.title
 
 
-class GalleryPage(Page):
+class GalleryPage(CommonPageFieldsMixin, Page):
     """
     This is a page to list all the locations on the site
     """
@@ -182,24 +207,11 @@ class GalleryPage(Page):
         null=True,
         blank=True,
         on_delete=models.SET_NULL,
+        help_text='Select the image collection for this gallery.'
     )
-    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 + [
+    content_panels = CommonPageFieldsMixin.content_panels + [
         FieldPanel('choices'),
-        ImageChooserPanel('image'),
-        FieldPanel('introduction')
     ]
 
     # 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'),
+        ),
+    ]

+ 2 - 19
bakerydemo/blog/models.py

@@ -20,6 +20,7 @@ from wagtail.wagtailsearch import index
 from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
 
 from bakerydemo.base.blocks import BaseStreamBlock
+from bakerydemo.base.models import CommonPageFieldsMixin
 
 
 class BlogPeopleRelationship(Orderable, models.Model):
@@ -116,7 +117,7 @@ class BlogPage(Page):
     subpage_types = []
 
 
-class BlogIndexPage(RoutablePageMixin, Page):
+class BlogIndexPage(CommonPageFieldsMixin, RoutablePageMixin, Page):
     """
     Index page for blogs.
     We need to alter the page model's context to return the child page objects - the
@@ -125,24 +126,6 @@ class BlogIndexPage(RoutablePageMixin, Page):
     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?
     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'),
+        ),
+    ]

+ 4 - 18
bakerydemo/breads/models.py

@@ -1,3 +1,4 @@
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.db import models
 
 from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
@@ -8,7 +9,8 @@ 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 django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+
+from bakerydemo.base.models import CommonPageFieldsMixin
 
 
 @register_snippet
@@ -95,31 +97,15 @@ class BreadPage(Page):
     api_fields = ['title', 'bread_type', 'origin', 'image']
 
 
-class BreadsIndexPage(Page):
+class BreadsIndexPage(CommonPageFieldsMixin, Page):
     """
     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
     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']
 
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction'),
-        ImageChooserPanel('image'),
-    ]
-
     def get_context(self, 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'),
+        ),
+    ]

+ 3 - 18
bakerydemo/locations/models.py

@@ -8,6 +8,8 @@ from wagtail.wagtailcore.models import Orderable, Page
 from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 from wagtail.wagtailsearch import index
 
+from bakerydemo.base.models import CommonPageFieldsMixin
+
 
 class OperatingHours(models.Model):
     """
@@ -62,29 +64,12 @@ class LocationOperatingHours(Orderable, OperatingHours):
     )
 
 
-class LocationsIndexPage(Page):
+class LocationsIndexPage(CommonPageFieldsMixin, Page):
     """
     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']
 
-    content_panels = Page.content_panels + [
-        FieldPanel('introduction'),
-        ImageChooserPanel('image'),
-    ]
-
     def get_context(self, request):
         context = super(LocationsIndexPage, self).get_context(request)
         context['locations'] = LocationPage.objects.descendant_of(