diff --git a/bakerydemo/base/blocks.py b/bakerydemo/base/blocks.py index aa068e5..80483e6 100644 --- a/bakerydemo/base/blocks.py +++ b/bakerydemo/base/blocks.py @@ -1,12 +1,7 @@ from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.wagtailembeds.blocks import EmbedBlock from wagtail.wagtailcore.blocks import ( - StructBlock, - TextBlock, - StreamBlock, - RichTextBlock, - CharBlock, - ChoiceBlock, + CharBlock, ChoiceBlock, RichTextBlock, StreamBlock, StructBlock, TextBlock, ) @@ -23,11 +18,11 @@ class ImageBlock(StructBlock): class HeadingBlock(StructBlock): heading_text = CharBlock(classname="title", required=True) size = ChoiceBlock(choices=[ - ('', 'Select a header size'), - ('h2', 'H2'), - ('h3', 'H3'), - ('h4', 'H4') - ], blank=True, required=False) + ('', 'Select a header size'), + ('h2', 'H2'), + ('h3', 'H3'), + ('h4', 'H4') + ], blank=True, required=False) class Meta: icon = "title" @@ -37,7 +32,7 @@ class HeadingBlock(StructBlock): class BlockQuote(StructBlock): text = TextBlock(), attribute_name = CharBlock( - blank=True, required=False, label='e.g. Guy Picciotto') + blank=True, required=False, label='e.g. Guy Picciotto') class Meta: icon = "fa-quote-left" diff --git a/bakerydemo/base/models.py b/bakerydemo/base/models.py index 37fd35c..3fd8aa9 100644 --- a/bakerydemo/base/models.py +++ b/bakerydemo/base/models.py @@ -4,23 +4,21 @@ from django.db import models from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail.wagtailcore.models import Page, Orderable, Collection -from wagtail.wagtailsearch import index -from wagtail.wagtailimages.edit_handlers import ImageChooserPanel -from wagtail.wagtailcore.fields import StreamField, RichTextField -from wagtail.wagtailadmin.edit_handlers import ( - FieldPanel, - InlinePanel, - FieldRowPanel, - StreamFieldPanel, - MultiFieldPanel, - PageChooserPanel - ) -from wagtail.wagtailsnippets.models import register_snippet -from .blocks import BaseStreamBlock -from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField + from wagtail.contrib.modeladmin.options import ( ModelAdmin, ModelAdminGroup, modeladmin_register) +from wagtail.wagtailadmin.edit_handlers import ( + FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel, + PageChooserPanel, StreamFieldPanel, +) +from wagtail.wagtailcore.fields import RichTextField, StreamField +from wagtail.wagtailcore.models import Collection, Orderable, Page +from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel +from wagtail.wagtailsearch import index +from wagtail.wagtailsnippets.models import register_snippet + +from .blocks import BaseStreamBlock @register_snippet @@ -51,15 +49,15 @@ class People(ClusterableModel): @property def thumb_image(self): - # fail silently if there is no profile pic or the rendition file can't - # be found. Note @richbrennan worked out how to do this... - try: - return self.image.get_rendition('fill-50x50').img_tag() - except: - return '' + # fail silently if there is no profile pic or the rendition file can't + # be found. Note @richbrennan worked out how to do this... + try: + return self.image.get_rendition('fill-50x50').img_tag() + except: + return '' def __str__(self): - return self.first_name + " " + self.last_name + return '{} {}'.format(self.first_name, self.last_name) class Meta: verbose_name = 'Person' @@ -113,7 +111,7 @@ class AboutPage(Page): body = StreamField( BaseStreamBlock(), verbose_name="About page detail", blank=True - ) + ) # We've defined the StreamBlock() within blocks.py that we've imported on # line 12. Defining it in a different file gives us consistency across the # site, though StreamFields _can_ be created on a per model basis if you @@ -123,10 +121,10 @@ class AboutPage(Page): ImageChooserPanel('image'), StreamFieldPanel('body'), InlinePanel( - 'location_about_relationship', - label='Locations', - min_num=None - ), + 'location_about_relationship', + label='Locations', + min_num=None + ), ] # parent_page_types = [ @@ -141,22 +139,6 @@ class AboutPage(Page): # api_fields = ['image', 'body'] -def getImageCollections(): - # We return all collections to a list that don't have the name root. - try: - collection_images = [( - collection.id, collection.name - ) for collection in Collection.objects.all().exclude( - name='Root' - )] - return collection_images - except: - return [('', '')] - - def __str__(self): - return self.title - - class HomePage(Page): """ The Home Page @@ -172,7 +154,7 @@ class HomePage(Page): body = StreamField( BaseStreamBlock(), verbose_name="Home page detail", blank=True - ) + ) content_panels = Page.content_panels + [ ImageChooserPanel('image'), @@ -267,6 +249,7 @@ class MyModelAdminGroup(ModelAdminGroup): menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd) items = (PeopleModelAdmin,) + # When using a ModelAdminGroup class to group several ModelAdmin classes together, # you only need to register the ModelAdminGroup class with Wagtail: modeladmin_register(MyModelAdminGroup) diff --git a/bakerydemo/base/templatetags/navigation_tags.py b/bakerydemo/base/templatetags/navigation_tags.py index 1d62aac..23292f9 100644 --- a/bakerydemo/base/templatetags/navigation_tags.py +++ b/bakerydemo/base/templatetags/navigation_tags.py @@ -1,5 +1,7 @@ from django import template + from wagtail.wagtailcore.models import Page + from bakerydemo.base.models import FooterText diff --git a/bakerydemo/blog/models.py b/bakerydemo/blog/models.py index 210f1c1..26530dd 100644 --- a/bakerydemo/blog/models.py +++ b/bakerydemo/blog/models.py @@ -4,22 +4,20 @@ from django.contrib import messages from django.db import models from django.shortcuts import redirect, render -from modelcluster.fields import ParentalKey from modelcluster.contrib.taggit import ClusterTaggableManager +from modelcluster.fields import ParentalKey from taggit.models import Tag, TaggedItemBase from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route from wagtail.wagtailadmin.edit_handlers import ( - FieldPanel, - InlinePanel, - StreamFieldPanel, + FieldPanel, InlinePanel, StreamFieldPanel, ) -from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailcore.fields import StreamField from wagtail.wagtailcore.models import Page, Orderable -from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtail.wagtailsearch import index +from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel from bakerydemo.base.blocks import BaseStreamBlock diff --git a/bakerydemo/breads/models.py b/bakerydemo/breads/models.py index 58083a1..2f1647d 100644 --- a/bakerydemo/breads/models.py +++ b/bakerydemo/breads/models.py @@ -1,12 +1,12 @@ from django.db import models -from wagtail.wagtailcore.models import Page -from wagtail.wagtailcore.fields import StreamField 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.wagtailcore import blocks from wagtail.wagtailsnippets.models import register_snippet @@ -55,7 +55,7 @@ class BreadPage(Page): on_delete=models.SET_NULL, null=True, blank=True, - ) + ) description = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), @@ -89,9 +89,7 @@ class BreadPage(Page): index.SearchField('description'), ] - parent_page_types = [ - 'BreadsIndexPage' - ] + parent_page_types = ['BreadsIndexPage'] class BreadsIndexPage(Page): diff --git a/bakerydemo/locations/models.py b/bakerydemo/locations/models.py index 6ee0c1e..61511b1 100644 --- a/bakerydemo/locations/models.py +++ b/bakerydemo/locations/models.py @@ -121,6 +121,4 @@ class LocationPage(Page): context['long'] = self.lat_long.split(",")[1] return context - parent_page_types = [ - 'LocationsIndexPage' - ] + parent_page_types = ['LocationsIndexPage'] diff --git a/bakerydemo/search/views.py b/bakerydemo/search/views.py index 2e453cd..ea5163f 100644 --- a/bakerydemo/search/views.py +++ b/bakerydemo/search/views.py @@ -1,5 +1,5 @@ -from django.shortcuts import render from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.shortcuts import render from wagtail.wagtailcore.models import Page from wagtail.wagtailsearch.models import Query