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 _generate_facepile(self, user): facepile_size = 40 * 2 facepile_img_url = append_query_string(user.avatar_image.url, params={'w': facepile_size, 'h': facepile_size}) facepile_block = html.a(href=self._user_link(user), *[ html.img(class_=('interaction-facepile',), alt=user['username'], title=user['username'], src=facepile_img_url) ]) return facepile_block
def generate_html(self): icon_url = None if self.target_avatar: icon_url = self.target_avatar return html.div(class_='autocomplete-block', *[ html.div(class_='content ellipsis', *[ html.div(class_='media', *[ html.img(src=icon_url, width='40', height='40') if icon_url else html.span() ]), html.span(*[self.target_username]), html.br(), html.small(class_='muted', *['Account']) ]) ])
def _generate_facepile(self, user): facepile_size = 40 * 2 facepile_img_url = append_query_string(user.avatar_image.url, params={ 'w': facepile_size, 'h': facepile_size }) facepile_block = html.a(href=self._user_link(user), *[ html.img(class_=('interaction-facepile', ), alt=user['username'], title=user['username'], src=facepile_img_url) ]) return facepile_block
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