roundabout,
created on Wednesday, 17 April 2024, 17:29:08 (1713374948),
received on Wednesday, 31 July 2024, 06:54:45 (1722408885)
Author identity: vlad <vlad.muntoiu@gmail.com>
d7b25d0e4611d0cbe818ec2a1e1bb00d01512ea8
app.py
@@ -363,8 +363,6 @@ def login():
db.session.add(notification)
db.session.commit()
result = celery_tasks.send_notification.delay(notification.id, [username], 1)
return flask.redirect("/", code=303)
@@ -450,9 +448,6 @@ def user_profile(username):
db.session.add(notification)
db.session.commit()
result = celery_tasks.send_notification.delay(notification.id, [username],
1)
db.session.commit()
return flask.redirect("?", code=303)
celery_tasks.py
@@ -11,24 +11,22 @@ from celery.utils.log import get_task_logger
@shared_task(ignore_result=False)
def send_notification(notification_id, users, level):
notification = db.session.get(Notification, notification_id)
for user in users:
db.session.add(UserNotification(db.session.get(User, user), notification, level))
if db.session.get(User, user).email:
with (SMTP(config.MAIL_SERVER) as mail):
if notification.data.get("type") == "welcome":
message = email_send.make_multipart_message(
f"Welcome, {user}",
config.NOTIFICATION_EMAIL,
db.session.get(User, user).email,
"welcome",
username=user)
mail.sendmail(config.NOTIFICATION_EMAIL, db.session.get(User, user).email, message)
db.session.commit()
def send_notification(user_notification_id):
user_notification = db.session.get(UserNotification, user_notification_id)
user = user_notification.user
notification = user_notification.notification
if user.email:
with (SMTP(config.MAIL_SERVER) as mail):
if notification.data.get("type") == "welcome":
message = email_send.make_multipart_message(
f"Welcome, {user.username}",
config.NOTIFICATION_EMAIL,
user.email,
"welcome",
username=user.username)
mail.sendmail(config.NOTIFICATION_EMAIL, user.email, message)
return 0 # notification sent successfully