Exemple #1
0
def update_icon_card_panel(panel):
    (rendition_mobile,
     rendition_desktop) = get_renditions(panel.value['image_meta'])

    panel.value['image'] = StructValue(BackgroundImageBlock, [
        ('image', panel.value['image']),
        ('meta_mobile_rendition',
         rendition_mobile if panel.value['mobile_use_renditions'] else 'none'),
        ('meta_desktop_rendition', rendition_desktop
         if panel.value['desktop_use_renditions'] else 'none'),
    ])

    for item in panel.value['cta']:
        item.block = SimpleCtaLinkBlock()
        item.block.name = 'simple_cta_link'

    panel.value['ctas'] = panel.value.pop('cta')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions'
    ]
    for key in keys_to_remove:
        del (panel.value[key])

    panel.block = IconCardPanel()
    return panel
Exemple #2
0
class ActionPlanDisplayShelf(Shelf, WithTracking):
    title = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(required=False)
    ctas = blocks.StreamBlock([('simple_menu_item', SimpleCtaLinkBlock())],
                              icon='arrow-left',
                              label='Items',
                              required=False)
Exemple #3
0
def update_video_teaser_panel(panel):
    (rendition_mobile,
     rendition_desktop) = get_renditions(panel.value['image_meta'])

    panel.value['image'] = StructValue(BackgroundImageBlock, [
        ('image', panel.value['image']),
        ('meta_mobile_rendition',
         rendition_mobile if panel.value['mobile_use_renditions'] else 'none'),
        ('meta_desktop_rendition', rendition_desktop
         if panel.value['desktop_use_renditions'] else 'none'),
    ])

    for item in panel.value['cta']:
        item.block = SimpleCtaLinkBlock()
        item.block.name = 'simple_cta_link'

    panel.value['ctas'] = panel.value.pop('cta')

    panel.value['meta_layout'] = '{}-{}'.format(
        panel.value['meta_layout_desktop'], panel.value['meta_layout_mobile'])

    panel.value['panel_id'] = panel.value.pop('shelf_id')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions',
        'meta_layout_mobile', 'meta_layout_desktop'
    ]
    for key in keys_to_remove:
        del (panel.value[key])

    panel.block = StandardVideoTeaserPanel()
    return panel
Exemple #4
0
def get_or_create_promo(promo_values):
    try:
        return Banner.objects.get(shelf_id=promo_values.shelf_id)
    except Banner.DoesNotExist:
        contenttype = ContentType.objects.get(app_label='dctcmsbase',
                                              model='banner')
        cta_stream_block = StreamBlock([('cta', SimpleCtaLinkBlock())])

        ctas = StreamValue(
            cta_stream_block,
            [('cta',
              StructValue(SimpleCtaLinkBlock, [
                  ('link_text', promo_values.cta_text),
                  ('link_external', promo_values.cta_link),
                  ('link_page', promo_values.cta_page),
                  ('link_id', ''),
                  ('meta_cta_variant', 'button'),
              ]))],
        )

        promo = Banner.objects.create(
            shelf_id=promo_values.shelf_id,
            heading=promo_values.heading,
            tracking_group=promo_values.tracking_group,
            content_type=contenttype,
            ctas=ctas,
        )
    return promo
Exemple #5
0
class ActionPlanShelf(Shelf, WithTracking):
    action_groups = blocks.StreamBlock([
        ('action_group', ActionGroupPanel(required=False,
                                          icon='collapse-down')),
    ])
    ctas = blocks.StreamBlock([('simple_menu_item', SimpleCtaLinkBlock())],
                              icon='arrow-left',
                              label='Items',
                              required=False)
Exemple #6
0
def update_action_plan_display_shelf(shelf):
    for item in shelf.value['cta']:
        item.block = SimpleCtaLinkBlock()
        item.block.name = 'simple_cta_link'

    shelf.value['ctas'] = shelf.value.pop('cta')

    shelf.block = ActionPlanDisplayShelf()

    return shelf
Exemple #7
0
class BackwardsCompatibleContentPanel(Panel):
    heading = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(required=False)
    image = ImageBlock(required=False)
    ctas = blocks.StreamBlock(
        [('simple_menu_item', SimpleCtaLinkBlock())],
        icon='arrow-left',
        label='Items',
        required=False,
    )

    class Meta:
        form_classname = 'dct-oneyou-teaser-panel dct-meta-panel'
