Add NotificationSender, one test
This commit is contained in:
@@ -17,5 +17,6 @@ from .portfolio_invitation import PortfolioInvitation
|
||||
from .application_invitation import ApplicationInvitation
|
||||
from .task_order import TaskOrder
|
||||
from .dd_254 import DD254
|
||||
from .notification_recipient import NotificationRecipient
|
||||
|
||||
from .mixins.invites import Status as InvitationStatus
|
||||
|
10
atst/models/notification_recipient.py
Normal file
10
atst/models/notification_recipient.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from sqlalchemy import String, Column
|
||||
|
||||
from atst.models import Base, types, mixins
|
||||
|
||||
|
||||
class NotificationRecipient(Base, mixins.TimestampsMixin):
|
||||
__tablename__ = "notification_recipients"
|
||||
|
||||
id = types.Id()
|
||||
email = Column(String, nullable=False)
|
20
atst/utils/notification_sender.py
Normal file
20
atst/utils/notification_sender.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from atst.queue import ATSTQueue
|
||||
from atst.database import db
|
||||
from atst.models import NotificationRecipient
|
||||
|
||||
|
||||
class NotificationSender(object):
|
||||
EMAIL_SUBJECT = "ATST notification"
|
||||
|
||||
def __init__(self, queue: ATSTQueue):
|
||||
self.queue = queue
|
||||
|
||||
def send(self, body, type_=None):
|
||||
recipients = self._get_recipients(type_)
|
||||
self.queue.send_mail(recipients, self.EMAIL_SUBJECT, body)
|
||||
|
||||
def _get_recipients(self, type_):
|
||||
return [
|
||||
recipient.email
|
||||
for recipient in db.session.query(NotificationRecipient).all()
|
||||
]
|
Reference in New Issue
Block a user