def email_alert_preview(request): user=request.user msg = Alert.get_new_alerts(user=user) heading='You have '+str(len(msg))+' new notification' if len(msg)>1: heading+='s' html = email_html({'alerts':msg,'heading':heading},'alerts',user) return HttpResponse(html)
def get_new_alerts(request): if request.user.is_authenticated: try: new_alerts = Alert.get_new_alerts(request.user) old_alerts = Alert.get_old_alerts(request.user) except: return apiRespond(400, msg=f'Something went wrong.') else: return apiRespond(201, new_alerts=new_alerts, old_alerts=old_alerts) else: return apiRespond(401, msg='User not logged in')
def send_alerts(): users = get_users_batch() for user in users: msg = Alert.get_new_alerts(user=user) heading = 'You have ' + str(len(msg)) + ' new notification' if len(msg) > 1: heading += 's' html = get_html({'alerts': msg, 'heading': heading}, 'alerts', user) success = send(to=user.email, subject=alert_subject(user), message=heading, html=html) if success: user.last_alert_email_date = timezone.now() user.save()