From 4d14f21ed7c962af236d86dc48621cb85164f699 Mon Sep 17 00:00:00 2001 From: David Ray Date: Fri, 10 Feb 2017 09:04:34 -0500 Subject: [PATCH 1/2] resolve merge conflicts and code cleanup --- bakerydemo/base/blocks.py | 22 +++--- bakerydemo/base/models.py | 71 +++++++------------ .../base/templatetags/navigation_tags.py | 3 +- bakerydemo/blog/models.py | 6 +- bakerydemo/breads/models.py | 12 ++-- bakerydemo/locations/models.py | 4 +- bakerydemo/search/views.py | 3 +- 7 files changed, 47 insertions(+), 74 deletions(-) diff --git a/bakerydemo/base/blocks.py b/bakerydemo/base/blocks.py index fd212e8..51c5183 100644 --- a/bakerydemo/base/blocks.py +++ b/bakerydemo/base/blocks.py @@ -1,14 +1,12 @@ from wagtail.wagtailimages.blocks import ImageChooserBlock from wagtail.wagtailembeds.blocks import EmbedBlock from wagtail.wagtailcore.blocks import ( + CharBlock, + ChoiceBlock, + RichTextBlock, + StreamBlock, StructBlock, TextBlock, - StreamBlock, - RichTextBlock, - CharBlock, - ListBlock, - ChoiceBlock, - PageChooserBlock ) @@ -25,11 +23,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" @@ -39,7 +37,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 e5a88d7..e2a5328 100644 --- a/bakerydemo/base/models.py +++ b/bakerydemo/base/models.py @@ -1,28 +1,24 @@ from __future__ import unicode_literals from django.db import models -from django.db.utils import OperationalError 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 wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel -from .blocks import BaseStreamBlock -from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField + FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel, + PageChooserPanel, StreamFieldPanel, +) from wagtail.contrib.modeladmin.options import ( ModelAdmin, ModelAdminGroup, modeladmin_register) +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 @@ -53,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' @@ -100,7 +96,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 @@ -110,10 +106,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 = [ @@ -128,22 +124,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 @@ -159,7 +139,7 @@ class HomePage(Page): body = StreamField( BaseStreamBlock(), verbose_name="Home page detail", blank=True - ) + ) content_panels = Page.content_panels + [ ImageChooserPanel('image'), @@ -254,6 +234,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 2d29ea8..207e9a9 100644 --- a/bakerydemo/base/templatetags/navigation_tags.py +++ b/bakerydemo/base/templatetags/navigation_tags.py @@ -1,6 +1,5 @@ from django import template -from django.template import Template -from django.utils.http import urlencode + from wagtail.wagtailcore.models import Page register = template.Library() diff --git a/bakerydemo/blog/models.py b/bakerydemo/blog/models.py index 210f1c1..a250ea7 100644 --- a/bakerydemo/blog/models.py +++ b/bakerydemo/blog/models.py @@ -4,8 +4,8 @@ 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 @@ -15,11 +15,11 @@ from wagtail.wagtailadmin.edit_handlers import ( 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 78bbff3..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 @@ -7,7 +7,6 @@ from wagtail.wagtailsearch.models import Query from bakerydemo.blog.models import BlogPage from bakerydemo.breads.models import BreadPage from bakerydemo.locations.models import LocationPage -from bakerydemo.base.models import People def search(request): From a26918f98d4b5236a957de99b1560088085f2ffc Mon Sep 17 00:00:00 2001 From: David Ray Date: Fri, 10 Feb 2017 09:09:38 -0500 Subject: [PATCH 2/2] normalize multiline imports --- bakerydemo/base/blocks.py | 7 +------ bakerydemo/blog/models.py | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/bakerydemo/base/blocks.py b/bakerydemo/base/blocks.py index 51c5183..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 ( - CharBlock, - ChoiceBlock, - RichTextBlock, - StreamBlock, - StructBlock, - TextBlock, + CharBlock, ChoiceBlock, RichTextBlock, StreamBlock, StructBlock, TextBlock, ) diff --git a/bakerydemo/blog/models.py b/bakerydemo/blog/models.py index a250ea7..26530dd 100644 --- a/bakerydemo/blog/models.py +++ b/bakerydemo/blog/models.py @@ -11,9 +11,7 @@ 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.wagtailcore.fields import StreamField from wagtail.wagtailcore.models import Page, Orderable