Exemple #8
0
def update_information_panel(panel):
    (rendition_mobile,
     rendition_desktop) = get_renditions(panel.value['image_meta'])

    panel.value['image'] = StructValue(BackgroundImageBlock, [
        ('image', panel.value['image']),
        ('meta_mobile_rendition',
         rendition_mobile if panel.value['mobile_use_renditions'] else 'none'),
        ('meta_desktop_rendition', rendition_desktop
         if panel.value['desktop_use_renditions'] else 'none'),
    ])

    panel.value['meta_layout'] = 'desktop-image-left-mobile-image-top'

    if panel.value['meta_variant'] not in [
            'light_background', 'dark_background'
    ]:
        variant = {
            'mobile-image-top-text-right':
            'desktop-image-left-mobile-image-top',
            'mobile-image-right': 'desktop-image-right-mobile-image-right',
        }
        panel.value['meta_layout'] = variant[panel.value['meta_variant']]
        panel.value['meta_variant'] = 'light_background'

    cta_stream_block = StreamBlock([('simple_menu_item', SimpleCtaLinkBlock())
                                    ])

    ctas = []
    for item in panel.value['cta']:
        ctas.append(('simple_menu_item',
                     StructValue(SimpleCtaLinkBlock, [
                         ('link_text', item.value['link_text']),
                         ('link_external', item.value['link_external']),
                         ('link_page', item.value['link_page']),
                         ('link_id', item.value['link_id']),
                         ('meta_cta_variant', 'button'),
                     ])))

    panel.value['ctas'] = StreamValue(cta_stream_block, ctas)

    panel.value['panel_id'] = panel.value.pop('shelf_id')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions', 'cta'
    ]
    for key in keys_to_remove:
        del (panel.value[key])

    panel.block = StandardInformationPanel()
    return panel
Exemple #9
0
def update_action_plan_shelf(shelf):

    action_groups_block = StreamBlock([
        ('action_group', ActionGroupPanel(required=False,
                                          icon='collapse-down')),
    ])
    action_plan_block = StreamBlock([
        ('action_panel',
         ActionChooserBlock(target_model='oneyou.Action', icon='list-ul')),
    ])

    action_group_items = []
    for action_group in shelf.value['action_groups']:
        items = []
        for item in action_group.value['actions']:
            item.value = get_or_create_action(item.value)
            item.block = ActionChooserBlock(target_model='oneyou.Action')
            items.append(('action_panel', item.value))
        action_group_items.append(
            ('action_group',
             StructValue(ActionGroupPanel, [
                 ('title', action_group.value['title']),
                 ('actions', StreamValue(action_plan_block, items)),
             ])))

    shelf.value['action_groups'] = StreamValue(action_groups_block,
                                               action_group_items)

    cta_stream_block = StreamBlock([('simple_menu_item', SimpleCtaLinkBlock())
                                    ])

    ctas = []
    for item in shelf.value['cta']:
        ctas.append(('simple_menu_item',
                     StructValue(SimpleCtaLinkBlock, [
                         ('link_text', item.value['link_text']),
                         ('link_external', item.value['link_external']),
                         ('link_page', item.value['link_page']),
                         ('link_id', item.value['link_id']),
                         ('meta_cta_variant', 'button'),
                     ])))

    shelf.value['ctas'] = StreamValue(cta_stream_block, ctas)

    del (shelf.value['cta'])

    shelf.block = ActionPlanShelf()

    return shelf
Exemple #10
0
def update_find_out_more_dropdown_shelf(shelf):
    for item in shelf.value['cta']:
        item.block = SimpleCtaLinkBlock()
        item.block.name = 'simple_cta_link'

    shelf.value['ctas'] = shelf.value.pop('cta')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions'
    ]
    for key in keys_to_remove:
        del (shelf.value[key])

    shelf.block = FindOutMoreDropDownShelf()
    return shelf
Exemple #11
0
def get_or_create_banner(banner_values):
    try:
        return Banner.objects.get(shelf_id=banner_values.shelf_id)
    except Banner.DoesNotExist:
        contenttype = ContentType.objects.get(app_label='dctcmsbase',
                                              model='banner')
        expanded_stream_block = ExpandedStreamBlock([('background_image',
                                                      BackgroundImageBlock())])
        cta_stream_block = StreamBlock([('cta', SimpleCtaLinkBlock())])

        attributes = StreamValue(
            expanded_stream_block,
            [('background_image',
              StructValue(BackgroundImageBlock, [
                  ('image', banner_values.background_image),
                  ('meta_variant',
                   'gradient' if banner_values.meta_gradient else 'none'),
                  ('meta_mobile_rendition', 'none'),
                  ('meta_desktop_rendition', 'none'),
                  ('meta_image_display', 'cover'),
              ]))],
        )

        ctas = StreamValue(
            cta_stream_block,
            [('cta',
              StructValue(SimpleCtaLinkBlock, [
                  ('link_text', banner_values.cta_text),
                  ('link_external', banner_values.cta_link),
                  ('link_page', banner_values.cta_page),
                  ('link_id', ''),
                  ('meta_cta_variant', 'button'),
              ]))],
        )

        banner = Banner.objects.create(
            shelf_id=banner_values.shelf_id,
            heading=banner_values.heading,
            body=banner_values.body,
            tracking_group=banner_values.tracking_group,
            content_type=contenttype,
            attributes=attributes,
            ctas=ctas,
        )
    return banner
