def send_collaborator_invite_email(collaborator_id, sending_user_id, **kwargs): collaborator = VideoCollaborator.query.get(collaborator_id) if not collaborator: return sender = AccountUser.query.get(sending_user_id) # if the video isn't ready yet, wait 5 mins and try again if (collaborator.video.status not in ('ready', 'published') and current_app.config.get('ENABLE_BACKGROUND_SQS')): kwargs['_delay_seconds'] = 300 send_collaborator_invite_email(collaborator_id, sending_user_id, **kwargs) return if current_app.config.get('ENABLE_REGISTRATION_AUTH'): kwargs['reg_token'] = RegistrationToken.new(collaborator.email).id template = email_template_env.get_template('collaborator_invite.html') body = template.render( collaborator=collaborator, sender=sender, video=collaborator.video, **kwargs ) send_email(collaborator.email, body)
def send_profile_visitor_email(**kwargs): template = email_template_env.get_template('profile_visitors.html') senders = AccountUser.query.filter( extract('dow', AccountUser.date_added) == extract('dow', func.now()), extract('hour', AccountUser.date_added) == extract('hour', func.now()), ).join( AccountUserVisit, (AccountUserVisit.profile_user_id == AccountUser.id) & (AccountUserVisit.notified == False) ) for sender in senders: visitors = AccountUserVisit.get_all_visits_in_last_7_days(sender, 5) visitors = [AccountUserVisit.visit_item(*v) for v in visitors.all()] if visitors: body = template.render( sender=sender, visitors=visitors, **kwargs ) send_email(sender.username, body) try: db.session.query(AccountUserVisit).filter_by(profile_user_id=sender.id).update({"notified": True}) db.session.commit() except: db.session.rollback() raise
def send_connection_acceptance_email(sender_id, recipient_id): connection = AccountUserConnection.query.filter_by( account_user_id=sender_id, connection_id=recipient_id, ).one() template = email_template_env.get_template('connection_acceptance.html') for sender, recipient, initiator in ( (connection.account_user, connection.connection, True), (connection.connection, connection.account_user, False)): recipient.is_initiator = initiator body = template.render(sender=sender, recipient=recipient) send_email(recipient.email, body)
def send_connection_invite_email(sender_id, recipient_id): connection = AccountUserConnection.query.filter_by( account_user_id=sender_id, connection_id=recipient_id, ).one() template = email_template_env.get_template('connection_invite.html') body = template.render( sender=connection.account_user, recipient=connection.connection, message=connection.message, ) send_email(connection.connection.email, body)
def send_published_email(video_id, dolly_channel, dolly_instance): video = Video.query.get(video_id) link = current_app.config['DOLLY_WEBLITE_URL_FMT'].format( slug='-', channelid=dolly_channel, instanceid=dolly_instance) template = email_template_env.get_template('video_published.html') users = AccountUser.query.filter_by(account_id=video.account_id) for recipient, name in users.values('username', 'display_name'): body = template.render(video=video, link=link, username=name) send_email(recipient, body) collabs = VideoCollaborator.query.filter_by(video_id=video_id) for recipient, name in collabs.values('email', 'name'): body = template.render(video=video, link=link, username=name) send_email(recipient, body)
def send_processed_email(video_id, error=None): video = Video.query.get(video_id) try: error_message = current_app.config['VIDEO_ERROR_MESSAGES'][error] except KeyError: current_app.logger.warning('Unable to map error message: %s', error) error_message = None template = email_template_env.get_template('video_processed.html') users = AccountUser.query.filter_by(account_id=video.account_id) for recipient, name in users.values('username', 'display_name'): body = template.render( username=name, video=video, error=error, error_message=error_message, ) send_email(recipient, body)
def send_comment_notifications(video_id, user_type, user_id): comments = VideoComment.query.filter_by( video_id=video_id, user_type=user_type, user_id=user_id, notification_sent=False ).all() if not comments: return if user_type == 'collaborator': sender = VideoCollaborator.query.get(user_id) else: sender = AccountUser.query.get(user_id) video = Video.query.get(video_id) template = email_template_env.get_template('comment_notification.html') collabs = VideoCollaborator.query.filter_by( video_id=video_id, can_comment=True ).outerjoin(AccountUser).values( func.coalesce(AccountUser.username, VideoCollaborator.email), func.coalesce(AccountUser.display_name, VideoCollaborator.name), VideoCollaborator.id ) account_users = AccountUser.query.filter_by( account_id=video.account_id).values('username', 'display_name', null()) for email, username, collaborator_id in chain(collabs, account_users): body = template.render( sender=sender, video=video, comments=comments, email=email, username=username or email, token=collaborator_id and VideoCollaborator.get_token(collaborator_id), gravatar_url=gravatar_url, ) send_email(email, body) VideoComment.query.filter( VideoComment.id.in_([c.id for c in comments]) ).update(dict(notification_sent=True), synchronize_session=False)
def send_beta_invite_emails(tokens): tokens = models.RegistrationToken.query.filter( models.RegistrationToken.id.in_(tokens)) for token, recipient in tokens.values('id', 'recipient'): template = email_template_env.get_template('beta_invite.html') send_email(recipient, template.render(reg_token=token))
def send_welcome_email(user_id): user = AccountUser.query.get(user_id) if user: template = email_template_env.get_template('welcome.html') send_email(user.email, template.render(user=user))
def send_invite_request_ack_email(request_id): invite_request = InviteRequest.query.get(request_id) template = email_template_env.get_template('invite_request_ack.html') send_email(invite_request.email, template.render(recipient=invite_request))