def generate_html(self): if not self.is_authenticated: return '' if not self.post_api_obj.user or self.request.user.adn_user.id == self.post_api_obj.user.id: return '' repost_class = 'icon-repost' repost_class += ' reposted' if self.viewer_has_reposted else '' title = 'remove repost' if self.viewer_has_reposted else 'repost' aria_label = title repost_inner = html.a(href='#repost', title=title, data={ 'repost-button': 1, 'reposted': int(self.viewer_has_reposted), 'post-id': self.post_api_obj['id'] }, *[ html.i(class_=repost_class, **{'aria-label': aria_label}), ]) return repost_inner
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_in_reply_to_container(self): return html.div(class_='hide in-reply-to layout-like-p subpixel', data={'in-reply-to': 1}, *[ html.div(html.em(*['In Reply To:'])), html.div(class_='well-style reply-to', *[ html.a(href='#', class_='close relative space-5', data={'remove-reply': 1}, *[ html.i(class_='icon-remove') ]), html.div(class_='post-container subpixel', data={'post-copy': 1}) ]) ])
def reply_button(self): href = '#' if self.reply_link_format == 'to_self' else self.post_detail_url data = {'reply-to': ''} data.update(self.click_data) tree = html.li(class_='show-on-hover yui3-u', *[ html.a(href=href, data=data, *[html.i(class_='icon-share-alt'), " Reply"]) ]) return tree
def reply_button(self): href = '#' if self.reply_link_format == 'to_self' else self.post_detail_url data = {'reply-to': ''} data.update(self.click_data) tree = html.li(class_='show-on-hover yui3-u', *[ html.a(href=href, data=data, *[ html.i(class_='icon-share-alt'), " Reply" ]) ]) return tree
def generate_html(self): if not self.is_authenticated: return '' star_class = 'icon-star-empty' aria_label = 'star' if self.viewer_has_starred: star_class = 'icon-star' aria_label = 'unstar' star_inner = html.a(href='#star', data={'star-button': 1, 'starred': int(self.viewer_has_starred), 'post-id': self.post_api_obj['id']}, *[ html.i(class_=star_class, **{'aria-label': aria_label}) ]) return star_inner
def generate_icon(self): c = None if self.action == 'follow': c = 'icon-ok' elif self.action == 'star': c = 'icon-star' elif self.action == 'reply': c = 'icon-share-alt' elif self.action == 'repost': c = 'icon-repost' elif self.action in ('broadcast_create', 'broadcast_subscribe', 'broadcast_unsubscribe'): c = 'icon-adn-bolt small' elif self.action == 'welcome': c = 'icon-adn' return html.i(class_=(c,)) if c else ''
def generate_icon(self): c = None if self.action == 'follow': c = 'icon-ok' elif self.action == 'star': c = 'icon-star' elif self.action == 'reply': c = 'icon-share-alt' elif self.action == 'repost': c = 'icon-repost' elif self.action in ('broadcast_create', 'broadcast_subscribe', 'broadcast_unsubscribe'): c = 'icon-adn-bolt small' elif self.action == 'welcome': c = 'icon-adn' return html.i(class_=(c, )) if c else ''
def generate_html(self): if not self.is_authenticated: return '' if not self.post_api_obj.user or self.request.user.adn_user.id == self.post_api_obj.user.id: return '' repost_class = 'icon-repost' repost_class += ' reposted' if self.viewer_has_reposted else '' title = 'remove repost' if self.viewer_has_reposted else 'repost' aria_label = title repost_inner = html.a(href='#repost', title=title, data={'repost-button': 1, 'reposted': int(self.viewer_has_reposted), 'post-id': self.post_api_obj['id']}, *[ html.i(class_=repost_class, **{'aria-label': aria_label}), ]) return repost_inner
def generate_html(self): if not self.is_authenticated: return '' star_class = 'icon-star-empty' aria_label = 'star' if self.viewer_has_starred: star_class = 'icon-star' aria_label = 'unstar' star_inner = html.a( href='#star', data={ 'star-button': 1, 'starred': int(self.viewer_has_starred), 'post-id': self.post_api_obj['id'] }, *[html.i(class_=star_class, **{'aria-label': aria_label})]) return star_inner
def generate_bottom_row(self): file_upload = file_upload_progress() success = html.span(class_='text-success hide', data={'success-text': 1}, *[self.success_message]) add_photo = html.button(class_='btn-attach-file file-related transition-color', data={'attach-btn': 1}, *[ html.i(class_='icon-picture'), u'Add photo\u2026' ]) char_count = self.generate_char_count() create_button = html.button(tabindex='2', data={'submit-button': 1}, class_='btn btn-primary %s-button btn-small disabled' % (self.btn_action.lower()), *[ self.btn_action ]) return html.grid(*[ html.div(class_='yui3-u-1-4 ta-left m-yui3-u-none', *[char_count]), html.div(class_='yui3-u-3-4 ta-right m-yui3-u-1', *[ file_upload, success, add_photo, create_button, ]) ])
def generate_html(self): if self.action not in self.allowed_actions: return '' timestamp = html.span( class_=('pull-right', 'timestamp'), title=self.interaction_date.strftime("%I:%M %p - %d %b %Y"), *[ html.i(class_='icon-time yui3-u'), " " + naturaldate(self.interaction_date), ]) text = html.div(*[ self.generate_icon(), self.generate_source_users(), ' ', self.generate_verb(), ' ', self.generate_obj_link, '.', timestamp ]) facepile = html.div(class_=('interaction-facepiles', ), *self.generate_facepiles()) return html.div(class_='post-container interaction subpixel', *[text, facepile])
def file_upload_progress(image_name='', uploaded=False): hide_progress = 'hide' text_class = '' if uploaded: hide_progress = 'plain' text_class = ' text-success' return html.div(class_='file-related yui3-u', *[ html.div(class_='hide', *[( html.input(type_='file', name='upload_file', data={'file-upload-input': 1}) )]), html.div(class_='file-preview', data={'image-preview-container': 1}, *[ html.div(class_=hide_progress, data={'upload-progress': 1}, *[ html.div(class_='progress', *[ html.span(class_='image-name', data={'img-name': 1}, *[ html.i(class_='icon icon-remove-sign transition-color muted' + hide_progress, data={'remove-attachment': 1}), html.span(class_='image-name-text' + text_class, data={'text': 1}, *[image_name]) ]), html.div(class_='bar', style={'width': '0%'}) ]) ]) ]) ])
def generate_html(self): if self.action not in self.allowed_actions: return '' timestamp = html.span(class_=('pull-right', 'timestamp'), title=self.interaction_date.strftime("%I:%M %p - %d %b %Y"), *[ html.i(class_='icon-time yui3-u'), " " + naturaldate(self.interaction_date), ]) text = html.div(*[ self.generate_icon(), self.generate_source_users(), ' ', self.generate_verb(), ' ', self.generate_obj_link, '.', timestamp ]) facepile = html.div(class_=('interaction-facepiles',), *self.generate_facepiles()) return html.div(class_='post-container interaction subpixel', *[text, facepile])
def generate_html(self): data = { 'backfill-control': 1, 'before-id': self.min_id, 'since-id': self.marker_id, } return [ html.div(class_='backfill-container', *[ html.div(class_='content ta-center', *[ html.a(href='#', data=data, *[ html.span(class_='yui3-u', *[ html.i(class_='icon-circle-arrow-up') ]), html.span(class_='yui3-u text', *[ ' Load More' ]) ]), html.div(class_='hide spinner-container', *[ html.span(class_='loading-spinner hide', *['']) ]), ]), ])]
def generate_html(self): data = { 'backfill-control': 1, 'before-id': self.min_id, 'since-id': self.marker_id, } return [ html.div( class_='backfill-container', *[ html.div( class_='content ta-center', *[ html.a( href='#', data=data, *[ html.span( class_='yui3-u', *[ html.i( class_='icon-circle-arrow-up') ]), html.span(class_='yui3-u text', *[' Load More']) ]), html.div(class_='hide spinner-container', *[ html.span( class_='loading-spinner hide', *['']) ]), ]), ]) ]
def generate_post_footer(self): if self.post_a.get('is_deleted'): return '' footer_top_row = [] # repost # N.B. if you change this html (reposts), make sure to change the ajax handler for repost, # which duplicates this html to provide client-side feedback viewer_has_reposted = self.post_a.get('you_reposted') if self.repost or viewer_has_reposted: # yes, there is a priority order of reposter info - viewer trumps everyone else if viewer_has_reposted: reposter_username = self.request.user.username reposter_display = 'you' elif self.repost: reposter_username = self.repost.user.username reposter_display = '@' + reposter_username footer_top_row.append( html.div(class_='post-reposted-by yui3-u', *[ html.span(class_='reposted-by-text', *[ html.i(class_='icon-repost'), html.span(' Reposted by ', *[ html.a(href=smart_reverse(self.request, 'user_detail_view', args=[reposter_username]), data=self.click_data, *[reposter_display]), ]) ]) ]) ) # place place_annotation = get_place_annotation(self.post_a.get('annotations', [])) if place_annotation: if place_annotation['value'].get('address'): place_pretty = u'%s \u2014 %s' % (place_annotation['value']['name'], place_annotation['value']['address']) else: place_pretty = u'%s' % place_annotation['value']['name'] tags_html = [] if place_annotation.get('type') == 'net.app.core.checkin': factual_url = urljoin('http://factual.com/', place_annotation['value']['factual_id']) tags_html.append(html.meta(name="factual", content=factual_url)) tags_html.append(html.span(class_='posted-from-text', *[ html.i(class_='icon-pushpin'), html.span(' at %s' % place_pretty), ])) footer_top_row.append(html.div(class_='post-posted-from-place yui3-u', *tags_html)) footer_bottom_row = [] # timestamp timezone_str = self.request.user.adn_user.timezone if self.is_authenticated else 'America/Los_Angeles' viewers_timezone = pytz.timezone(timezone_str) non_relative_timestamp = pytz.utc.localize(self.post_a.created_at).astimezone(viewers_timezone) datetime_formatted = non_relative_timestamp.strftime("%I:%M %p - %d %b %Y") footer_bottom_row.append(html.li( html.a(href=self.post_detail_url, data=self.click_data, class_='timestamp u-url', title=datetime_formatted, *[ html.time(class_='dt-published', datetime=datetime_formatted, *[ html.i(class_='icon-time yui3-u'), " " + naturaldate(self.post_a.created_at), ]) ])), ) is_reply = hasattr(self.post_a, 'reply_to') and self.post_a.reply_to reply_to_hash = "#" + str(self.post_a.reply_to) if is_reply else '' # conversation active? if is_reply or (self.post_a.num_replies > 0 and not self.single_post): footer_bottom_row.append( html.li(class_='in-reply-to yui3-u', *[ html.a(href=self.post_detail_url + reply_to_hash, data=self.click_data, title='In Reply To...', *[ html.i(class_='icon-comments', **{'aria-label': 'In Reply To...'}) ]) ]) ) # reply if self.is_authenticated and self.show_reply_button: footer_bottom_row.append(self.reply_button()) if self.show_stream_marker: data = { 'set-stream-marker': '' } footer_bottom_row.append( html.li(class_='show-on-hover yui3-u stream-marker-button', *[ html.a(href='#', data=data, *[ html.i(class_='icon-bookmark'), "" ]) ]) ) if self.post_a.source and self.show_via_attribution: source_link = getattr(self.post_a.source, 'link', None) source_name = getattr(self.post_a.source, 'name', None) if source_link and source_name: footer_bottom_row.append( html.li(class_='show-on-hover post-source yui3-u', *[ html.a(href=self.post_a.source.link, rel='nofollow', target='_blank', *[ html.i(class_='icon-share'), ' via ' + source_name ]) ]) ) # crosspost annotations = self.post_a.get('annotations', []) cp_url = None for a in annotations: annotation_type = a.get('type') if annotation_type == "net.app.core.crosspost": cp_url = a.get('value', {}).get('canonical_url') if cp_url and not re.match('^https?://', cp_url, re.IGNORECASE): cp_url = "http://" + cp_url if cp_url: cp_url_display = urlparse(cp_url).netloc if cp_url_display.startswith('www.'): cp_url_display = cp_url_display[4:] footer_bottom_row.append( html.li(class_='show-on-hover crossposted-from yui3-u', *[ html.a(href=cp_url, target='_blank', *[ html.i(class_='icon-random'), ' from ' + cp_url_display ]) ]) ) # report this post to app.net if self.show_report_button: if self.is_authenticated and self.request.user.adn_user.id != self.post_a.user.id: footer_bottom_row.append( html.li(class_='show-on-hover last pull-right yui3-u', *[ html.a(href='#report', data={'post-report': ''}, *[ html.i(class_='icon-flag'), html.span(class_='t-yui3-u-none m-yui3-u-none', *[' Report']), ]) ]) ) # mute this user--it's not really an if/else with the delete case so I'm not combining the conditions if self.show_mute_button: if self.is_authenticated and self.request.user.adn_user.id != self.post_a.user.id and not self.post_a.user.you_muted: footer_bottom_row.append( html.li(class_='show-on-hover pull-right yui3-u', *[ html.a(href='#mute-user', data={'post-mute-user': ''}, *[ html.i(class_='icon-minus-sign'), html.span(class_='t-yui3-u-none m-yui3-u-none', *[' Mute user']), ]) ]) ) # delete this post if self.show_delete_button: if self.is_authenticated and self.request.user.adn_user.id == self.post_a.user.id: footer_bottom_row.append( html.li(class_='show-on-hover last pull-right yui3-u', *[ html.a(href='#delete', data={'post-delete': ''}, *[ html.i(class_='icon-remove'), html.span(class_='t-yui3-u-none m-yui3-u-none', *[' Delete']), ]) ]) ) tree = html.div(class_='post-footer', *[ html.ul(class_='ul-horizontal unstyled footer-top', *footer_top_row), html.ul(class_='ul-horizontal unstyled footer-bottom', *footer_bottom_row) ]) return tree
def generate_post_footer(self): if self.post_a.get('is_deleted'): return '' footer_top_row = [] # repost # N.B. if you change this html (reposts), make sure to change the ajax handler for repost, # which duplicates this html to provide client-side feedback viewer_has_reposted = self.post_a.get('you_reposted') if self.repost or viewer_has_reposted: # yes, there is a priority order of reposter info - viewer trumps everyone else if viewer_has_reposted: reposter_username = self.request.user.username reposter_display = 'you' elif self.repost: reposter_username = self.repost.user.username reposter_display = '@' + reposter_username footer_top_row.append( html.div(class_='post-reposted-by yui3-u', *[ html.span( class_='reposted-by-text', *[ html.i(class_='icon-repost'), html.span( ' Reposted by ', *[ html.a(href=smart_reverse( self.request, 'user_detail_view', args=[reposter_username]), data=self.click_data, *[reposter_display]), ]) ]) ])) # place place_annotation = get_place_annotation( self.post_a.get('annotations', [])) if place_annotation: if place_annotation['value'].get('address'): place_pretty = u'%s \u2014 %s' % ( place_annotation['value']['name'], place_annotation['value']['address']) else: place_pretty = u'%s' % place_annotation['value']['name'] tags_html = [] if place_annotation.get('type') == 'net.app.core.checkin': factual_url = urljoin('http://factual.com/', place_annotation['value']['factual_id']) tags_html.append(html.meta(name="factual", content=factual_url)) tags_html.append( html.span(class_='posted-from-text', *[ html.i(class_='icon-pushpin'), html.span(' at %s' % place_pretty), ])) footer_top_row.append( html.div(class_='post-posted-from-place yui3-u', *tags_html)) footer_bottom_row = [] # timestamp timezone_str = self.request.user.adn_user.timezone if self.is_authenticated else 'America/Los_Angeles' viewers_timezone = pytz.timezone(timezone_str) non_relative_timestamp = pytz.utc.localize( self.post_a.created_at).astimezone(viewers_timezone) datetime_formatted = non_relative_timestamp.strftime( "%I:%M %p - %d %b %Y") footer_bottom_row.append( html.li( html.a(href=self.post_detail_url, data=self.click_data, class_='timestamp u-url', title=datetime_formatted, *[ html.time(class_='dt-published', datetime=datetime_formatted, *[ html.i(class_='icon-time yui3-u'), " " + naturaldate(self.post_a.created_at), ]) ])), ) is_reply = hasattr(self.post_a, 'reply_to') and self.post_a.reply_to reply_to_hash = "#" + str(self.post_a.reply_to) if is_reply else '' # conversation active? if is_reply or (self.post_a.num_replies > 0 and not self.single_post): footer_bottom_row.append( html.li(class_='in-reply-to yui3-u', *[ html.a(href=self.post_detail_url + reply_to_hash, data=self.click_data, title='In Reply To...', *[ html.i( class_='icon-comments', **{'aria-label': 'In Reply To...'}) ]) ])) # reply if self.is_authenticated and self.show_reply_button: footer_bottom_row.append(self.reply_button()) if self.show_stream_marker: data = {'set-stream-marker': ''} footer_bottom_row.append( html.li(class_='show-on-hover yui3-u stream-marker-button', *[ html.a(href='#', data=data, *[html.i(class_='icon-bookmark'), ""]) ])) if self.post_a.source and self.show_via_attribution: source_link = getattr(self.post_a.source, 'link', None) source_name = getattr(self.post_a.source, 'name', None) if source_link and source_name: footer_bottom_row.append( html.li(class_='show-on-hover post-source yui3-u', *[ html.a(href=self.post_a.source.link, rel='nofollow', target='_blank', *[ html.i(class_='icon-share'), ' via ' + source_name ]) ])) # crosspost annotations = self.post_a.get('annotations', []) cp_url = None for a in annotations: annotation_type = a.get('type') if annotation_type == "net.app.core.crosspost": cp_url = a.get('value', {}).get('canonical_url') if cp_url and not re.match('^https?://', cp_url, re.IGNORECASE): cp_url = "http://" + cp_url if cp_url: cp_url_display = urlparse(cp_url).netloc if cp_url_display.startswith('www.'): cp_url_display = cp_url_display[4:] footer_bottom_row.append( html.li(class_='show-on-hover crossposted-from yui3-u', *[ html.a(href=cp_url, target='_blank', *[ html.i(class_='icon-random'), ' from ' + cp_url_display ]) ])) # report this post to app.net if self.show_report_button: if self.is_authenticated and self.request.user.adn_user.id != self.post_a.user.id: footer_bottom_row.append( html.li( class_='show-on-hover last pull-right yui3-u', *[ html.a( href='#report', data={'post-report': ''}, *[ html.i(class_='icon-flag'), html.span( class_='t-yui3-u-none m-yui3-u-none', *[' Report']), ]) ])) # mute this user--it's not really an if/else with the delete case so I'm not combining the conditions if self.show_mute_button: if self.is_authenticated and self.request.user.adn_user.id != self.post_a.user.id and not self.post_a.user.you_muted: footer_bottom_row.append( html.li( class_='show-on-hover pull-right yui3-u', *[ html.a( href='#mute-user', data={'post-mute-user': ''}, *[ html.i(class_='icon-minus-sign'), html.span( class_='t-yui3-u-none m-yui3-u-none', *[' Mute user']), ]) ])) # delete this post if self.show_delete_button: if self.is_authenticated and self.request.user.adn_user.id == self.post_a.user.id: footer_bottom_row.append( html.li( class_='show-on-hover last pull-right yui3-u', *[ html.a( href='#delete', data={'post-delete': ''}, *[ html.i(class_='icon-remove'), html.span( class_='t-yui3-u-none m-yui3-u-none', *[' Delete']), ]) ])) tree = html.div(class_='post-footer', *[ html.ul(class_='ul-horizontal unstyled footer-top', *footer_top_row), html.ul( class_='ul-horizontal unstyled footer-bottom', *footer_bottom_row) ]) return tree
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