Exemple #12
0
def get_or_create_app_teaser(app_teaser_values):
    try:
        return AppTeaser.objects.get(shelf_id=app_teaser_values.shelf_id)
    except AppTeaser.DoesNotExist:
        contenttype = ContentType.objects.get(app_label='dctcmsbase',
                                              model='appteaser')
        expanded_stream_block = ExpandedStreamBlock([('image', ImageBlock())])
        cta_stream_block = StreamBlock([('cta', SimpleCtaLinkBlock())])

        attributes = StreamValue(
            expanded_stream_block,
            [('image',
              StructValue(ImageBlock, [
                  ('image', app_teaser_values.image),
              ]))],
        )

        ctas = StreamValue(
            cta_stream_block,
            [('cta',
              StructValue(SimpleCtaLinkBlock, [
                  ('link_text', app_teaser_values.cta_text),
                  ('link_external', app_teaser_values.cta_link),
                  ('link_page', app_teaser_values.cta_page),
                  ('link_id', ''),
                  ('meta_cta_variant', 'button'),
              ]))],
        )

        app_teaser = AppTeaser.objects.create(
            shelf_id=app_teaser_values.shelf_id,
            heading=app_teaser_values.heading,
            body=app_teaser_values.body,
            attributes=attributes,
            tracking_group=app_teaser_values.tracking_group,
            content_type=contenttype,
            ctas=ctas,
            cta_googleplay=app_teaser_values.cta_googleplay,
            cta_appstore=app_teaser_values.cta_appstore,
        )
    return app_teaser
Exemple #13
0
def update_oneyou_teaser_panel(panel):
    (rendition_mobile,
     rendition_desktop) = get_renditions(panel.value['image_meta'])

    panel.value['image'] = StructValue(BackgroundImageBlock, [
        ('image', panel.value['image']),
        ('meta_mobile_rendition',
         rendition_mobile if panel.value['mobile_use_renditions'] else 'none'),
        ('meta_desktop_rendition', rendition_desktop
         if panel.value['desktop_use_renditions'] else 'none'),
    ])

    cta_stream_block = StreamBlock([('simple_menu_item', SimpleCtaLinkBlock())
                                    ])

    ctas = []
    for item in panel.value['cta']:
        ctas.append(('simple_menu_item',
                     StructValue(SimpleCtaLinkBlock, [
                         ('link_text', item.value['link_text']),
                         ('link_external', item.value['link_external']),
                         ('link_page', item.value['link_page']),
                         ('link_id', item.value['link_id']),
                         ('meta_cta_variant', 'link'),
                     ])))

    panel.value['ctas'] = StreamValue(cta_stream_block, ctas)

    panel.value['panel_id'] = panel.value.pop('shelf_id')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions', 'cta'
    ]
    for key in keys_to_remove:
        del (panel.value[key])

    panel.block = BackwardsCompatibleContentPanel()
    return panel
Exemple #14
0
def update_image_teaser_panel(panel):
    (rendition_mobile,
     rendition_desktop) = get_renditions(panel.value['image_meta'])

    panel.value['image'] = StructValue(BackgroundImageBlock, [
        ('image', panel.value['image']),
        ('meta_mobile_rendition',
         rendition_mobile if panel.value['mobile_use_renditions'] else 'none'),
        ('meta_desktop_rendition', rendition_desktop
         if panel.value['desktop_use_renditions'] else 'none'),
    ])

    for item in panel.value['cta']:
        if 'link_external' in item.value:
            item.block = SimpleCtaLinkBlock()
            item.block.name = 'simple_cta_link'
        else:
            item.block = DocumentDownloadBlock()
            item.block.name = 'document_download'

    panel.value['ctas'] = panel.value.pop('cta')

    panel.value['meta_layout'] = '{}-{}'.format(
        panel.value['meta_layout_desktop'], panel.value['meta_layout_mobile'])

    panel.value['panel_id'] = panel.value.pop('shelf_id')

    keys_to_remove = [
        'image_meta', 'mobile_use_renditions', 'desktop_use_renditions',
        'meta_layout_mobile', 'meta_layout_desktop', 'audio',
        'meta_cta_variant'
    ]
    for key in keys_to_remove:
        del (panel.value[key])

    panel.block = StandardImageTeaserPanel()
    return panel