CPI Ordering System (the old version)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 

62 lines
1.6 KiB

from pyramid.events import NewRequest, subscriber
from pyramid.renderers import render
from pyramid_mailer.message import Message
from ordr2.views import set_display_defaults
class UserLogIn(object):
def __init__(self, request, user):
self.request = request
self.user = user
class UserNotification(object):
template = None
def __init__(self, request, user, data=None):
self.request = request
self.user = user
self.data = data
class AccountActivation(UserNotification):
subject='[ordr] Your account was activated'
template = 'ordr2:templates/emails/activation.jinja2'
class PasswordReset(UserNotification):
subject='[ordr] Password Reset'
template = 'ordr2:templates/emails/password_reset.jinja2'
class OrderStatusChange(UserNotification):
subject='[ordr] Order Status Change'
template = 'ordr2:templates/emails/order.jinja2'
@subscriber(UserLogIn)
def set_display_defaults_on_log_in(event):
set_display_defaults(event.request)
@subscriber(NewRequest)
def check_display_defaults(event):
if event.request.user and 'display' not in event.request.session:
set_display_defaults(event.request)
@subscriber(UserNotification)
def notify_user(event):
body = render(
event.template,
{'user': event.user, 'data': event.data},
event.request
)
message = Message(
subject=event.subject,
sender=event.request.registry.settings['mail.default_sender'],
recipients=[event.user.email],
html=body
)
event.request.mailer.send(message)