Beispiel #1
0
class FooterSerializer(serializers.ModelSerializer):
    items = StreamField(source='menu_items')
    social_media = StreamField(source='follow_us')
    image = ImageSerializer()

    class Meta:
        model = apps.get_model('dctcmsbase', 'Footer')
        fields = (
            'items',
            'social_media',
            'image',
            'show_sitemap',
            'heading',
            'number_per_column',
        )
Beispiel #2
0
class BannerSerializer(HyperlinkedModelSerializer):

    attributes = StreamField()
    ctas = StreamField()

    def to_representation(self, obj):
        """Move fields from profile to user representation."""
        representation = super().to_representation(obj)
        representation['shelf_id'] = slugify(representation['shelf_id'])
        return representation


    class Meta:
        model = Banner
        fields = ['shelf_id', 'heading', 'body', 'attributes', 'ctas']
Beispiel #3
0
class MenuSerializer(serializers.ModelSerializer):
    items = StreamField(source='menu_items')

    class Meta:
        model = apps.get_model('dctcmsbase', 'Menu')
        fields = (
            'items',
        )
class SectionPageSerializer(serializers.ModelSerializer):

    body = StreamField()

    class Meta:
        model = SectionPage
        fields = (
            'title',
            'slug',
            'body',
        )
        read_only_fields = fields
class TestPageSerializer(serializers.ModelSerializer):
    """ TestPageSerializer """
    body = StreamField()

    class Meta:
        """ Meta """
        model = TestPage
        fields = (
            'title',
            'name1',
            'body',
            'test_related_model',
        )
Beispiel #6
0
class AppTeaserSerializer(HyperlinkedModelSerializer):

    attributes = StreamField()
    ctas = StreamField()

    def to_representation(self, obj):
        representation = super().to_representation(obj)
        cta_appstore = representation.pop('cta_appstore')
        cta_googleplay = representation.pop('cta_googleplay')
        if cta_appstore:
            representation['cta_appstore'] = {
                'link_text': '',
                'link_external': cta_appstore,
            }
        if cta_googleplay:
            representation['cta_googleplay'] = {
                'link_text': '',
                'link_external': cta_googleplay,
            }
        return representation

    class Meta:
        model = AppTeaser
        fields = ['shelf_id', 'heading', 'body', 'attributes', 'ctas', 'cta_googleplay', 'cta_appstore']
class TestModelSerializer(serializers.ModelSerializer):
    """ TestModelSerializer """
    body = StreamField()

    def to_representation(self, instance):
        """ to_representation """
        serialized_data = super(TestModelSerializer,
                                self).to_representation(instance)
        serialized_data['redirects'] = instance.get_redirections()
        return serialized_data

    class Meta:
        """ Meta """
        model = TestModel
        fields = (
            'name1',
            'name2',
            'body',
        )
Beispiel #8
0
class GeneralShelvePageSerializer(serializers.ModelSerializer):
    body = StreamField()

    def to_representation(self, data, has_body=True):
        meta_fields = getattr(self.Meta, 'meta_fields')
        serialized_data = super(GeneralShelvePageSerializer, self).to_representation(data)
        serialized_data['meta'] = {}
        for meta_field in meta_fields:
            try:
                meta_field_value = serialized_data.pop(meta_field)
                serialized_data['meta'][meta_field] = meta_field_value
            except KeyError:
                pass
        serialized_data['meta']['type'] = 'general_page'

        if has_body:
            for shelf in serialized_data['body']:
                shelf_id = shelf.get('id', None)
                if shelf_id:
                    shelf['id'] = 'p%s-%s' % (data.id, shelf_id)

        serialized_data['meta']['breadcrumbs'] = data.breadcrumbs

        return serialized_data

    class Meta:

        def get_fields():
            return (
                'id',
                'title',
                'body',
                'theme',
            )

        def get_meta_fields():
            return (
                'slug',
                'show_in_menus',
                'seo_title',
                'search_description',
                'first_published_at',
            )

        def get_social_fields():
            return (
                # OpenGraph fields
                'og_title',
                'og_description',
                'og_url',
                'og_image',
                'og_type',

                # Twitter fields
                'twitter_url',
                'twitter_card',
                'twitter_site',
                'twitter_title',
                'twitter_description',
                'twitter_image',

                'use_share_button',
                'use_email_button',
                'use_print_button',
            )

        def get_tracking_fields():
            return (
                'tracking_group',
            )

        abstract = True

        meta_fields = get_meta_fields() + get_social_fields() + get_tracking_fields()
        fields = get_fields() + meta_fields
