class ChartBlock(blocks.StructBlock): title = blocks.CharBlock(required=True) # todo: make radio buttons chart_type = blocks.ChoiceBlock(choices=[ ('bar', 'Bar'), ('line', 'Line'), ('tile_map', 'Tile Map'), ], required=True) color_scheme = blocks.ChoiceBlock( choices=[ ('green', 'Green'), ('blue', 'Blue'), ('teal', 'Teal'), ('navy', 'Navy'), ], required=False, help_text='Chart\'s color scheme. See ' 'https://github.com/cfpb/cfpb-chart-builder#configuration.') data_source = blocks.CharBlock( required=True, help_text='Location of the chart\'s data source relative to ' '"http://files.consumerfinance.gov/data/". For example,' '"consumer-credit-trends/volume_data_Score_Level_AUT.csv".') date_published = blocks.DateBlock( help_text='Automatically generated when CCT cron job runs' ) description = blocks.CharBlock( required=True, help_text='Briefly summarize the chart for visually impaired users.') has_top_rule_line = blocks.BooleanBlock( default=False, required=False, help_text=('Check this to add a horizontal rule line to top of ' 'chart block.') ) last_updated_projected_data = blocks.DateBlock( help_text='Month of latest entry in dataset' ) metadata = blocks.CharBlock( required=False, help_text='Optional metadata for the chart to use. ' 'For example, with CCT this would be the chart\'s "group".') note = blocks.CharBlock( required=False, help_text='Text to display as a footnote. For example, ' '"Data from the last six months are not final."') y_axis_label = blocks.CharBlock( required=False, help_text='Custom y-axis label') class Meta: label = 'Chart Block' icon = 'image' template = '_includes/organisms/chart.html' class Media: js = ['chart.js']
class CareerItemBlock(blocks.StructBlock): url = blocks.URLBlock(max_length=250, default='', label='URL') name = blocks.CharBlock(max_length=150, default='', label='Firma') start_date = blocks.DateBlock(label='Datum Antritt') end_date = blocks.DateBlock(label='Datum Austritt', required=False) text = blocks.RichTextBlock(label='Beschreibung') class Meta: template = 'blocks/career_item.html'
class RelatedMetadata(blocks.StructBlock): slug = blocks.CharBlock(max_length=100) content = blocks.StreamBlock([ ('text', blocks.StructBlock([('heading', blocks.CharBlock(max_length=100)), ('blob', blocks.RichTextBlock())], icon='pilcrow')), ('list', blocks.StructBlock([ ('heading', blocks.CharBlock(max_length=100)), ('links', blocks.ListBlock(atoms.Hyperlink())), ], icon='list-ul')), ('date', blocks.StructBlock([('heading', blocks.CharBlock(max_length=100)), ('date', blocks.DateBlock())], icon='date')), ('topics', blocks.StructBlock([ ('heading', blocks.CharBlock(max_length=100, default='Topics')), ('show_topics', blocks.BooleanBlock(default=True, required=False)) ], icon='tag')), ]) is_half_width = blocks.BooleanBlock(required=False, default=False) class Meta: icon = 'grip' template = '_includes/molecules/related-metadata.html' label = 'Related metadata'
class DataSnapshot(blocks.StructBlock): """ A basic Data Snapshot object. """ # Market key corresponds to market short name for lookup market_key = blocks.CharBlock(max_length=20, required=True, help_text='Market identifier, e.g. AUT') num_originations = blocks.CharBlock( max_length=20, help_text='Number of originations, e.g. 1.2 million') value_originations = blocks.CharBlock( max_length=20, help_text='Total dollar value of originations, e.g. $3.4 billion') year_over_year_change = blocks.CharBlock( max_length=20, help_text='Percentage change, e.g. 5.6% increase') last_updated_projected_data = blocks.DateBlock( help_text='Month of latest entry in dataset') # Market-specific descriptor text num_originations_text = blocks.CharBlock( max_length=100, help_text='Descriptive sentence, e.g. Auto loans originated') value_originations_text = blocks.CharBlock( max_length=100, help_text='Descriptive sentence, e.g. Dollar volume of new loans') year_over_year_change_text = blocks.CharBlock( max_length=100, help_text='Descriptive sentence, e.g. In year-over-year originations') # Select an image image = images_blocks.ImageChooserBlock(required=False, icon='image') class Meta: icon = 'image' label = 'CCT Data Snapshot' template = '_includes/organisms/data_snapshot.html'
class ActionBlock(blocks.StructBlock): action = blocks.CharBlock( verbose_name="Action", help_text="Text that appears at the top left of the image. For example: Blog" ) color = ColorPickerBlock( label = _('Background color'), help_text='Background color for action', required = False, ) image = ImageChooserBlock() date = blocks.DateBlock( required=False, help_text="Optional. For example for blogs or special events." ) title = blocks.CharBlock( verbose_name=_("Title"), help_text="Title of your action block. Example: Review: The new HP Latex 570" ) link = blocks.CharBlock( verbose_name="Link url", help_text="Enter a url manually here. For example: / contact / or www.google.nl" ) link_text = blocks.CharBlock( verbose_name="Link text", help_text="Enter a url text manually here. For example: view all blog articles or view all reviews." )
class CaosBlogPage(Page): """ Caos blog page admin controls """ blog_head_img = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) body = StreamField([ ('heading', blocks.CharBlock(classname="full title", icon="title")), ('caption', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('date', blocks.DateBlock()), ('codeblock', CodeBlock()), ]) author = models.CharField(max_length=30, choices=getattr(settings, 'AUTHORS')) category = MultiSelectField(max_length=40, choices=getattr(settings, 'CATEGORIES'), max_choices=2, default=None) date = models.DateField("Post date") to_read = models.IntegerField("Length To Read", max_length=20) footer = RichTextField("Footnote", null=True, blank=True) disclaimer = RichTextField("Disclaimer", null=True, blank=True) indexed_fields = ('body',) search_name = "Caos Blog Page"
class ActionBlock(blocks.StructBlock): action = blocks.CharBlock( verbose_name="Actie", help_text= "Tekst wat linksboven in de afbeelding komt. Bijvoorbeeld: Blog") color = ColorPickerBlock( label='Achtergrond kleur', help_text='Achtergrond kleur voor actie', required=False, ) image = ImageChooserBlock() datum = blocks.DateBlock( required=False, help_text="Optioneel. Bijvoorbeeld voor blogs of speciale events.") title = blocks.CharBlock( verbose_name="Titel", help_text= "Titel van je actieblok. Voorbeeld: Review: De nieuwe HP Latex 570") link = blocks.CharBlock( verbose_name="Link url", help_text= "Vul hier een url handmatig in. Bijvoorbeeld: /contact/ of www.google.nl" ) link_text = blocks.CharBlock( verbose_name="Link tekst", help_text= "Vul hier een url tekst handmatig in. Bijvoorbeeld: bekijk alle blogartikelen of bekijk alle reviews. " )
class DateAnswerBlock(AnswerBlock): """ Represents a numeric answer. """ answer = blocks.DateBlock( required=True, help_text=_('Required date.'), )
class HomePage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('logo', ImageChooserBlock()), ('date', blocks.DateBlock()), ('table', TableBlock()), ('quote', blocks.RichTextBlock()), ]) content_panels = Page.content_panels + [ StreamFieldPanel('body', classname="full"), ]
class ItemIntroduction(blocks.StructBlock): category = blocks.ChoiceBlock(choices=ref.categories, required=False) heading = blocks.CharBlock(required=False) paragraph = blocks.RichTextBlock(required=False) date = blocks.DateBlock(required=False) has_social = blocks.BooleanBlock( required=False, help_text="Whether to show the share icons or not.") class Meta: icon = 'form' template = '_includes/organisms/item-introduction.html' classname = 'block__flush-top'
class BureauStructure(blocks.StructBlock): last_updated_date = blocks.DateBlock(required=False) download_image = DocumentChooserBlock(icon='image') director = blocks.CharBlock() divisions = blocks.ListBlock(BureauStructureDivision()) office_of_the_director = blocks.ListBlock(BureauStructureOffice(), label='Office of the Director') class Meta: icon = None template = '_includes/organisms/bureau-structure.html' icon = "table" class Media: js = ['bureau-structure.js']
class ItemIntroduction(blocks.StructBlock): show_category = blocks.BooleanBlock( required=False, default=True, help_text=("Whether to show the category or not " "(category must be set in 'Configuration').")) heading = blocks.CharBlock(required=False) paragraph = blocks.RichTextBlock(required=False) date = blocks.DateBlock(required=False) has_social = blocks.BooleanBlock( required=False, help_text="Whether to show the share icons or not.") class Meta: icon = 'form' template = '_includes/organisms/item-introduction.html' classname = 'block__flush-top'
class BlogPage(Page): author = models.CharField(max_length = 250) date = models.DateField('Post date') intro = models.CharField(max_length = 250) tags = ClusterTaggableManager(through = BlogPageTag, blank = True) body = StreamField([ ('heading', blocks.CharBlock(classname = 'full title')), ('paragraph', blocks.RichTextBlock()), ('url', blocks.URLBlock()), ('date', blocks.DateBlock()), ('time', blocks.TimeBlock()), ('page', blocks.PageChooserBlock()), ('image', ImageChooserBlock()), ('doc', DocumentChooserBlock()), ('embed', EmbedBlock()), ]) def main_image(self): gallery_item = self.gallery_images.first() if gallery_item: return gallery_item.image else: return None search_fields = Page.search_fields + [ index.SearchField('intro'), index.SearchField('body'), index.SearchField('author'), ] content_panels = Page.content_panels + [ MultiFieldPanel([ FieldPanel('date'), FieldPanel('tags'), ], heading = 'Blog information'), FieldPanel('author'), FieldPanel('intro'), StreamFieldPanel('body'), InlinePanel('gallery_images', label = 'Gallery images') ]
class FeaturedLibraryExpertBlock(FeaturedLibraryExpertBaseBlock): """ Streamfield block for "Featured Library Experts". """ start_date = blocks.DateBlock(blank=True, null=True) end_date = blocks.DateBlock(blank=True, null=True)
class OpeningTimeBlock(blocks.StructBlock): """ A semi-structured opening times block. Period is left as a free text input to allow for """ PUBLIC = 7 PUBLIC_LABEL = 'Public holiday' WEEKDAYS = tuple(enumerate(calendar.day_name)) + ((PUBLIC, PUBLIC_LABEL),) weekday = blocks.ChoiceBlock(choices=WEEKDAYS, required=False) label = blocks.CharBlock(help_text='Optionally override default weekday label', required=False) date = blocks.DateBlock(help_text='Optionally specify a day these times are for', required=False) start = blocks.TimeBlock(required=False) end = blocks.TimeBlock(required=False) closed = blocks.BooleanBlock(default=False, required=False) class Meta: template = 'wagtail_extensions/blocks/openingtime.html' def clean(self, value): cleaned = super().clean(value) start, end, weekday, date = map(cleaned.get, ['start', 'end', 'weekday', 'date']) errors = defaultdict(ErrorList) if date and date < datetime.date.today(): err = ValidationError('Dates need to be in the future') errors['date'].append(err) if (start or end) and not (weekday or date): err = ValidationError('Specifying a weekday or date is required') errors['weekday'].append(err) if start and end and end <= start: err = ValidationError('End must be after start') errors['end'].append(err) if errors: raise ValidationError("There is a problem with this opening time", params=errors) return cleaned def get_context(self, value, parent_context=None): ctx = super().get_context(value, parent_context=parent_context) weekday = ctx['value'].get('weekday') if weekday is not None: if weekday == self.PUBLIC: ctx['is_public'] = True else: # Next date with this weekday today = datetime.date.today() ctx['next_date'] = today + relativedelta(weekday=weekday) return ctx def to_python(self, value): weekday = value.get('weekday') if weekday: weekday_int = int(weekday) value['weekday'] = weekday_int label = value.get('label') if weekday_int == self.PUBLIC and not label: value['label'] = self.PUBLIC_LABEL return super().to_python(value)