class LinkBlock(blocks.StructBlock): external_link = blocks.URLBlock(required=False) page = blocks.PageChooserBlock(required=False) document = DocumentChooserBlock(required=False) text = blocks.CharBlock(required=False) button_style = blocks.ChoiceBlock( choices=(('button', 'Default'), ('button button-primary', 'Primary'), ('button button-secondary', 'Secondary')), required=False) class Meta: template = 'general/blocks/link.html' icon = 'link'
class HomePage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('page', blocks.PageChooserBlock()), ('document', DocumentChooserBlock()), ('media', EmbedBlock()), ('html', blocks.RawHTMLBlock(label='Raw HTML')), ]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ]
class StoryStreamBlock(StreamBlock): subheadline = CharBlock(icon="title", classname="title") embedded_image = EmbeddedImageBlock() h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") classy_paragraph = ClassyParagraph(icon="pilcrow") image = ImageBlock(label="Image", icon="image") aligned_html = AlignedHTMLBlock(icon="code", label='Raw HTML') embed = EmbedBlock(help_text="URL for media to embed") document = DocumentChooserBlock(icon="doc-full-inverse") image_gallery = ImageGalleryBlock(ImageGalleryItemBlock)
class ExamplePage(Page): content = StreamField([ ('image', ImageChooserBlock()), ('text', RichTextBlock()), ('docs', StreamBlock([ ('doc', DocumentChooserBlock()), ('page', PageChooserBlock()), ])), ]) content_panels = Page.content_panels + [ StreamFieldPanel('content'), ]
class BlogStreamBlock(StreamBlock): h2 = Heading2Block(icon="title", classname="title") h3 = Heading3Block(icon="title", classname="title") h4 = Heading4Block(icon="title", classname="title") hr = HRuleBlock() paragraph = RichTextBlock(icon="pilcrow", features=PARAGRAPH_FEATURES) image = ImageChooserBlock() pullquote = PullQuoteBlock() document = DocumentChooserBlock(icon="doc-full-inverse") code = CodeBlock() table = HtmlTableBlock(table_options=TABLE_SETTINGS) collapsible = CollapsibleBlock() callout = CalloutBlock() html = HTMLBlock()
class BlogStreamBlock(StreamBlock): h2 = CharBlock(icon='title', classname='title') h3 = CharBlock(icon='title', classname='title') h4 = CharBlock(icon='title', classname='title') paragraph = RichTextBlock(icon='pilcrow') credit_image = CreditImageBlock() plain_image = PlainImageBlock() pullquote = PullQuoteBlock() document = DocumentChooserBlock(icon='doc-full-inverse') table = TableBlock(table_options={ 'startRows': 1, 'startCols': 4, }, template='blocks/table_block.html')
class BaseStreamBlock(StreamBlock): heading_block = HeadingBlock() intro = RichTextBlock(icon="pilcrow") paragraph_block = RichTextBlock(icon="form", template="blocks/block_paragraph.html") aligned_image = BaseImageBlock(label=_('Aligned image'), icon="image") aligned_html = RawHTMLBlock(icon="code", label='Raw HTML') document = DocumentChooserBlock(icon="doc-full-inverse") block_quote = BlockQuote() block_parallax = BaseParallaxBlock() embed_block = EmbedBlock( help_text= 'Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon="placeholder", template="blocks/block_embed.html")
class ColumnBlock(blocks.StreamBlock): 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')) aligned_paragraph = AlignedParagraphBlock() paragraph = blocks.RichTextBlock() image = ImageChooserBlock() document = DocumentChooserBlock() button = ButtonBlock() html = blocks.RawHTMLBlock() class Meta: template = 'blocks/column.html'
class PDFBlock(StructBlock): file = DocumentChooserBlock() description = CharBlock() def get_context(self, value, parent_context=None): context = super(PDFBlock, self).get_context(value, parent_context=parent_context) context['button'] = {'text': 'Download', 'href': value.get('file').url} context['description'] = value.get('description') context['fontawesome'] = 'file-pdf-o' return context class Meta: icon = 'fa fa-file-pdf-o' template = 'widgets/download-link.html'
class ListAndButtonBlock(blocks.StructBlock): """List and buttons of main""" title = blocks.CharBlock(required=True) points = blocks.ListBlock( blocks.StructBlock([ ("point", blocks.CharBlock(required=True, max_length=200)), ("pdfs", blocks.ListBlock(DocumentChooserBlock(required=True), )) ])) class Meta: #noqa template = "streams/list_and_button.html" icon = "edit" label = "GR Text & Documents"
class HomePageStreamBlock(StreamBlock): h2styled = CharBlock(label='stilisert overskrift', icon='title', classname='title') h2 = CharBlock(label='overskrift stor', icon='title', classname='title') h3 = CharBlock(label='overskrift mindre', icon='title', classname='title') h4 = CharBlock(label='overskrift minst', icon='title', classname='title') hr = HorizontalRulerBlock() intro = RichTextBlock(label='introduksjon', icon='pilcrow') paragraph = RichTextBlock(label='paragraf', icon='pilcrow') pullquote = PullQuoteBlock(label='Sitat') aligned_image = ImageBlock(label='Justert bilde', icon='image') document = DocumentChooserBlock(label='dokument', icon='doc-full-inverse') markdown = MarkDownBlock(label='markdown') news_feed = NewsFeedBlock(label='Siste nyheter', icon='grip')
class Resource(Orderable): page = ParentalKey(ActivityPage, on_delete=models.CASCADE, related_name="resources") content = StreamField([ ("heading", blocks.CharBlock()), ("paragraph", blocks.RichTextBlock()), ("embed", EmbedBlock()), ("image", ImageChooserBlock()), ("document", DocumentChooserBlock()), ]) panels = [ StreamFieldPanel('content'), ]
class BureauStructure(blocks.StructBlock): last_updated_date = blocks.DateBlock(required=False) download_image = DocumentChooserBlock(icon='image', required=False) director = blocks.CharBlock() divisions = blocks.ListBlock(BureauStructureDivision()) office_of_the_director = blocks.ListBlock(BureauStructureOffices(), label='Office of the Director') class Meta: icon = None template = '_includes/organisms/bureau-structure.html' icon = "table" class Media: js = ['bureau-structure.js']
class DocumentBlock(blocks.StructBlock): """document block""" title = blocks.CharBlock(required=True) points = blocks.ListBlock( blocks.StructBlock([ ("point", blocks.CharBlock(required=True, max_length=200)), ("doc_upload", DocumentChooserBlock(required=True)), ])) class Meta: #noqa template = "streams/document.html" icon = "edit" label = " Documents"
class DownloadBlock(blocks.StructBlock): """ Link to a file that can be downloaded. """ button_title = blocks.CharBlock(max_length=25, required=True, help_text="Text to go on download button") downloadable_file = DocumentChooserBlock(required=True, help="Document to download") class Meta: template = "streams/download_block.html" icon = "download" help_text = "Display a button that downloads a file"
class ProgramDocuments(models.Model): """ List of documents associated with a program .. no_pii: """ display = models.BooleanField( blank=False, null=False, default=True, verbose_name="Display Program Documents", ) header = models.CharField( max_length=128, blank=False, null=False, default="Program Documents", verbose_name="Header for Program Documents", ) documents = StreamField( [ ('file', StructBlock( [ ('display_text', CharBlock()), ('document', DocumentChooserBlock()) ], icon='doc-full' )), ('link', StructBlock( [ ('display_text', CharBlock()), ('url', URLBlock()), ], icon='link' )) ], blank=True, verbose_name="Documents" ) page = ParentalKey(ProgramPage, on_delete=models.CASCADE, related_name='program_documents', unique=True) panels = [ FieldPanel('display'), FieldPanel('header'), StreamFieldPanel('documents'), ]
class ContentStreamBlock(StreamBlock): paragraph = RichTextBlock(icon='fa-paragraph') heading = TextBlock(icon='fa-header', template='blocks/heading.html') smaller_heading = TextBlock(icon='fa-header', template='blocks/smaller_heading.html') smallest_heading = TextBlock(icon='fa-header', template='blocks/smallest_heading.html') image = CaptionedImageBlock() download = DocumentChooserBlock(icon='fa-download', template='blocks/download.html') accordion = AccordionBlock() notice = NoticeBlock() embed = EmbedBlock(icon="media") button = CallToActionButtonBlock() class Meta: template = 'blocks/streamfield.html'
class LibraryItem(Page): publication_date = models.DateField("Publication date") body = StreamField([ ("paragraph", blocks.RichTextBlock()), ("image", ImageChooserBlock()), ("document", DocumentChooserBlock()), ("embed", EmbedBlock()), ("url", blocks.URLBlock()), ("quote", blocks.BlockQuoteBlock()), ]) item_audience = models.ForeignKey("facets.Audience", on_delete=models.SET_NULL, null=True) item_genre = models.ForeignKey("facets.Genre", on_delete=models.SET_NULL, null=True) item_medium = models.ForeignKey("facets.Medium", on_delete=models.SET_NULL, null=True) item_time_period = models.ForeignKey("facets.TimePeriod", on_delete=models.SET_NULL, null=True) content_panels = Page.content_panels + [ InlinePanel( "authors", heading="Authors", help_text= "Select one or more authors, who contributed to this article", ), FieldPanel("publication_date"), StreamFieldPanel("body"), MultiFieldPanel( children=[ FieldPanel("item_audience"), FieldPanel("item_genre"), FieldPanel("item_medium"), FieldPanel("item_time_period"), InlinePanel("topics", label="topics") ], heading="Categorization", ), ] parent_page_types = ["LibraryIndexPage"] subpage_types = []
class HeroBlock(BaseBlock): background_image = ImageChooserBlock() text = blocks.TextBlock(required=False) button_page = blocks.PageChooserBlock(required=False) button_text = blocks.TextBlock(required=False) use_img_overlay = blocks.BooleanBlock(default=True, required=False) show_logo = blocks.BooleanBlock(default=True, required=False) slides_interval = blocks.IntegerBlock(default=0, help_text="The duration between slide cycles (in milliseconds, use 0 for no transition)") slides = blocks.ListBlock( blocks.StructBlock([ ('image', DocumentChooserBlock()), ('text', blocks.TextBlock(required=False)), ], label="slides"), required=False )
class DocumentBlock(StructBlock): title = RichTextBlock(required=False) document = DocumentChooserBlock() summary = RichTextBlock(required=False) class Meta: icon = 'doc' template = 'blocks/document_block.html' help_text = 'Choose or upload a document' def get_context(self, value, parent_context): context = super().get_context(value, parent_context) context['file_ext'] = value['document'].file_extension context['file_size'] = filesizeformat( value['document'].get_file_size()) return context
class BaseStreamBlock(StreamBlock): """ Define the custom blocks that `StreamField` will utilize """ required = False heading_block = HeadingBlock() paragraph_block = RichTextBlock(icon="fa-paragraph", template="blocks/paragraph_block.html") image_block = ImageBlock() block_quote = BlockQuote() embed_block = EmbedBlock( help_text= 'Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon="fa-s15", template="blocks/embed_block.html") html_block = RawHTMLBlock() document_block = DocumentChooserBlock()
class TestStreamBlock(blocks.StreamBlock): test_charblock = blocks.CharBlock(max_length=255) test_textblock = blocks.TextBlock(label=gettext_lazy("text block")) test_emailblock = blocks.EmailBlock() test_urlblock = blocks.URLBlock() test_richtextblock = blocks.RichTextBlock() test_rawhtmlblock = blocks.RawHTMLBlock() test_blockquoteblock = blocks.BlockQuoteBlock() test_structblock = TestStructBlock() test_listblock = blocks.ListBlock(blocks.TextBlock()) test_nestedstreamblock = TestNestedStreamBlock() test_customstructblock = CustomStructBlock() test_customblockwithoutextractmethod = CustomBlockWithoutExtractMethod() test_pagechooserblock = blocks.PageChooserBlock() test_imagechooserblock = ImageChooserBlock() test_documentchooserblock = DocumentChooserBlock() test_snippetchooserblock = SnippetChooserBlock(TestSnippet)
class CMSStreamBlock(StreamBlock): h2 = CharBlock(icon='title', classname='title') h3 = CharBlock(icon='title', classname='title') h4 = CharBlock(icon='title', classname='title') h5 = CharBlock(icon='title', classname='title') intro = RichTextBlock(icon='pilcrow') paragraph = RichTextBlock(icon='pilcrow') pullquote = PullQuoteBlock() image = ImageBlock(label='Aligned image', icon='image') document = DocumentChooserBlock(icon='doc-full-inverse') page = PageLinkBlock(icon='link') embed = EmbedBlock(icon='media') html = AlignedHTMLBlock(icon='code', label='Raw HTML') map_html = AlignedHTMLBlock(icon='code', label='Map HTML')
class BasicPage( Page, BasicPageAbstract, FeatureablePageAbstract, ShareablePageAbstract, ): """Page with StreamField body""" related_files = StreamField( [ ('file', DocumentChooserBlock()), ], blank=True, ) content_panels = [ BasicPageAbstract.title_panel, BasicPageAbstract.body_panel, BasicPageAbstract.images_panel, MultiFieldPanel( [ StreamFieldPanel('related_files'), ], heading='Related Files', classname='collapsible collapsed', ), ] promote_panels = Page.promote_panels + [ FeatureablePageAbstract.feature_panel, ShareablePageAbstract.social_panel, ] parent_page_types = ['core.BasicPage', 'core.HomePage'] subpage_types = [ 'core.AnnualReportListPage', 'core.BasicPage', 'core.FundingPage', 'people.PersonListPage', 'research.ProjectPage', ] template = 'core/basic_page.html' class Meta: verbose_name = 'Page' verbose_name_plural = 'Pages'
class StandardPage(Page): section = StreamField([ ('heading', HeadingBlock()), ('paragraph', blocks.RichTextBlock()), ('quote', blocks.BlockQuoteBlock()), ('image', ImageChooserBlock()), ('document', DocumentChooserBlock()), ('embed', EmbedBlock()), ('table', TableBlock()), ('person', SnippetChooserBlock(Person)), ('event', blocks.StaticBlock(admin_text='Latest events: no configuration needed.', template='')), ], blank=True) person = models.ForeignKey( 'Person', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) # event = models.ForeignKey( # 'Event', # null=True, # blank=True, # on_delete=models.SET_NULL, # related_name='+' # ) content_panels = Page.content_panels + [ StreamFieldPanel('section'), InlinePanel('person_placements', label="people"), # SnippetChooserPanel('event'), ]
class BrochureBlock(blocks.StructBlock): title = blocks.CharBlock(max_length=30, required=True) brochure_type = blocks.ChoiceBlock(max_length=3, choices=( ('pdf', 'pdf'), ('doc', 'doc'), ('docx', 'docx'), ('ppt', 'ppt'), ('pptx', 'pptx'), ('wd', 'wd'), ), default='pdf', icon='cup') get_link = DocumentChooserBlock(blank=True, null=True, default=None) class Meta: icon = "cup" label = "Brochure"
class OtherPost(Post): """ """ parent_page_types = ['ProgramOtherPostsPage', 'OtherPostCategory'] subpage_types = [] attachment = StreamField([ ('attachment', DocumentChooserBlock(required=False)), ], null=True, blank=True) content_panels = Post.content_panels + [ StreamFieldPanel('attachment'), ] other_content_type = models.ForeignKey( 'other_content.ProgramOtherPostsPage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', ) category = models.ForeignKey( 'other_content.OtherPostCategory', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', ) def save(self, *args, **kwargs): parent = self.get_parent().specific if type(parent) == OtherPostCategory: self.category = parent self.other_content_type = parent.get_parent().specific else: self.other_content_type = parent super(OtherPost, self).save(*args, **kwargs) class Meta: verbose_name = 'Other Post'
class DownloadBlock(ButtonMixin, BaseBlock): """ Link to a file that can be downloaded. """ automatic_download = blocks.BooleanBlock( required=False, label=_('Auto download'), ) downloadable_file = DocumentChooserBlock( required=False, label=_('Document link'), ) advsettings_class = CoderedAdvTrackingSettings class Meta: template = 'coderedcms/blocks/download_block.html' icon = 'download' label = _('Download')
class BaseStreamBlock(StreamBlock): """ Define the custom blocks that `StreamField` will utilize """ heading_block = HeadingBlock() paragraph_block = RichTextBlock(icon='pilcrow', template='blocks/paragraph_block.html') image_block = ImageBlock() document = DocumentChooserBlock(icon='doc-full-inverse') button_block = ButtonBlock() image_grid_block = ImageGridBlock() embed_block = EmbedBlock( help_text= 'Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='code', template='blocks/embed_block.html') icon_block = IconBlock() table = TableBlock(template='includes/table.html') raw_html = AlignedRAWHTMLBlock()
class DocumentLink(blocks.StructBlock): """ Single Internal link block """ link = DocumentChooserBlock(required=True) title = blocks.CharBlock(required=False) @property def get_title(self): # weird; property with get_ if self.title: return self.title else: self.link.name class Meta: icon = 'link' def get_api_representation(self, value, context=None): return DocumentLinkSerializer(value).data