class CommissionerPage(Page): first_name = models.CharField(max_length=255, default='', blank=False) middle_initial = models.CharField(max_length=255, blank=True) last_name = models.CharField(max_length=255, default='', blank=False) picture = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') sworn_in = models.DateField(null=True, blank=True) term_expiration = models.DateField(null=True, blank=True) reappointed_dates = models.CharField(max_length=255, blank=True) party_affiliation = models.CharField(max_length=2, choices=( ('D', 'Democrat'), ('R', 'Republican'), ('I', 'Independent'), )) commissioner_title = models.CharField(max_length=255, blank=True) commissioner_bio = StreamField([('paragraph', blocks.RichTextBlock())], null=True, blank=True) commissioner_email = models.CharField(max_length=255, blank=True) commissioner_phone = models.CharField(max_length=255, null=True, blank=True) commissioner_twitter = models.CharField(max_length=255, null=True, blank=True) content_panels = Page.content_panels + [ FieldPanel('first_name'), FieldPanel('middle_initial'), FieldPanel('last_name'), ImageChooserPanel('picture'), FieldPanel('sworn_in'), FieldPanel('term_expiration'), FieldPanel('reappointed_dates'), FieldPanel('party_affiliation'), FieldPanel('commissioner_title'), StreamFieldPanel('commissioner_bio'), FieldPanel('commissioner_email'), FieldPanel('commissioner_phone'), FieldPanel('commissioner_twitter'), ] def get_context(self, request): context = super(CommissionerPage, self).get_context(request) # Breadcrumbs for Commissioner pages context['ancestors'] = [{ 'title': 'About the FEC', 'url': '/about/', }, { 'title': 'Leadership and Structure', 'url': '/about/leadership-and-structure', }, { 'title': 'All Commissioners', 'url': '/about/leadership-and-structure/commissioners', }] return context
class CustomPage(Page): """Flexible customizable page.""" author = models.CharField(max_length=255) date = models.DateField('Creation date') body = StreamField([ ('heading', blocks.CharBlock(classname='full title')), ('paragraph', blocks.RichTextBlock()), ('html', blocks.RawHTMLBlock()), ('image', ImageChooserBlock()), ('table', TableBlock()), ('example_paragraph', ExampleParagraph()), ('example_forms', ExampleForms()), ('reporting_example_cards', ReportingExampleCards()), ('contact_info', ContactInfoBlock()), ('internal_button', InternalButtonBlock()), ('external_button', ExternalButtonBlock()), ('contribution_limits_table', SnippetChooserBlock('home.EmbedTableSnippet', template='blocks/embed-table.html', icon='table')), ]) sidebar = stream_factory(null=True, blank=True) related_topics = StreamField( [('related_topics', blocks.ListBlock(blocks.PageChooserBlock(label="Related topic")))], null=True, blank=True) citations = StreamField( [('citations', blocks.ListBlock(CitationsBlock()))], null=True, blank=True) record_articles = StreamField( [('record_articles', blocks.ListBlock(blocks.PageChooserBlock(target_model=RecordPage)))], null=True, blank=True) continue_learning = StreamField([ ('continue_learning', blocks.ListBlock(ThumbnailBlock(), icon='doc-empty')), ], null=True, blank=True) show_contact_link = models.BooleanField(max_length=255, default=True, null=False, blank=False, choices=[ (True, 'Show contact link'), (False, 'Do not show contact link') ]) content_panels = Page.content_panels + [ FieldPanel('author'), FieldPanel('date'), StreamFieldPanel('body'), StreamFieldPanel('related_topics'), StreamFieldPanel('citations'), StreamFieldPanel('continue_learning'), MultiFieldPanel([ StreamFieldPanel('sidebar'), StreamFieldPanel('record_articles'), FieldPanel('show_contact_link'), ], heading="Sidebar", classname="collapsible") ] # Adds a settings field for making a custom title that displays in the Wagtail page explorer menu_title = models.CharField(max_length=255, null=True) settings_panels = Page.settings_panels + [FieldPanel('menu_title')] def get_admin_display_title(self): return self.menu_title if self.menu_title else self.title @property def content_section(self): return get_content_section(self)
def __init__(self, block_types=None, **kwargs): block_types = [ ('Paragraph', blocks.RichTextBlock(icon="doc-full")), ] super(BioField, self).__init__(block_types, **kwargs)
from fec import constants logger = logging.getLogger(__name__) from home.blocks import (ThumbnailBlock, AsideLinkBlock, ContactInfoBlock, CitationsBlock, ResourceBlock, OptionBlock, CollectionBlock, DocumentFeedBlurb, ExampleParagraph, ExampleForms, ExampleImage, CustomTableBlock, ReportingExampleCards, InternalButtonBlock, ExternalButtonBlock, SnippetChooserBlock) stream_factory = functools.partial( StreamField, [('heading', blocks.CharBlock(classname='full title')), ('paragraph', blocks.RichTextBlock()), ('html', blocks.RawHTMLBlock()), ('image', ImageChooserBlock()), ('table', TableBlock()), ('custom_table', CustomTableBlock())], ) def get_content_section(page): """ Find the top-level parent in order to highlight the main nav item and set social images. Takes a Page object and returns a string of either 'legal', 'help', or '' """ slugs = { 'help-candidates-and-committees': 'help', 'legal-resources': 'legal' }
class YoutubeRegretsPage(FoundationMetadataPageMixin, Page): headline = models.CharField( max_length=500, help_text='Page headline', blank=True, ) intro_text = StreamField([ ('text', blocks.CharBlock()), ]) intro_images = StreamField([ ('image', customblocks.ImageBlock()), ]) faq = StreamField( [('paragraph', blocks.RichTextBlock(features=[ 'bold', 'italic', 'h2', 'h3', 'h4', 'h5', 'ol', 'ul', 'link', 'hr', ]))], blank=True, ) regret_stories = StreamField([ ('regret_story', customblocks.YoutubeRegretBlock()), ]) content_panels = Page.content_panels + [ FieldPanel('headline'), StreamFieldPanel('intro_text'), StreamFieldPanel('intro_images'), StreamFieldPanel('faq'), StreamFieldPanel('regret_stories'), ] translatable_fields = [ # Promote tab fields SynchronizedField('slug'), TranslatableField('seo_title'), SynchronizedField('show_in_menus'), TranslatableField('search_description'), SynchronizedField('search_image'), # Content tab fields TranslatableField('title'), TranslatableField('headline'), TranslatableField('intro_text'), TranslatableField('intro_images'), TranslatableField('faq'), TranslatableField('regret_stories'), ] zen_nav = True def get_context(self, request): context = super().get_context(request) return set_main_site_nav_information(self, context, 'Homepage') template = 'wagtailpages/pages/youtube_regrets_page.html'