class PlaceDetailBlock(blocks.StructBlock): place = blocks.CharBlock(requried=True) details = blocks.TextBlock(requried=True, help_text="Add place details") duration_of_visit = blocks.CharBlock(requried=True) distance_from_start_location = blocks.IntegerBlock(null=False, default=0) map_icon = blocks.StructBlock([ ("map_icon", ImageChooserBlock(required=False)), ]) trip_types = blocks.ListBlock( blocks.StructBlock([ ("trip_type", SnippetChooserBlock(models.TripType)), ])) tags = blocks.ListBlock( blocks.StructBlock([ ("tag", SnippetChooserBlock(models.LocationTag)), ])) images = blocks.ListBlock( blocks.StructBlock([ ("image", ImageChooserBlock(required=True)), ])) class Meta: template = "outstation/place_detail.html" icon = "edit"
class FullText(blocks.StructBlock): text_size = blocks.ChoiceBlock(choices=[ ('xsmall', 'X-Small'), ('small', 'Small'), ('normal', 'Normal'), ('medium', 'Medium'), ('big', 'Big'), ('giant', 'Giant'), ], icon='edit', default='big') font_color = SnippetChooserBlock('home.Colors', blank=True) text = blocks.RichTextBlock() align = blocks.CharBlock(default="left", label='css align type [left, right, center, etc]') use_container = blocks.BooleanBlock(required=False, default=False) use_background_color = blocks.BooleanBlock(required=False) back_color = SnippetChooserBlock('home.Colors', blank=True, required=False) padding = blocks.CharBlock(default="none", label='css padding value', required=False) margin = blocks.CharBlock(default="none", label='css margin value', required=False) class Meta: template = 'tmps/tmp_full_text.html'
class HeroParametric(blocks.StructBlock): use_image_carousel = blocks.BooleanBlock(required=False) images = blocks.StreamBlock([('image', ImageChooserBlock())], required=False) tint_overlay = blocks.FloatBlock(default=0.7, label='Amount of blue Tint') tint_R = blocks.IntegerBlock(default=0) tint_G = blocks.IntegerBlock(default=74) tint_B = blocks.IntegerBlock(default=135) height = blocks.CharBlock(default="300px") min_height = blocks.CharBlock(default="500px") big_text = blocks.RichTextBlock() detail_text = blocks.RichTextBlock(required=False) text_color = SnippetChooserBlock('home.Colors', blank=True, required=False) use_circle = blocks.BooleanBlock(required=False) use_image = blocks.BooleanBlock(required=False) mini_image = ImageChooserBlock(required=False) letters = blocks.CharBlock(required=False, max_length=3, label="Initial letters if dont use image") letters_color = SnippetChooserBlock('home.Colors', blank=True, required=False) letters_back = SnippetChooserBlock('home.Colors', blank=True, required=False) class Meta: template = 'tmps/tmp_hero_params.html'
class ContributorPage(Page, PagePreviewDescriptionMixin): '''Project contributor and advisory board page.''' contributors = StreamField( [('person', SnippetChooserBlock(Person))], blank=True, help_text='Select and order people to be listed as project \ contributors.') board = StreamField( [('person', SnippetChooserBlock(Person))], blank=True, help_text='Select and order people to be listed as board members.') body = StreamField(BodyContentBlock, blank=True) content_panels = Page.content_panels + [ FieldPanel('description'), StreamFieldPanel('contributors'), StreamFieldPanel('board'), StreamFieldPanel('body'), ] # only allow creating directly under home page parent_page_types = [HomePage] # not allowed to have sub pages subpage_types = []
class RoundFrameText(blocks.StructBlock): text = blocks.RichTextBlock() text_color = SnippetChooserBlock('home.Colors', blank=True) back_color = SnippetChooserBlock('home.Colors', blank=True) class Meta: template = 'tmps/tmp_round_frame_text.html' icon = 'placeholder' label = 'Round Frame Text'
def test_form_response(self): block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') value = block.value_from_datadict({'advertwithcustomprimarykey': str(test_advert.pk)}, {}, 'advertwithcustomprimarykey') self.assertEqual(value, test_advert) empty_value = block.value_from_datadict({'advertwithcustomprimarykey': ''}, {}, 'advertwithcustomprimarykey') self.assertEqual(empty_value, None)
class CircleKeyValues(blocks.StructBlock): text_color = SnippetChooserBlock('home.Colors', blank=True) background_color = SnippetChooserBlock('home.Colors', blank=True) key_value = blocks.StreamBlock([('key_value', blocks.CharBlock())]) class Meta: template = 'tmps/tmp_circle_key_value_aum.html' icon = 'placeholder' label = 'Little Circles with Value'
def test_deserialize(self): """The serialized value of a SnippetChooserBlock (an ID) should deserialize to a snippet instance""" block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(block.to_python(test_advert.pk), test_advert) # None should deserialize to None self.assertEqual(block.to_python(None), None)
def test_serialize(self): """The value of a SnippetChooserBlock (a snippet instance) should serialize to an ID""" block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(block.get_prep_value(test_advert), test_advert.id) # None should serialize to None self.assertEqual(block.get_prep_value(None), None)
def test_deserialize(self): """The serialized value of a SnippetChooserBlock (an ID) should deserialize to a snippet instance""" block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(block.to_python(test_advert.pk), test_advert) # None should deserialize to None self.assertEqual(block.to_python(None), None)
def test_deserialize(self): """The serialized value of a SnippetChooserBlock (an ID) should deserialize to a snippet instance""" block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(block.to_python(test_advert.id), test_advert) # None should deserialize to None self.assertEqual(block.to_python(None), None)
def test_serialize(self): """The value of a SnippetChooserBlock (a snippet instance) should serialize to an ID""" block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(block.get_prep_value(test_advert), test_advert.id) # None should serialize to None self.assertEqual(block.get_prep_value(None), None)
def test_deserialize(self): """The serialized value of a SnippetChooserBlock (an ID) should deserialize to a snippet instance""" block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(block.to_python(test_advert.id), test_advert) # None should deserialize to None self.assertEqual(block.to_python(None), None)
def test_serialize(self): """The value of a SnippetChooserBlock (a snippet instance) should serialize to an ID""" block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(block.get_prep_value(test_advert), test_advert.pk) # None should serialize to None self.assertEqual(block.get_prep_value(None), None)
def test_form_response(self): block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') value = block.value_from_datadict({'advertwithcustomprimarykey': str(test_advert.pk)}, {}, 'advertwithcustomprimarykey') self.assertEqual(value, test_advert) empty_value = block.value_from_datadict({'advertwithcustomprimarykey': ''}, {}, 'advertwithcustomprimarykey') self.assertEqual(empty_value, None)
def test_form_response(self): block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') value = block.value_from_datadict({'advert': str(test_advert.id)}, {}, 'advert') self.assertEqual(value, test_advert) empty_value = block.value_from_datadict({'advert': ''}, {}, 'advert') self.assertEqual(empty_value, None)
def test_serialize(self): """The value of a SnippetChooserBlock (a snippet instance) should serialize to an ID""" block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(block.get_prep_value(test_advert), test_advert.pk) # None should serialize to None self.assertEqual(block.get_prep_value(None), None)
def test_form_response(self): block = SnippetChooserBlock(Advert) test_advert = Advert.objects.get(text='test_advert') value = block.value_from_datadict({'advert': str(test_advert.id)}, {}, 'advert') self.assertEqual(value, test_advert) empty_value = block.value_from_datadict({'advert': ''}, {}, 'advert') self.assertEqual(empty_value, None)
class CustomBlock2(blocks.StructBlock): field_link = PageChooserBlock(required=False) field_link_list = blocks.ListBlock(PageChooserBlock(), required=False) field_image = ImageChooserBlock(required=False) field_image_list = blocks.ListBlock(ImageChooserBlock(), required=False) field_snippet = SnippetChooserBlock(target_model=App2Snippet, required=False) field_snippet_list = blocks.ListBlock( SnippetChooserBlock(target_model=App2Snippet), required=False)
class CentralCircle(blocks.StructBlock): anchor = blocks.CharBlock(label='Id of object to use as activator', required=False) font_color = SnippetChooserBlock('home.Colors', blank=True) back_color = SnippetChooserBlock('home.Colors', blank=True) text_big = blocks.RichTextBlock(required=False) text_line1 = blocks.RichTextBlock(required=False) text_line2 = blocks.RichTextBlock(required=False) class Meta: template = 'tmps/tmp_centralcircle_aum.html'
class Comp_BigNumbAndTextTitle(blocks.StructBlock): text_color = SnippetChooserBlock('home.Colors', blank=True) text_mini_color = SnippetChooserBlock('home.Colors', blank=True) number_big = blocks.CharBlock(required=False) text_normal = blocks.RichTextBlock(required=False) text_title = blocks.CharBlock(required=False) class Meta: template = 'tmps/comp_bignumbtext_title.html' icon = 'placeholder' label = 'Big Number and Title with Sub'
class SimpleRecordsTable(blocks.StructBlock): field_text_color = SnippetChooserBlock('home.Colors', blank=True) detail_text_color = SnippetChooserBlock('home.Colors', blank=True) items = blocks.StreamBlock([ ('record', SimpleRecordsItem()), ]) class Meta: template = 'tmps/tmp_simple_records.html' icon = 'placeholder' label = 'Simple Records Table'
class GroupCards(blocks.StructBlock): text_color = SnippetChooserBlock('home.Colors', blank=True) index_color = SnippetChooserBlock('home.Colors', blank=True) background_color = SnippetChooserBlock('home.Colors', blank=True) cards = blocks.StreamBlock([('card', CardItem())]) class Meta: template = 'tmps/tmp_groupcards.html' icon = 'placeholder' label = 'Group Cards'
def test_form_render(self): block = SnippetChooserBlock(AdvertWithCustomPrimaryKey, help_text="pick an advert, any advert") empty_form_html = block.render_form(None, 'advertwithcustomprimarykey') self.assertInHTML('<input id="advertwithcustomprimarykey" name="advertwithcustomprimarykey" placeholder="" type="hidden" />', empty_form_html) self.assertIn('createSnippetChooser("advertwithcustomprimarykey", "tests/advertwithcustomprimarykey");', empty_form_html) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') test_advert_form_html = block.render_form(test_advert, 'advertwithcustomprimarykey') expected_html = '<input id="advertwithcustomprimarykey" name="advertwithcustomprimarykey" placeholder="" type="hidden" value="%s" />' % test_advert.pk self.assertInHTML(expected_html, test_advert_form_html) self.assertIn("pick an advert, any advert", test_advert_form_html)
def test_form_render(self): block = SnippetChooserBlock(AdvertWithCustomPrimaryKey, help_text="pick an advert, any advert") empty_form_html = block.render_form(None, 'advertwithcustomprimarykey') self.assertInHTML('<input id="advertwithcustomprimarykey" name="advertwithcustomprimarykey" placeholder="" type="hidden" />', empty_form_html) self.assertIn('createSnippetChooser("advertwithcustomprimarykey", "tests/advertwithcustomprimarykey");', empty_form_html) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') test_advert_form_html = block.render_form(test_advert, 'advertwithcustomprimarykey') expected_html = '<input id="advertwithcustomprimarykey" name="advertwithcustomprimarykey" placeholder="" type="hidden" value="%s" />' % test_advert.pk self.assertInHTML(expected_html, test_advert_form_html) self.assertIn("pick an advert, any advert", test_advert_form_html)
def test_form_render(self): block = SnippetChooserBlock(Advert, help_text="pick an advert, any advert") empty_form_html = block.render_form(None, 'advert') self.assertInHTML('<input id="advert" name="advert" placeholder="" type="hidden" />', empty_form_html) self.assertIn('createSnippetChooser("advert", "tests/advert");', empty_form_html) test_advert = Advert.objects.get(text='test_advert') test_advert_form_html = block.render_form(test_advert, 'advert') expected_html = '<input id="advert" name="advert" placeholder="" type="hidden" value="%d" />' % test_advert.id self.assertInHTML(expected_html, test_advert_form_html) self.assertIn("pick an advert, any advert", test_advert_form_html)
def test_form_render(self): block = SnippetChooserBlock(Advert, help_text="pick an advert, any advert") empty_form_html = block.render_form(None, 'advert') self.assertInHTML('<input id="advert" name="advert" placeholder="" type="hidden" />', empty_form_html) self.assertIn('createSnippetChooser("advert", "tests/advert");', empty_form_html) test_advert = Advert.objects.get(text='test_advert') test_advert_form_html = block.render_form(test_advert, 'advert') expected_html = '<input id="advert" name="advert" placeholder="" type="hidden" value="%d" />' % test_advert.id self.assertInHTML(expected_html, test_advert_form_html) self.assertIn("pick an advert, any advert", test_advert_form_html)
class MiniProfessorItem(blocks.StructBlock): name = blocks.CharBlock() subtitle = blocks.CharBlock(label="Professor of...") use_photo = blocks.BooleanBlock(required=False) image = ImageChooserBlock(required=False) letters = blocks.CharBlock( required=False, label="Inital Letter like AA if dont use picture") letters_color = SnippetChooserBlock('home.Colors', blank=True, required=False) letters_back = SnippetChooserBlock('home.Colors', blank=True, required=False) link = blocks.PageChooserBlock()
def test_clean(self): required_block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) nonrequired_block = SnippetChooserBlock(AdvertWithCustomPrimaryKey, required=False) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(required_block.clean(test_advert), test_advert) with self.assertRaises(ValidationError): required_block.clean(None) self.assertEqual(nonrequired_block.clean(test_advert), test_advert) self.assertEqual(nonrequired_block.clean(None), None)
def test_clean(self): required_block = SnippetChooserBlock(Advert) nonrequired_block = SnippetChooserBlock(Advert, required=False) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(required_block.clean(test_advert), test_advert) with self.assertRaises(ValidationError): required_block.clean(None) self.assertEqual(nonrequired_block.clean(test_advert), test_advert) self.assertEqual(nonrequired_block.clean(None), None)
class _S_WhyBlock(blocks.StructBlock): why_background = ColorBlock( null=True, blank=False, help_text="Select background color that contrasts text") why_head = blocks.CharBlock(null=True, blank=False, classname="full title", help_text="Bold header text") why_displayhead = blocks.BooleanBlock( null=True, blank=True, default=True, required=False, help_text="Whether or not to display the header") why_collum1 = Why_CollumBlock(null=True, blank=False, icon='cogs', help_text="Left block") why_collum2 = Why_CollumBlock(null=True, blank=False, icon='cogs', help_text="Middle block") why_collum3 = Why_CollumBlock(null=True, blank=False, icon='cogs', help_text="Right block") why_button = SnippetChooserBlock( Button, null=True, blank=True, required=False, help_text="Button displayed at why-section")
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 Shop_PricingcardBlock(blocks.StructBlock): shopcard_background = ColorBlock(null=True, blank=False, required=False, help_text="Select background color that contrasts text") shopcard_title = blocks.CharBlock(null=True, blank=False, required=False, classname="full title", help_text="Title of pricing card") shopcard_description = blocks.RichTextBlock(null=True, blank=False, required=False, help_text="Description of offer", classname="full") shopcard_price = blocks.DecimalBlock(null=True, blank=False, required=False, decimal_places=2, help="Price of the offer") shopcard_sucessmsg = blocks.RichTextBlock(null=True, blank=False, required=False, help_text="Success message", classname="full") shopcard_button = SnippetChooserBlock(Button, null=True, blank=False, required=False, help_text="Button displayed at the pricing-section")
class OfficeBlock(blocks.StructBlock): office = SnippetChooserBlock(Office) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context=parent_context) context["candidates"] = [a for a in CandidatePage.objects.live()] return context
class FooterCTABlock(blocks.StructBlock): cta = SnippetChooserBlock(target_model='cta.CallToAction') class Meta: template = "includes/footer_cta.html" label = "Footer Call to Action"
class BTOPage(Page): background_image = models.ForeignKey( "wagtailimages.Image", null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) author = models.CharField( max_length=64, default="William D. Torcaso", null=True, blank=True, ) body = StreamField( [ ("heading", CharBlock(classname="full title")), ("rtblock", RichTextBlock()), ("image", ImageChooserBlock()), ], null=True, blank=True, ) info_stream = StreamField( [("info_snippet", SnippetChooserBlock(BTOInfoSnippet))], null=True, blank=True, ) template = "BTOPage/bto_responsive_page_v2.html" content_panels = Page.content_panels + [ ImageChooserPanel("background_image"), FieldPanel("author"), StreamFieldPanel("body"), StreamFieldPanel("info_stream"), ]
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 _S_FeaturesBlock(blocks.StructBlock): features_background = ColorBlock( null=True, blank=False, help_text="Select background color that contrasts text") features_head = blocks.CharBlock(null=True, blank=False, classname="full title", help_text="Bold header text") features_displayhead = blocks.BooleanBlock( null=True, blank=True, default=True, required=False, help_text="Whether or not to display the header") features_subhead = blocks.CharBlock(null=True, blank=False, classname="full title", help_text="Smaller subhead text") features_displaysubhead = blocks.BooleanBlock( null=True, blank=True, default=True, required=False, help_text="Whether or not to display the header") features_button = SnippetChooserBlock( Button, null=True, blank=True, required=False, help_text="Button displayed at features-block") features_features = blocks.StreamBlock( [('feature', Features_FeatureBlock(null=True, blank=False))], null=True, blank=False)
def test_clean(self): required_block = SnippetChooserBlock(AdvertWithCustomPrimaryKey) nonrequired_block = SnippetChooserBlock(AdvertWithCustomPrimaryKey, required=False) test_advert = AdvertWithCustomPrimaryKey.objects.get(pk='advert/01') self.assertEqual(required_block.clean(test_advert), test_advert) with self.assertRaises(ValidationError): required_block.clean(None) self.assertEqual(nonrequired_block.clean(test_advert), test_advert) self.assertEqual(nonrequired_block.clean(None), None)
def test_clean(self): required_block = SnippetChooserBlock(Advert) nonrequired_block = SnippetChooserBlock(Advert, required=False) test_advert = Advert.objects.get(text='test_advert') self.assertEqual(required_block.clean(test_advert), test_advert) with self.assertRaises(ValidationError): required_block.clean(None) self.assertEqual(nonrequired_block.clean(test_advert), test_advert) self.assertEqual(nonrequired_block.clean(None), None)
def test_reference_model_by_string(self): block = SnippetChooserBlock('tests.Advert') test_advert = Advert.objects.get(text='test_advert') self.assertEqual(block.to_python(test_advert.id), test_advert)