Exemplo n.º 1
0
 def get_story_image(self, obj):
     if obj.story_image:
         rendition_name = self.context['request'].query_params.get(
             'story_image_rendition', None)
         rendition_filter_spec = EventSerializer.STORY_IMAGE_RENDITIONS.get(
             rendition_name, None)
         return generate_image_url(obj.story_image, rendition_filter_spec)
Exemplo n.º 2
0
    def to_representation(self, obj):
        data = super(WeeklyEditionListSerializer, self).to_representation(obj)
        first_child = obj.get_children().first().specific
        if not first_child:
            return data

        data['title'] = first_child.title
        data['story_image'] = generate_image_url(first_child.story_image,
                                                 'fill-180x180')
        data['story_excerpt'] = first_child.story_excerpt

        return data
Exemplo n.º 3
0
    def to_representation(self, obj):
        data = super(SearchSerializer, self).to_representation(obj)
        obj = obj.specific

        if type(obj) == Person:
            data['profile_image'] = generate_image_url(
                obj.specific.profile_image, 'fill-300x300')
            data['first_name'] = obj.first_name
            data['last_name'] = obj.last_name
            data['position'] = obj.position_at_new_america
        elif isinstance(obj, Post) or type(obj) == Event:
            data['story_image'] = generate_image_url(obj.story_image,
                                                     'max-300x240')
            data['date'] = obj.date
            data['programs'] = PostProgramSerializer(obj.parent_programs,
                                                     many=True).data

        if isinstance(obj, Post):
            data['authors'] = AuthorSerializer(obj.post_author,
                                               many=True,
                                               context=self.context).data

        data['content_type'] = get_content_type(obj)
        return data
Exemplo n.º 4
0
def about_pages(request):
    aboutpages = cache.get('NA_about_pages', [])
    aboutimage = cache.get('NA_about_img', '')

    if len(aboutpages) == 0:
        about_pages = HomePage.objects.first().about_pages
        if len(about_pages) != 0:
            aboutpages = [{
                'title': a.value.title,
                'url': a.value.url
            } for a in about_pages]
            aboutimage = generate_image_url(
                about_pages[0].value.specific.story_image, 'fill-200x170')
            cache.set('NA_about_pages', aboutpages, 60 * 60)
            cache.set('NA_about_img', aboutimage, 60 * 60)

    return {'about_pages': aboutpages, 'about_image': aboutimage}
Exemplo n.º 5
0
    def get_data(self, obj):
        panels = None
        for d in obj.body.stream_data:
            # only the first panels is relevant
            if d['type'] == 'panels':
                panels = d['value']
                break
        if not panels:
            return None

        data = {}

        for p in panels:
            d = {}
            panel_key = p['value']['title']
            for b in p['value']['body']:
                key = b['type']

                if not key in d:
                    d[key] = []

                if key == 'inline_image':
                    img = CustomImage.objects.get(pk=b['value']['image'])
                    b['value']['url'] = generate_image_url(img, 'fill-800x550')
                elif key == 'resource_kit':
                    for r in b['value']['resources']:
                        id = r['value']['resource']
                        if r['type'] == 'attachment':
                            resource = Document.objects.get(pk=id)
                            r['value']['resource'] = resource.url
                        elif r['type'] == 'post':
                            resource = Page.objects.get(pk=id)
                            r['value']['resource'] = resource.url
                d[key].append(b['value'])

            data[panel_key] = d

        return data
Exemplo n.º 6
0
 def get_story_image_thumbnail(self, obj):
     return generate_image_url(obj.story_image, 'fill-30x14')
Exemplo n.º 7
0
 def get_profile_image(self, obj):
     if obj.profile_image:
         return generate_image_url(obj.profile_image, 'fill-200x200')
Exemplo n.º 8
0
 def get_story_image(self, obj):
     if obj.story_image:
         return generate_image_url(obj.story_image, 'fill-675x250')
Exemplo n.º 9
0
 def get_story_image_sm(self, obj):
     if obj.story_image:
         return generate_image_url(obj.story_image, 'fill-400x400')
Exemplo n.º 10
0
 def get_story_image_lg(self, obj):
     if obj.story_image:
         return generate_image_url(obj.story_image, 'fill-1400x525')
Exemplo n.º 11
0
 def get_story_image(self, obj):
     if obj.story_image:
         return generate_image_url(obj.story_image, 'width-800')
Exemplo n.º 12
0
 def get_partner_logo(self, obj):
     return generate_image_url(obj.partner_logo, 'max-240x30')
Exemplo n.º 13
0
 def get_story_image(self, obj):
     return generate_image_url(obj.story_image, 'fill-180x180')