class FlexPage(Page): parent_page_types = ["home.HomePage", "flex.FlexPage"] body = StreamField( [("title", blocks.TitleBlock()), ("cards", blocks.CardsBlock()), ("image_and_text", blocks.ImageAndTextBlock()), ("cta", blocks.CallToActionBlock()), ("testimonial", SnippetChooserBlock( target_model='testimonials.Testimonial', template="streams/testimonial_block.html", )), ("pricing_table", blocks.PricingTableBlock(table_options=NEW_TABLE_OPTIONS, )), ("richtext", wagtail_blocks.RichTextBlock( template="streams/simple_richtext_block.html", features=["bold", "italic", "ol", "ul", "link"])), ("large_image", ImageChooserBlock( help_text='This image will be cropped to 1200px by 775px', template="streams/large_image_block.html"))], null=True, blank=True) content_panels = Page.content_panels + [ StreamFieldPanel("body"), ] class Meta: verbose_name = "Flex (misc) page" verbose_name_plural = "Flex (misc) pages"
class HomePage(Page): parent_page_types = ["wagtailcore.Page"] subpage_types = ["flex.FlexPage", "services.ServiceListingPage", "contact.ContactPage"] max_count = 1 lead_text = models.CharField( max_length=140, blank=True, help_text='Subheading text under the banner title', ) button = models.ForeignKey( 'wagtailcore.Page', blank=True, null=True, related_name='+', help_text='Select an optional page to link to', on_delete=models.SET_NULL, ) button_text = models.CharField( max_length=50, default='Read More', blank=False, help_text='Button text', ) banner_background_image = models.ForeignKey( 'wagtailimages.Image', blank=False, null=True, related_name='+', help_text='The banner background image', on_delete=models.SET_NULL, ) body = StreamField([ ("title", blocks.TitleBlock()), ("cards", blocks.CardsBlock()), ("image_and_text", blocks.ImageAndTextBlock()), ("cta", blocks.CallToActionBlock()), ("testimonial", SnippetChooserBlock( target_model='testimonials.Testimonial', template="streams/testimonial_block.html", )), ("pricing_table", blocks.PricingTableBlock(table_options=NEW_TABLE_OPTIONS)), ], null=True, blank=True) content_panels = Page.content_panels + [ FieldPanel("lead_text"), PageChooserPanel("button"), FieldPanel("button_text"), ImageChooserPanel("banner_background_image"), StreamFieldPanel("body"), ] def save(self, *args, **kwargs): key = make_template_fragment_key( "home_page_streams", [self.id], ) cache.delete(key) return super().save(*args, **kwargs)
class FlexPage(Page): # limit where pages may be created parent_page_types = ["home.HomePage", "flex.FlexPage"] # define custom streamfields, takes list of tuples # uses classes defined in streams.blocks body = StreamField( [ # names in quotes are arbitrary but should be descriptive ("title", blocks.TitleBlock()), ("cards", blocks.CardsBlock()), ("image_and_text", blocks.ImageAndTextBlock()), ('call_to_action', blocks.CallToActionBlock()), ( 'richtext_editor', wagtail_blocks.RichTextBlock( template='streams/simple_richtext_block.html', # limit available features to the following # features=["bold", "italic", "ol", "ul", "link"] )), ('large_image', ImageChooserBlock( help_text='Add a large image to the page, 1200x775', template="streams/large_image_block.html")), ('small_image', ImageChooserBlock( help_text='Add a small image to the page, 900x450', template="streams/small_image_block.html")), ('pricing_table', blocks.PricingTableBlock(table_options=new_table_options)), ], null=True, blank=True) # expose the body fields via the admin interface for editing content_panels = Page.content_panels + [ StreamFieldPanel("body"), MultiFieldPanel( [ InlinePanel( "carousel_images", max_num=10, min_num=0, label="Image") ], heading="Carousel Images", ), ] class Meta: verbose_name = "Flex (misc) page" verbose_name_plural = "Flex (misc) pages"
class FlexPage(Page): parent_page_types = ["home.HomePage","flex.FlexPage"] class Meta: verbose_name = "Flex (misc) page" verbose_name_plural = "Flex (misc) pages" #Declare the Stream Field body = StreamField([ ('title', blocks.TitleBlock()), ('cards', blocks.CardsBlock()), ('images', blocks.ImageAndTextBlock()), ('cta', blocks.CallToActionBlock()), ("testimonials", SnippetChooserBlock( target_model = "testimonials.Testimonial", template = "streams/testimonial_block.html", )), ("table", blocks.PricingTableBlock( table_options = new_table_options )), ('rich_text', wagtail_blocks.RichTextBlock( template = "streams/simple_richtext_block.html" )), ('large_image', ImageChooserBlock( template = "streams/large_image_block.html", help_text = "This image will be cropped 1080px by 900px" )) #('new_richtext', blocks.NewRichTextBlock()) ], null = True, blank = True) content_panels = Page.content_panels + [ StreamFieldPanel("body") ] def save(self,*args,**kwargs): key = make_template_fragment_key( "flex_page", [self.id] ) cache.delete(key) return super().save(*args,**kwargs)
class HomePage(Page): parent_page_types = ["wagtailcore.Page"] subpage_types = ["flex.FlexPage", "services.ServiceListingPage", "contact.ContactPage"] max_count = 1 lead_text = models.CharField( max_length=140, blank=True, help_text="Subheading text under the banner title" ) button = models.ForeignKey( "wagtailcore.Page", blank=True, null=True, related_name="+", help_text="Select an optional text to link to", on_delete=models.SET_NULL, ) button_text = models.CharField( max_length=50, default="Read More", blank=False, help_text="Read more " ) banner_background_image = models.ForeignKey( "wagtailimages.Image", blank=True, null=True, related_name="+", help_text="The banner background image", on_delete=models.SET_NULL, ) body = StreamField( [("title", blocks.TitleBlock()), ("cards", blocks.CardBlock()),("image_and_text", blocks.ImageAndTextBlock()), ("cta", blocks.CallToActionBlock()), ("testimonial", SnippetChooserBlock( target_model="testimonials.Testimonial", template="streams/testimonial_block.html", )), ("pricing_table", blocks.PricingTableBlock(table_options=NEW_TABLE_OPTIONS)),], null=True, blank=True, ) content_panels = Page.content_panels + [ FieldPanel("lead_text"), PageChooserPanel("button"), FieldPanel("button_text"), ImageChooserPanel("banner_background_image"), StreamFieldPanel("body"), ]
class HomePage(Page): parent_page_types = ["wagtailcore.Page"] subpage_types = ["flex.FlexPage", "services.ServiceListingPage","contacts.ContactPage"] max_count = 1 lead_text = models.CharField( max_length = 140, blank = True, help_text = "Subsequent text after the banner title idk some other stuff ok?", ) button = models.ForeignKey( 'wagtailcore.Page', blank = True, null = True, on_delete = models.SET_NULL, related_name = '+', help_text = "Page Chooser Panel" ) button_text = models.CharField( max_length = 50, blank = False, help_text = "The Button Text", ) banner_background_image = models.ForeignKey( 'wagtailimages.Image', blank = False, null = True, related_name = '+', help_text = 'The banner background image', on_delete = models.SET_NULL, ) #Declare the Stream Field body = StreamField([ ('title', blocks.TitleBlock()), ('cards', blocks.CardsBlock()), ('images', blocks.ImageAndTextBlock()), ('cta', blocks.CallToActionBlock()), ("testimonials", SnippetChooserBlock( target_model = "testimonials.Testimonial", template = "streams/testimonial_block.html", )), ("table", blocks.PricingTableBlock( table_options = new_table_options )) ], null = True, blank = True) content_panels = Page.content_panels + [ FieldPanel("lead_text"), PageChooserPanel("button"), FieldPanel("button_text"), ImageChooserPanel("banner_background_image"), StreamFieldPanel("body"), #Add the stream field to content Panel ] #*********Remove Caching every time the page gets saved************** def save(self, *args, **kwargs): key = make_template_fragment_key( "home_page_streams", [self.id], #This value is a list ) cache.delete(key) return super().save(*args,**kwargs)
class ServicePage(Page): parent_page_types = ["services.ServiceListingPage"] subpage_types = [] template = "services/service_page.html" description = models.TextField( blank=True, max_length=500, ) internal_page = models.ForeignKey( 'wagtailcore.Page', blank=True, null=True, related_name='+', help_text='Select an internal Wagtail page', on_delete=models.SET_NULL, ) external_page = models.URLField(blank=True) button_text = models.CharField(blank=True, max_length=50) service_image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=False, on_delete=models.SET_NULL, help_text= 'This image will be used on the Service Listing Page and will be cropped to 570px by 370px on this page.', related_name='+', ) body = StreamField( [("title", blocks.TitleBlock()), ("cards", blocks.CardsBlock()), ("image_and_text", blocks.ImageAndTextBlock()), ("cta", blocks.CallToActionBlock()), ("testimonial", SnippetChooserBlock( target_model='testimonials.Testimonial', template="streams/testimonial_block.html", )), ("pricing_table", blocks.PricingTableBlock(table_options=NEW_TABLE_OPTIONS, )), ("richtext", wagtail_blocks.RichTextBlock( template="streams/simple_richtext_block.html", features=["bold", "italic", "ol", "ul", "link"])), ("large_image", ImageChooserBlock( help_text='This image will be cropped to 1200px by 775px', template="streams/large_image_block.html"))], null=True, blank=True) content_panels = Page.content_panels + [ FieldPanel("description"), PageChooserPanel("internal_page"), FieldPanel("external_page"), FieldPanel("button_text"), ImageChooserPanel("service_image"), StreamFieldPanel("body"), ] def clean(self): super().clean() if self.internal_page and self.external_page: # Both fields are filled out raise ValidationError({ 'internal_page': ValidationError( "Please only select a page OR enter an external URL"), 'external_page': ValidationError( "Please only select a page OR enter an external URL"), }) if not self.internal_page and not self.external_page: raise ValidationError({ 'internal_page': ValidationError( "You must always select a page OR enter an external URL"), 'external_page': ValidationError( "You must always select a page OR enter an external URL"), })
class HomePage(Page): # limit where home page may be created parent_page_types = ["wagtailcore.Page"] subpage_types = [ "flex.FlexPage", "services.ServiceListingPage", "contact.ContactPage" ] max_count = 1 lead_text = models.CharField(max_length=140, blank=True, help_text='Subheading text under banner') button = models.ForeignKey('wagtailcore.Page', blank=True, null=True, related_name='+', help_text='Select an option page to link to', on_delete=models.SET_NULL) button_text = models.CharField( max_length=50, default='Read More', blank=False, help_text='button text', ) banner_background_image = models.ForeignKey( 'wagtailimages.Image', blank=False, null=True, related_name='+', help_text='The banner background image', on_delete=models.SET_NULL) # define custom streamfields, takes list of tuples # uses classes defined in streams.blocks body = StreamField( [ # names in quotes are arbitrary but should be descriptive ("title", blocks.TitleBlock()), ("cards", blocks.CardsBlock()), ("image_and_text", blocks.ImageAndTextBlock()), ('call_to_action', blocks.CallToActionBlock()), ('pricing_table', blocks.PricingTableBlock(table_options=new_table_options)), ( 'richtext_editor', wagtail_blocks.RichTextBlock( # template='streams/simple_richtext_block.html', # limit available features to the following # features=["bold", "italic", "ol", "ul", "link", "heading", 'h2', 'h3'] )), ], null=True, blank=True) # augment content panels with the fields defined in our model # each panel type takes an argument (string) corresponding to the variables above content_panels = Page.content_panels + [ FieldPanel("lead_text"), PageChooserPanel('button'), FieldPanel("button_text"), ImageChooserPanel("banner_background_image"), # add panel for streamfield in admin interface # can create one or more streamfield blocks on the home page StreamFieldPanel("body") ]