def generate_media_block(self, default_size=100): # Make a thumbnail for the first photo or video media_block = '' link_kwargs = None photo_annotations = get_photo_annotations(self.post_a.get('annotations', [])) video_annotations = get_video_annotations(self.post_a.get('annotations', [])) if photo_annotations: icon_class = 'icon-zoom-in' value = photo_annotations[0]['value'] link_kwargs = { 'href': value.get('embeddable_url', smart_reverse(self.request, 'photo', args=[self.post_a.user.username, self.post_a.id, 1])), } # keep the :// here photos_domain = '://photos.app.net' if photos_domain not in link_kwargs['href']: link_kwargs['target'] = '_blank' link_kwargs['rel'] = 'nofollow' else: link_kwargs['data-pjax-url'] = smart_reverse(self.request, 'pau.views.alpha.photo', args=[self.post_a.user.username, self.post_a.id, 1], force_qualified=True) elif video_annotations: icon_class = 'icon-play-circle' value = video_annotations[0]['value'] embeddable_url = value.get('embeddable_url') if embeddable_url: link_kwargs = { 'href': embeddable_url, 'target': '_blank', 'rel': 'nofollow' } if link_kwargs: thumbnail_width = value['thumbnail_width'] thumbnail_height = value['thumbnail_height'] thumbnail_url = value.get('thumbnail_url_secure', value['thumbnail_url']) try: max_width = int(self.request.GET.get('max_width', default_size)) max_height = int(self.request.GET.get('max_height', default_size)) except: max_width = max_height = default_size include_zoom = bool(self.request.GET.get('include_zoom', True)) display_width, display_height = map(str, fit_to_box(thumbnail_width, thumbnail_height, max_width, max_height)) media_block = [ html.div(class_='post-media', *[ html.a(class_="shadow-overlay", data=self.click_data, *[ html.i(class_=icon_class) if include_zoom else '' ], **link_kwargs), html.div(class_='inner-shadow-overlay'), html.img(src=thumbnail_url, width=display_width, height=display_height) ]) ] return media_block
def populate_context(self, request, username=None, post_id=None, photo_id=None, *args, **kwargs): super(PauPhotoView, self).populate_context(request, *args, **kwargs) try: post_id = int(post_id) photo_id = int(photo_id) except: raise Http404() post_api_obj = bridge.get_post(request, post_id) if not verify_post(username, post_api_obj): raise Http404() photo_annotations = get_photo_annotations(post_api_obj.get('annotations', [])) num_photos = len(photo_annotations) # N.B. photo_id is 1-based if photo_id < 1 or photo_id > num_photos: raise Http404() photo_annotation = photo_annotations[photo_id - 1] value = photo_annotation['value'] width = value['width'] height = value['height'] url = value.get('url_secure', value['url']) next_photo_url = None prev_photo_url = None if photo_id > 1: prev_photo_url = smart_reverse(request, 'photo', args=[username, post_id, photo_id - 1]) if photo_id < num_photos: next_photo_url = smart_reverse(request, 'photo', args=[username, post_id, photo_id + 1]) post_presenter = PhotoPostPresenter.from_item(request, post_api_obj) self.view_ctx['page_title'] = u'App.net | %s photo: %s' % (post_api_obj.user.username, truncate(post_api_obj.get('text', ''), 50)) self.view_ctx['page_description'] = truncate(post_api_obj.get('text', self.view_ctx['page_title']), 100) self.view_ctx.update_ctx({ 'image_url': url, 'image_width': width, 'image_height': height, 'next_photo_url': next_photo_url, 'prev_photo_url': prev_photo_url, 'post_presenter': post_presenter, 'post_url': smart_reverse(request, 'post_detail_view', args=[username, post_id]), 'post_api_obj': post_api_obj, 'oembed_url': oembed_url(request.build_absolute_uri()), '__js_page_load_hooks': ['photo.init'] })
def generate_media_block(self, default_size=100): # Make a thumbnail for the first photo or video media_block = '' link_kwargs = None photo_annotations = get_photo_annotations( self.post_a.get('annotations', [])) video_annotations = get_video_annotations( self.post_a.get('annotations', [])) if photo_annotations: icon_class = 'icon-zoom-in' value = photo_annotations[0]['value'] link_kwargs = { 'href': value.get( 'embeddable_url', smart_reverse( self.request, 'photo', args=[self.post_a.user.username, self.post_a.id, 1])), } # keep the :// here photos_domain = '://photos.app.net' if photos_domain not in link_kwargs['href']: link_kwargs['target'] = '_blank' link_kwargs['rel'] = 'nofollow' else: link_kwargs['data-pjax-url'] = smart_reverse( self.request, 'pau.views.alpha.photo', args=[self.post_a.user.username, self.post_a.id, 1], force_qualified=True) elif video_annotations: icon_class = 'icon-play-circle' value = video_annotations[0]['value'] embeddable_url = value.get('embeddable_url') if embeddable_url: link_kwargs = { 'href': embeddable_url, 'target': '_blank', 'rel': 'nofollow' } if link_kwargs: thumbnail_width = value['thumbnail_width'] thumbnail_height = value['thumbnail_height'] thumbnail_url = value.get('thumbnail_url_secure', value['thumbnail_url']) try: max_width = int(self.request.GET.get('max_width', default_size)) max_height = int( self.request.GET.get('max_height', default_size)) except: max_width = max_height = default_size include_zoom = bool(self.request.GET.get('include_zoom', True)) display_width, display_height = map( str, fit_to_box(thumbnail_width, thumbnail_height, max_width, max_height)) media_block = [ html.div(class_='post-media', *[ html.a(class_="shadow-overlay", data=self.click_data, *[ html.i(class_=icon_class) if include_zoom else '' ], **link_kwargs), html.div(class_='inner-shadow-overlay'), html.img(src=thumbnail_url, width=display_width, height=display_height) ]) ] return media_block
def populate_context(self, request, username=None, post_id=None, photo_id=None, *args, **kwargs): super(PauPhotoView, self).populate_context(request, *args, **kwargs) try: post_id = int(post_id) photo_id = int(photo_id) except: raise Http404() post_api_obj = bridge.get_post(request, post_id) if not verify_post(username, post_api_obj): raise Http404() photo_annotations = get_photo_annotations( post_api_obj.get('annotations', [])) num_photos = len(photo_annotations) # N.B. photo_id is 1-based if photo_id < 1 or photo_id > num_photos: raise Http404() photo_annotation = photo_annotations[photo_id - 1] value = photo_annotation['value'] width = value['width'] height = value['height'] url = value.get('url_secure', value['url']) next_photo_url = None prev_photo_url = None if photo_id > 1: prev_photo_url = smart_reverse( request, 'photo', args=[username, post_id, photo_id - 1]) if photo_id < num_photos: next_photo_url = smart_reverse( request, 'photo', args=[username, post_id, photo_id + 1]) post_presenter = PhotoPostPresenter.from_item(request, post_api_obj) self.view_ctx['page_title'] = u'App.net | %s photo: %s' % ( post_api_obj.user.username, truncate(post_api_obj.get('text', ''), 50)) self.view_ctx['page_description'] = truncate( post_api_obj.get('text', self.view_ctx['page_title']), 100) self.view_ctx.update_ctx({ 'image_url': url, 'image_width': width, 'image_height': height, 'next_photo_url': next_photo_url, 'prev_photo_url': prev_photo_url, 'post_presenter': post_presenter, 'post_url': smart_reverse(request, 'post_detail_view', args=[username, post_id]), 'post_api_obj': post_api_obj, 'oembed_url': oembed_url(request.build_absolute_uri()), '__js_page_load_hooks': ['photo.init'] })