class BankingStreamFieldPage(Page): body = StreamField([ ('paragraph', blocks.RichTextBlock()), ('bankrate_widget', BankrateWidgetBlock()), ('bankrate_cd_widget', BankrateCDRatesBlock()), ('bankrate_mortgage_widget', BankrateMortgageRatesBlock()), ('table_block', TableBlock(table_options=banking_table_options)), ]) comparisons = StreamField([ ('paragraph', blocks.RichTextBlock()), ('banking_comparison', BankingComparisonBlock()), ('bankrate_widget', BankrateWidgetBlock()), ('bankrate_cd_widget', BankrateCDRatesBlock()), ('bankrate_mortgage_widget', BankrateMortgageRatesBlock()), ('table_block', TableBlock(table_options=banking_table_options)), ], null=True, blank=True) parent_page_types = ['banking.BankingIndexPage'] class Meta: verbose_name = 'Banking and Savings Streamfield page' content_panels = Page.content_panels + [ StreamFieldPanel('body'), StreamFieldPanel('comparisons'), ]
class ArticlePage(common.GenericPage): class Meta: verbose_name = '呼吸疾病中心页面模板/一般文章页' template = 'ncrcrd/article.html' content = StreamField([ ('title', blocks.TitleBlock()), ('heading', blocks.HeadingBlock()), ('paragraph', blocks.ParagraphBlock()), ('image', blocks.ImageBlock()), ('person_card', blocks.PersonCardBlock()), ('organization_card', blocks.OrganizationCardBlock()), ('study_card', blocks.StudyCardBlock()), ('book_card', blocks.BookCardBlock()), ('table', TableBlock(label='表格')), ('table_corporation', TableBlock(label='协作单位表格', template='ncrcrd/blocks/table_corporation.html')), ('table_guide', TableBlock(label='指南规范表格', template='ncrcrd/blocks/table_guide.html')), ], verbose_name='正文') show_sidebar = models.BooleanField(default=True, verbose_name='显示侧边栏') show_breadcrumb = models.BooleanField(default=True, verbose_name='显示面包屑导航')
class TwoColumnPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('table', TableBlock()), ('image', ImageChooserBlock(icon="image")), ('embedded_video', EmbedBlock(icon="media")), ], blank=True) sidebar = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('table', TableBlock()), ('image', ImageChooserBlock(icon="image")), ('embedded_video', EmbedBlock(icon="media")), ], blank=True) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ] sidebar_panel = [ StreamFieldPanel('sidebar'), ] edit_handler = TabbedInterface([ ObjectList(content_panels, heading='Main'), ObjectList(sidebar_panel, heading='Sidebar'), ObjectList(Page.promote_panels, heading='Promote'), ObjectList(Page.settings_panels, heading='Settings', classname="settings"), ]) template = "wagtail-2-col.html"
def test_table_options_context_menu(self): """ Test how contextMenu is set to default. """ default_context_menu = list( DEFAULT_TABLE_OPTIONS["contextMenu"]) # create copy # confirm the default is correct table_options = TableBlock().table_options self.assertEqual(table_options["contextMenu"], default_context_menu) # confirm that when custom option is True, default is still used table_options_menu_true = TableBlock(table_options={ "contextMenu": True }).table_options self.assertEqual(table_options_menu_true["contextMenu"], default_context_menu) # confirm menu is removed if False is passed in table_options_menu_false = TableBlock(table_options={ "contextMenu": False }).table_options self.assertIs(table_options_menu_false["contextMenu"], False) # confirm if list passed in, it is used table_options_menu_list = TableBlock(table_options={ "contextMenu": ["undo", "redo"] }).table_options self.assertEqual(table_options_menu_list["contextMenu"], ["undo", "redo"]) # test if empty array passed in table_options_menu_list = TableBlock(table_options={ "contextMenu": [] }).table_options self.assertEqual(table_options_menu_list["contextMenu"], [])
class BlogPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('small_table', TableBlock(table_options=small_table)), ('large_table', TableBlock(table_options=large_table)), ]) thumbnail = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') tags = ClusterTaggableManager(through=BlogPageTag, blank=True) @property def intro(self): intro_text = '' blocks = self.body.stream_data for block in blocks: if block['type'] == "paragraph": intro_text = "   " + remove_html_tags( block['value'][:300]) + "..." break return intro_text @property def npcs(self): npcs = [n.npc for n in self.npc_blog_relationship.all()] return npcs @property def quests(self): quests = [q.quest for q in self.quest_blog_relationship.all()] return quests content_panels = Page.content_panels + [ StreamFieldPanel('body'), MultiFieldPanel([ FieldPanel('thumbnail'), ], heading="Thumbnail", classname="collapsible collapsed"), MultiFieldPanel([ InlinePanel('npc_blog_relationship'), InlinePanel('quest_blog_relationship'), ], heading="Blog Extras -- NPC's and Quests", classname="collapsible collapsed"), FieldPanel('tags', heading="Tags") ] def save(self, *args, **kwargs): if self.id is None: self.show_in_menus = True self.show_in_menus_default = True return super().save()
class CreditCardReview(RoutablePageMixin, Page): ''' The review of a card. Includes both the summary and the full review. Inherits from Page because it generates a page on the site. ''' card = models.OneToOneField(CreditCard, related_name='review', on_delete=models.PROTECT) intro = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('blockquote', blocks.BlockQuoteBlock()), ('table_block', TableBlock()), ], blank=True) body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('blockquote', blocks.BlockQuoteBlock()), ('table_block', TableBlock()), ]) pros = RichTextField(default='<ul><li></li></ul>') cons = RichTextField(default='<ul><li></li></ul>') tags = ClusterTaggableManager(through=CreditCardReviewTag, blank=True) content_panels = Page.content_panels + [ SnippetChooserPanel('card'), #FieldPanel('card', classname="full"), StreamFieldPanel('intro'), StreamFieldPanel('body'), FieldPanel('pros', classname="full"), FieldPanel('cons', classname="full"), FieldPanel('tags', classname="full"), ] @route(r'^card/$', name='conduit') def conduit(self, request): self.template = 'creditcards/credit_card_only.html' self.conduit = True return self.serve(request) @route(r'^$') #need default for revision view it seems def regular(self, request): return self.serve(request) @cached_property def conduit_url(self): subpage_url = self.reverse_subpage('conduit') if not self.url.endswith('/') and not subpage_url.startswith('/'): return self.url + '/' + subpage_url return self.url + subpage_url parent_page_types = ['creditcards.CreditCardIndex'] def disclosure(self): return disclosure_generator(self.card.processing_network)
def test_is_html_renderer(self): """ Test that settings flow through correctly to the is_html_renderer method. """ # TableBlock with default table_options block1 = TableBlock() self.assertIs(block1.is_html_renderer(), False) # TableBlock with altered table_options new_options = self.default_table_options.copy() new_options["renderer"] = "html" block2 = TableBlock(table_options=new_options) self.assertIs(block2.is_html_renderer(), True)
def test_table_options_others(self): """ Test simple options overrides get passed correctly. """ block_1_opts = TableBlock(table_options={'startRows': 5, 'startCols': 2}).table_options self.assertEqual(block_1_opts['startRows'], 5) self.assertEqual(block_1_opts['startCols'], 2) block_2_opts = TableBlock(table_options={'stretchH': 'none'}).table_options self.assertEqual(block_2_opts['stretchH'], 'none') # check value that is not part of the defaults block_3_opts = TableBlock(table_options={'allowEmpty': False}).table_options self.assertEqual(block_3_opts['allowEmpty'], False)
def test_table_block_alignment_render(self): """ Test a generic render with some cells aligned. """ value = { "first_row_is_table_header": True, "first_col_is_header": False, "cell": [ {"row": 0, "col": 1, "className": "htLeft"}, {"row": 1, "col": 1, "className": "htRight"}, ], "data": [ ["Test 1", "Test 2", "Test 3"], [None, None, None], [None, None, None], ], } block = TableBlock() result = block.render(value) expected = """ <table> <thead> <tr><th scope="col">Test 1</th><th scope="col" class="htLeft">Test 2</th><th scope="col">Test 3</th></tr> </thead> <tbody> <tr><td></td><td class="htRight"></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn("Test 2", result)
def test_table_options_others(self): """ Test simple options overrides get passed correctly. """ block_1_opts = TableBlock( table_options={"startRows": 5, "startCols": 2} ).table_options self.assertEqual(block_1_opts["startRows"], 5) self.assertEqual(block_1_opts["startCols"], 2) block_2_opts = TableBlock(table_options={"stretchH": "none"}).table_options self.assertEqual(block_2_opts["stretchH"], "none") # check value that is not part of the defaults block_3_opts = TableBlock(table_options={"allowEmpty": False}).table_options self.assertIs(block_3_opts["allowEmpty"], False)
class BaseStoryBlock(blocks.StreamBlock): heading = blocks.CharBlock( form_classname="full title", help_text= ("The link to this heading uses the heading text in lowercase, with no" " symbols, and with the spaces replaced with hyphens." ' e.g. "Lorem @ 2 ipsum" becomes "lorem-2-ipsum"'), icon="title", template="patterns/molecules/streamfield/blocks/heading_block.html", group="Heading", label="Main heading", ) subheading = blocks.CharBlock( form_classname="full title", help_text= ("The link to this subheading uses the subheading text in lowercase, with no" " symbols, and with the spaces replaced with hyphens." ' e.g. "Lorem @ 2 ipsum" becomes "lorem-2-ipsum"'), icon="title", template="patterns/molecules/streamfield/blocks/subheading_block.html", group="Heading", ) paragraph = blocks.RichTextBlock(features=RICH_TEXT_FEATURES, ) image = ImageBlock() embed = EmbedBlock() local_area_links = LocalAreaLinksBlock() table = TableBlock() button = ButtonBlock() highlight = HighlightBlock() class Meta: abstract = True template = "patterns/molecules/streamfield/stream_block.html"
def test_column_headers(self): """ Ensure that column headers are properly rendered. """ value = { "first_row_is_table_header": False, "first_col_is_header": True, "data": [ ["Foo", "Bar", "Baz"], ["one", "two", "three"], ["four", "five", "six"], ], } expected = """ <table> <tbody> <tr><th scope="row">Foo</th><td>Bar</td><td>Baz</td></tr> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_table_block_alignment_render(self): """ Test a generic render with some cells aligned. """ value = {'first_row_is_table_header': True, 'first_col_is_header': False, 'cell': [{'row': 0, 'col': 1, 'className': 'htLeft'}, {'row': 1, 'col': 1, 'className': 'htRight'}], 'data': [['Test 1', 'Test 2', 'Test 3'], [None, None, None], [None, None, None]]} block = TableBlock() result = block.render(value) expected = """ <table> <thead> <tr><th>Test 1</th><th class="htLeft">Test 2</th><th>Test 3</th></tr> </thead> <tbody> <tr><td></td><td class="htRight"></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn('Test 2', result)
def test_row_and_column_headers(self): """ Test row and column headers at the same time. """ value = { 'first_row_is_table_header': True, 'first_col_is_header': True, 'data': [['Foo', 'Bar', 'Baz'], ['one', 'two', 'three'], ['four', 'five', 'six']] } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_searchable_content(self): value = {'first_row_is_table_header': False, 'first_col_is_header': False, 'data': [['Test 1', 'Test 2', 'Test 3'], [None, 'Bar', None], [None, 'Foo', None]]} block = TableBlock() content = block.get_searchable_content(value) self.assertEqual(content, ['Test 1', 'Test 2', 'Test 3', 'Bar', 'Foo', ])
class DonorSchedulePage(AbstractBase): body = StreamField(block_types=[ ('heading', Heading(classname='full title', help_text=_('Text will be green and centered'))), ('emphatic_text', EmphaticText(classname='full title', help_text=_('Text will be red, italic and centered'))), ('paragraph', AlignedParagraphBlock(required=True, classname='paragraph')), ('image', ImageChooserBlock()), ('html', blocks.RawHTMLBlock()), ('table', TableBlock(table_options=donor_schedule_table_options, help_text=_("Right-click to add/remove rows/columns"))), ('concerts', SimpleConcertStreamBlock()), ], blank=False) content_panels = AbstractBase.content_panels + [ StreamFieldPanel('body'), ] search_fields = AbstractBase.search_fields + [ index.SearchField('body'), ]
class ResourceBlock(blocks.StructBlock): """A section of a ResourcePage""" title = blocks.CharBlock(required=True) hide_title = blocks.BooleanBlock( required=False, help_text='Should the section title be displayed?') content = blocks.StreamBlock([ ('text', blocks.RichTextBlock(blank=False, null=False, required=False, icon='pilcrow')), ('documents', blocks.ListBlock(ThumbnailBlock(), template='blocks/section-documents.html', icon='doc-empty')), ('contact_info', ContactInfoBlock()), ('internal_button', InternalButtonBlock()), ('external_button', ExternalButtonBlock()), ('page', blocks.PageChooserBlock(template='blocks/page-links.html')), ('document_list', blocks.ListBlock(FeedDocumentBlock(), template='blocks/document-list.html', icon='doc-empty')), ('current_commissioners', CurrentCommissionersBlock()), ('fec_jobs', CareersBlock()), ('table', TableBlock()) ]) aside = blocks.StreamBlock( [('title', blocks.CharBlock(required=False, icon='title')), ('document', ThumbnailBlock()), ('link', AsideLinkBlock())], template='blocks/section-aside.html', icon='placeholder') class Meta: template = 'blocks/section.html'
def test_row_headers(self): """ Ensure that row headers are properly rendered. """ value = { 'first_row_is_table_header': True, 'first_col_is_header': False, 'data': [['Foo', 'Bar', 'Baz'], [None, None, None], [None, None, None]] } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_column_headers(self): """ Ensure that column headers are properly rendered. """ value = { 'first_row_is_table_header': False, 'first_col_is_header': True, 'data': [['Foo', 'Bar', 'Baz'], ['one', 'two', 'three'], ['four', 'five', 'six']] } expected = """ <table> <tbody> <tr><th scope="row">Foo</th><td>Bar</td><td>Baz</td></tr> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_do_not_render_html(self): """ Ensure that raw html doesn't render by default. """ value = { "first_row_is_table_header": False, "first_col_is_header": False, "data": [ ["<p><strong>Test</strong></p>", None, None], [None, None, None], [None, None, None], ], } expected = """ <table> <tbody> <tr><td><p><strong>Test</strong></p></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_table_block_render(self): """ Test a generic render. """ value = { 'first_row_is_table_header': False, 'first_col_is_header': False, 'data': [['Test 1', 'Test 2', 'Test 3'], [None, None, None], [None, None, None]] } block = TableBlock() result = block.render(value) expected = """ <table> <tbody> <tr><td>Test 1</td><td>Test 2</td><td>Test 3</td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn('Test 2', result)
class ResourceBlock(blocks.StructBlock): """A section of a ResourcePage""" title = blocks.CharBlock(required=True) hide_title = blocks.BooleanBlock(required=False, help_text='Should the section title be displayed?') content = blocks.StreamBlock([ ('text', blocks.RichTextBlock(blank=False, null=False, required=False, icon='pilcrow')), ('documents', blocks.ListBlock(ThumbnailBlock(), template='blocks/section-documents.html', icon='doc-empty')), ('contact_info', ContactInfoBlock()), ('internal_button', InternalButtonBlock()), ('external_button', ExternalButtonBlock()), ('page', blocks.PageChooserBlock(template='blocks/page-links.html')), ('disabled_page', blocks.CharBlock(blank=False, null=False, required=False, template='blocks/disabled-page-links.html', icon='placeholder', help_text='Name of a disabled link')), ('document_list', blocks.ListBlock(FeedDocumentBlock(), template='blocks/document-list.html', icon='doc-empty')), ('current_commissioners', CurrentCommissionersBlock()), ('fec_jobs', CareersBlock()), ('mur_search', MURSearchBlock()), ('table', TableBlock()), ('html', blocks.RawHTMLBlock()), ('reporting_example_cards', ReportingExampleCards()), ('contribution_limits_table', SnippetChooserBlock('home.EmbedTableSnippet', template = 'blocks/embed-table.html', icon='table')), ]) aside = blocks.StreamBlock([ ('title', blocks.CharBlock(required=False, icon='title')), ('document', ThumbnailBlock()), ('link', AsideLinkBlock()), ], template='blocks/section-aside.html', icon='placeholder') class Meta: template = 'blocks/section.html'
def test_row_headers(self): """ Ensure that row headers are properly rendered. """ value = { "first_row_is_table_header": True, "first_col_is_header": False, "data": [["Foo", "Bar", "Baz"], [None, None, None], [None, None, None]], } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
class ContentPage(Page): sub_header = models.CharField(max_length=50, default="") body = StreamField([ ('heading', blocks.CharBlock(icon='title')), ('rich_text', blocks.RichTextBlock( features=[ 'bold', 'italic', 'h2', 'h3', 'h4', 'ol', 'ul', 'hr', 'embed', 'link', 'document-link', 'image', 'code', ], )), ('image', ImageChooserBlock()), ('quote', QuoteBlock()), ('table', TableBlock()), ]) content_panels = Page.content_panels + [ FieldPanel('sub_header'), StreamFieldPanel('body'), ]
def test_row_and_column_headers(self): """ Test row and column headers at the same time. """ value = { "first_row_is_table_header": True, "first_col_is_header": True, "data": [ ["Foo", "Bar", "Baz"], ["one", "two", "three"], ["four", "five", "six"], ], } expected = """ <table> <thead> <tr><th scope="col">Foo</th><th scope="col">Bar</th><th scope="col">Baz</th></tr> </thead> <tbody> <tr><th scope="row">one</th><td>two</td><td>three</td></tr> <tr><th scope="row">four</th><td>five</td><td>six</td></tr> </tbody> </table> """ block = TableBlock() result = block.render(value) self.assertHTMLEqual(result, expected)
def test_render_empty_table(self): """ An empty table should render okay. """ block = TableBlock() result = block.render(self.default_value) self.assertHTMLEqual(result, self.default_expected)
def test_table_block_caption_render(self): """ Test a generic render with caption. """ value = { "table_caption": "caption", "first_row_is_table_header": False, "first_col_is_header": False, "data": [ ["Test 1", "Test 2", "Test 3"], [None, None, None], [None, None, None], ], } block = TableBlock() result = block.render(value) expected = """ <table> <caption>caption</caption> <tbody> <tr><td>Test 1</td><td>Test 2</td><td>Test 3</td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </tbody> </table> """ self.assertHTMLEqual(result, expected) self.assertIn("Test 2", result)
class TableModuleBlock(blocks.StructBlock): table = TableBlock() class Meta: template = "streams/table_block.html" icon = "list-ul" label = "Table module"
class DefaultPage(RoutablePageMixin, Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock("")), ('image', ImageChooserBlock()), ('table', TableBlock(template='core/tableblock.html')), ]) tags = ClusterTaggableManager(through=DefaultPageTag, blank=True) date = models.DateField("Post date", default=datetime.datetime.today) feed_image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') api_fields = ['body', 'tags', 'date', 'feed_image'] content_panels = Page.content_panels + [ FieldPanel('date'), StreamFieldPanel('body'), ] promote_panels = Page.promote_panels + [ ImageChooserPanel('feed_image'), FieldPanel('tags'), ] search_fields = Page.search_fields + [ index.SearchField('body'), ] class Meta: verbose_name = "Standard page"
class BlogPostPage(HeadlessPreviewMixin, PageBase): author = models.CharField( verbose_name="Author", max_length=255, blank=True, ) hero_image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') content = StreamField([('image', APIImageChooserBlock()), ('markdown', APIMarkDownBlock()), ('richText', APIRichTextBlock()), ('table', TableBlock())], null=True, blank=True) content_panels = Page.content_panels + [ FieldPanel('author'), ImageChooserPanel('hero_image'), StreamFieldPanel('content') ] search_fields = Page.search_fields + [ index.SearchField('content'), ] api_fields = [ APIField('author'), APIField('hero_image'), APIField('content') ]