Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
migrations.AddField(
model_name="topic",
name="featured",
field=wagtail.core.fields.StreamField(
[
(
"article",
wagtail.core.blocks.PageChooserBlock(
page_type=["articles.Article"], required=False
),
),
(
"external_page",
wagtail.core.blocks.StructBlock(
[
("url", wagtail.core.blocks.URLBlock()),
("title", wagtail.core.blocks.CharBlock()),
(
"intro",
wagtail.core.blocks.TextBlock(required=False),
),
(
"header_image",
wagtail.images.blocks.ImageChooserBlock(
label="Image"
),
),
]
),
),
],
blank=True,
# Search index configuration
search_fields = Page.search_fields + [
index.SearchField('description')
]
# Editor panels configuration
content_panels = Page.content_panels + [
FieldPanel('description'),
FieldPanel('icon'),
InlinePanel('data_indicators', label="Data Indicators"),
]
class EntityStructBlock(blocks.StructBlock):
title = blocks.CharBlock()
name = blocks.CharBlock(required=False)
image = ImageChooserBlock(required=False)
description = blocks.RichTextBlock(features=['link'], required=False)
class Meta:
icon = 'group'
template = 'takwimu/_includes/dataview/entity_detail.html'
class DataIndicatorChooserBlock(blocks.ChooserBlock):
target_model = DataIndicator
widget = forms.Select
class Meta:
icon = 'folder'
blocks.TextBlock: TextBlock,
blocks.EmailBlock: EmailBlock,
blocks.IntegerBlock: IntegerBlock,
blocks.FloatBlock: FloatBlock,
blocks.DecimalBlock: DecimalBlock,
blocks.RegexBlock: RegexBlock,
blocks.URLBlock: URLBlock,
blocks.BooleanBlock: BooleanBlock,
blocks.DateBlock: DateBlock,
blocks.TimeBlock: TimeBlock,
blocks.DateTimeBlock: DateTimeBlock,
blocks.RichTextBlock: RichTextBlock,
blocks.RawHTMLBlock: RawHTMLBlock,
blocks.BlockQuoteBlock: BlockQuoteBlock,
blocks.ChoiceBlock: ChoiceBlock,
blocks.StreamBlock: StreamBlock,
blocks.StructBlock: StructBlock,
blocks.StaticBlock: StaticBlock,
blocks.ListBlock: ListBlock,
wagtail.embeds.blocks.EmbedBlock: EmbedBlock,
}
)
def register_streamfield_blocks():
from .pages import PageInterface
from .documents import get_document_type
from .images import get_image_type
class PageChooserBlock(graphene.ObjectType):
page = graphene.Field(PageInterface, required=True)
operations = [
migrations.AlterField(
model_name="homepage",
name="featured",
field=wagtail.core.fields.StreamField(
[
(
"article",
wagtail.core.blocks.PageChooserBlock(
page_type=["articles.Article"], required=False
),
),
(
"external_page",
wagtail.core.blocks.StructBlock(
[
("url", wagtail.core.blocks.URLBlock()),
("title", wagtail.core.blocks.CharBlock()),
(
"intro",
wagtail.core.blocks.TextBlock(required=False),
),
(
"header_image",
wagtail.images.blocks.ImageChooserBlock(
label="Image"
),
),
]
),
),
chart_type = blocks.ChoiceBlock(required=True,
choices=[
('histogram', 'Histogram'),
('pie', 'Pie Chart'),
('grouped_column', 'Grouped Column'),
],
label='Chart Type')
data_stat_type = blocks.ChoiceBlock(required=True,
choices=[
('dollar', 'Dollar'),
('number', 'Number'),
('percentage', 'Percentage'),
('scaled-percentage', 'Scaled Percentage'),
],
label='Stat Type')
chart_height = blocks.IntegerBlock(required=False,
label='Chart Height',
help_text='Default is 300px')
data_source_link = blocks.URLBlock(required=False, label='Source URL')
data_source_title = blocks.CharBlock(required=False, label='Source Title')
chart_qualifier = blocks.RichTextBlock(
features=['h5', 'h6', 'ol', 'ul', 'bold', 'italic', 'hr',
'link'],
required=False, label='Chart Qualifier',
help_text='Chart context e.g. legend, universe, etc.')
description = blocks.TextBlock(
required=False, label='Description of the data')
wagtail.core.blocks.PageChooserBlock(
page_type=[
"articles.Article",
"externalcontent.ExternalArticle",
]
),
),
(
"external_page",
wagtail.core.blocks.StructBlock(
[
("url", wagtail.core.blocks.URLBlock()),
("title", wagtail.core.blocks.CharBlock()),
(
"description",
wagtail.core.blocks.TextBlock(required=False),
),
("image", wagtail.images.blocks.ImageChooserBlock()),
]
),
),
],
blank=True,
help_text="Optional space for featured articles, max. 4",
null=True,
),
from modelcluster.models import ClusterableModel
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.contrib.settings.models import BaseSetting, register_setting
from wagtail.core import blocks
from wagtail.core.fields import StreamField
class LinkBlock(blocks.StructBlock):
page = blocks.PageChooserBlock()
title = blocks.CharBlock(help_text="Leave blank to use the page's own title", required=False)
class Meta:
template = 'blocks/menu_item.html',
@register_setting(icon='list-ul')
class NavigationSettings(BaseSetting, ClusterableModel):
primary_navigation = StreamField(
[('link', LinkBlock()), ],
blank=True,
help_text="Main site navigation"
)
panels = [
StreamFieldPanel('primary_navigation'),
]
class Migration(migrations.Migration):
dependencies = [("core", "0007_auto_20190429_1739")]
operations = [
migrations.AlterField(
model_name="articlepage",
name="body",
field=wagtail.core.fields.StreamField(
[
("paragraph", wagtail.core.blocks.RichTextBlock()),
(
"photo",
wagtail.core.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
("caption", wagtail.core.blocks.RichTextBlock()),
]
),
),
(
"photo_gallery",
wagtail.core.blocks.ListBlock(
wagtail.snippets.blocks.SnippetChooserBlock("core.Photo"),
icon="image",
),
),
(
"embed",
wagtail.core.blocks.StructBlock(
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
class ImageLink(blocks.StructBlock):
image = ImageChooserBlock(
label='Image',
)
link = blocks.CharBlock(
label='Link',
max_length=200,
)
class ImageLinkGalleryBlock(blocks.StructBlock):
image_items = blocks.ListBlock(
ImageLink(),
label="Image",
)
single_image_width = blocks.IntegerBlock(
help_text="in pixels"
)
class Meta:
template = 'cms/blocks/image_link_gallery.html'