Ejemplo n.º 1
0
class LinkBlock(StructBlock):
    title = CharBlock(required=True)
    picture = ImageChooserBlock(required=False)
    text = RichTextBlock(required=False)
    link = URLBlock(required=False)
    date = DateBlock(required=False)

    class Meta:
        classname = 'link'
        icon = 'fa fa-external-link'
        template = 'widgets/page-teaser-wide.html'

    def get_context(self, value, parent_context=None):
        context = super(LinkBlock,
                        self).get_context(value, parent_context=parent_context)
        context['arrow_right_link'] = True
        context['title'] = value.get('title')
        context['description'] = value.get('text')
        context['date'] = value.get('date')

        image = value.get('picture')
        if image:
            rendition = image.get_rendition('fill-640x360-c100')
            context['image'] = {'url': rendition.url, 'name': image.title}
        if value.get('link'):
            context['href'] = value.get('link')
        return context
Ejemplo n.º 2
0
class BigTeaserBlock(StructBlock):
    title = CharBlock(required=True)
    subtitle = CharBlock(required=False)
    picture = ImageChooserBlock(required=False)
    full_width_picture = BooleanBlock(required=False, default=False)
    text = RichTextBlock(required=False)
    external_link = URLBlock(
        required=False,
        help_text="Will be ignored if an internal link is provided")
    internal_link = PageChooserBlock(
        required=False,
        help_text='If set, this has precedence over the external link.')

    from_date = DateBlock(required=False)
    to_date = DateBlock(required=False)

    class Meta:
        icon = 'fa fa-list-alt'
        template = 'blocks/big_teaser_block.html'

    def __init__(self, wideimage=False, local_blocks=None, **kwargs):
        super().__init__(local_blocks=local_blocks, **kwargs)
        self.wideimage = wideimage

    def get_context(self, value, parent_context=None):
        context = super(BigTeaserBlock,
                        self).get_context(value, parent_context=parent_context)
        context['super_title'] = value.get('title')

        image = value.get('picture')
        if image:
            rendition = image.get_rendition('max-800x800')
            context['image'] = {'url': rendition.url, 'name': image.title}
        if value.get('internal_link'):
            context['href'] = value.get('internal_link').url
        else:
            context['href'] = value.get('external_link')
        if context['href']:
            context['text_right_link'] = True
            context['text_right_link_text'] = 'Learn more'

        context.update({
            'title': value.get('subtitle'),
            'description': value.get('text'),
            'divider': value.get('subtitle') and value.get('text'),
            'calendaricon': True,
            'full_width_picture': value.get('full_width_picture'),
        })
        if value.get('from_date') and value.get('to_date'):
            context['date'] = '"{} to {}"'.format(
                formats.date_format(value.get('from_date'),
                                    "SHORT_DATE_FORMAT"),
                formats.date_format(value.get('to_date'), "SHORT_DATE_FORMAT"))

        context['wideimage'] = self.wideimage
        return context
Ejemplo n.º 3
0
class ImpactModelsBlock(StructBlock):
    description = RichTextBlock()
    rows_per_page = IntegerBlock(default=20, min_value=1, required=True)

    def get_context(self, value, parent_context=None):
        context = super(ImpactModelsBlock, self).get_context(value, parent_context=parent_context)

        bims = BaseImpactModel.objects.select_related('sector').prefetch_related('impact_model', 'impact_model_owner', 'impact_model_owner__user')
        bims = bims.filter(impact_model__public=True).distinct().order_by('name')

        # Filter und Suchfelder
        context['tableid'] = 'selectortable'
        context['searchfield'] = {'value': ''}
        sector_options = [{'value': x} for x in bims.values_list('sector__name', flat=True).distinct().order_by('sector')]
        simulation_round_options = [{'value': x} for x in bims.exclude(impact_model__simulation_round__isnull=True).values_list('impact_model__simulation_round__name', flat=True).distinct().order_by('impact_model__simulation_round')]
        context['selectors'] = [
            {'colnumber': '2', 'all_value': 'All simulation rounds', 'options': simulation_round_options, 'name': 'simulation_round'},
            {'colnumber': '3', 'all_value': 'All sectors', 'options': sector_options, 'name': 'sector'},
        ]
        # Tabelle
        context['id'] = 'selectortable'
        context['head'] = {
            'cols': [{'text': 'Model'}, {'text': 'Simulation round'}, {'text': 'Sector'}, {'text': 'Contact person'}, {'text': 'Email'}]
        }
        rows_per_page = value.get('rows_per_page')
        numpages = math.ceil(bims.count() / rows_per_page)
        context['pagination'] = {
            'rowsperpage': (rows_per_page),
            'numberofpages': numpages,  # number of pages with current filters
            'pagenumbers': [{'number': i + 1, 'invisible': False} for i in range(numpages)],
            'activepage': 1,  # set to something between 1 and numberofpages
        }
        context['norowvisible'] = False  # true when no row is visible

        context['body'] = {'rows': []}
        for i, bmodel in enumerate(bims):
            simulation_rounds = bmodel.impact_model.filter(public=True).values_list('simulation_round__name', flat=True)
            values = [["<a href='details/{0.id}/'>{0.name}</a>".format(bmodel, bmodel)], simulation_rounds, [bmodel.sector]]
            values += [["{0.name}<br/>".format(x) for x in bmodel.impact_model_owner.all()]]
            values += [["<a href='mailto:{0.email}'>{0.email}</a><br/>".format(x) for x in bmodel.impact_model_owner.all()]]
            row = {
                'invisible': i >= rows_per_page,
                'cols': [{'texts': x} for x in values],
            }
            context['body']['rows'] += [row]

        return context

    class Meta:
        icon = 'fa fa-database'
        template = 'blocks/impact_models_block.html'
Ejemplo n.º 4
0
class SupporterBlock(StructBlock):
    name = CharBlock()
    image = ImageBlock(required=False)
    content = RichTextBlock()
Ejemplo n.º 5
0
class FAQBlock(StructBlock):
    question = CharBlock()
    answer = RichTextBlock()
Ejemplo n.º 6
0
from wagtail.wagtaildocs.blocks import DocumentChooserBlock
from wagtail.wagtailembeds.blocks import EmbedBlock
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.contrib.table_block.blocks import TableBlock

from isi_mip.contrib.blocks import EmailBlock, IntegerBlock, HeadingBlock, HRBlock, ImageBlock, RichTextBlock, MonospaceTextBlock
from isi_mip.twitter import TwitterTimeline


class RowBlock(StreamBlock):
    class Meta:
        icon = 'horizontalrule'
        template = 'blocks/row_block.html'


BASE_BLOCKS = [('heading', HeadingBlock()), ('rich_text', RichTextBlock()),
               ('horizontal_ruler', HRBlock()), ('embed', EmbedBlock()),
               ('image', ImageBlock()), ('table', TableBlock()),
               ('monospace_text', MonospaceTextBlock())]


class SmallTeaserBlock(StructBlock):
    title = CharBlock(required=True)
    picture = ImageChooserBlock()
    text = TextBlock(required=True)
    link = PageChooserBlock(required=True)

    class Meta:
        icon = 'fa fa-list-alt'
        template = 'blocks/small_teaser_block.html'