Beispiel #9
0
class PageSerializer(WagtailPageSerializer):
    parent = PageParentField(read_only=True)
    children = ChildrenField(read_only=True)
    siblings = SiblingsField(read_only=True)
    body = StreamField()
Beispiel #10
0
class OneYou2PageSerializer(serializers.ModelSerializer):
    body = StreamField()

    def to_representation(self, data):
        meta_fields = getattr(self.Meta, 'meta_fields')
        serialized_data = super(OneYou2PageSerializer,
                                self).to_representation(data)
        serialized_data['meta'] = {}
        for meta_field in meta_fields:
            try:
                meta_field_value = serialized_data.pop(meta_field)
                serialized_data['meta'][meta_field] = meta_field_value
            except KeyError:
                pass
        serialized_data['meta']['type'] = 'general_page'
        for shelf in serialized_data['body']:
            determine_image_rendtions_for_shared_content_shelves(shelf)
            replace_resource_ids_with_links_for_download(shelf)
            shelf_id = shelf.get('id', None)
            if shelf_id:
                shelf['id'] = 'p%s-%s' % (data.id, shelf_id)

        serialized_data['meta']['breadcrumbs'] = data.breadcrumbs

        return serialized_data

    class Meta:
        model = apps.get_model('pages', 'OneYou2Page')
        fields = (
            'id',
            'title',
            'body',
            # 'path',
            # 'depth',
            # 'numchild',
            # 'live',
            'page_theme')

        meta_fields = (
            # 'type',
            'slug',
            # 'html_url',
            # 'detail_url',
            'show_in_menus',
            'seo_title',
            'search_description',
            'first_published_at',
            # 'parent',

            # OpenGraph fields
            'og_title',
            'og_description',
            'og_url',
            'og_image',
            'og_type',

            # Twitter fields
            'twitter_url',
            'twitter_card',
            'twitter_site',
            'twitter_title',
            'twitter_description',
            'twitter_image',
            'use_share_button',
            'use_email_button',
            'use_print_button',
            'opt_in_1_text',
            'opt_in_2_text',
            'ts_and_cs_statement',
            'tracking_group')

        fields = fields + meta_fields
Beispiel #11
0
class RecipePageSerializer(serializers.ModelSerializer):
    body = StreamField()

    def to_representation(self, data):
        meta_fields = getattr(self.Meta, 'meta_fields')
        serialized_data = super(RecipePageSerializer,
                                self).to_representation(data)
        serialized_data['meta'] = {}
        for meta_field in meta_fields:
            try:
                meta_field_value = serialized_data.pop(meta_field)
                serialized_data['meta'][meta_field] = meta_field_value
            except KeyError:
                pass

        serialized_data['meta']['type'] = 'recipe_page'
        image_id = serialized_data['image']
        if image_id:
            image_object = PHEImage.objects.get(id=image_id)
            renditions = image_object.generate_or_get_all_renditions()
            serialized_data['image'] = {
                'desktop': renditions['banner_shelf/None/None/desktop'],
                'mobile': renditions['banner_shelf/None/None/mobile']
            }

        serialized_data['meta']['breadcrumbs'] = data.breadcrumbs

        return serialized_data

    class Meta:
        model = apps.get_model('pages', 'RecipePage')
        fields = (
            'id',
            'title',
            'image',
            'body',
            'recipe_name',
            'tags',
            'serves',
            'preparation_time',
            'difficulty',
            'ingredients_list',
            'instructions',
            'page_theme',
            'video_id',
            'host',
            'header_gradient',
        )

        meta_fields = (
            # 'type',
            'slug',
            # 'html_url',
            # 'detail_url',
            'show_in_menus',
            'seo_title',
            'search_description',
            'first_published_at',
            # 'parent',

            # OpenGraph fields
            'og_title',
            'og_description',
            'og_url',
            'og_image',
            'og_type',

            # Twitter fields
            'twitter_url',
            'twitter_card',
            'twitter_site',
            'twitter_title',
            'twitter_description',
            'twitter_image',
            'use_share_button',
            'use_email_button',
            'use_print_button',
        )

        fields = fields + meta_fields