Commit c35ac0da authored by Romain Bignon's avatar Romain Bignon

notify ass2m owner when a user changes his state on an event

parent 49a9b316
......@@ -29,6 +29,7 @@ from ass2m.routes import View
from ass2m.server import ViewAction
from ass2m.cmd import Command
from ass2m.template import build_url, build_root_url
from ass2m.mail import Mail
from .contacts import ContactsSelection
from .cleanup import ICleaner
......@@ -49,6 +50,12 @@ class Event(object):
'-': USER_DECLINED
}
STATES_LABEL = {USER_CONFIRMED: 'confirmed',
USER_MAYBE: 'maybe',
USER_WAITING: 'waiting',
USER_DECLINED: 'declined',
}
def __init__(self, f):
self.f = f
self.title = None
......@@ -103,6 +110,22 @@ class Event(object):
mail.send()
return user.email
def notify_state_changed(self, user):
config = self.f.storage.get_config()
if not 'sender' in config.data['mail']:
return
sender = config.data['mail']['sender']
recipient = config.data['mail']['sender']
smtp = config.data['mail'].get('smtp', 'localhost')
subject = 'A user has changed state'
mail = Mail(self.f.storage, 'event-state-changed.mail', sender, recipient, subject, smtp)
mail.vars['realname'] = user.realname
mail.vars['state'] = self.STATES_LABEL[self.users[user.name]]
mail.vars['url'] = build_url(build_root_url(self.f.storage), self.f)
mail.send()
def print_me(self):
print '-' * len(unicode(self.title))
self._print(sys.stdout)
......@@ -330,6 +353,7 @@ class EventAction(ViewAction):
event.load()
else:
confirm_message = 'Your state has been changed!'
event.notify_state_changed(self.ctx.user)
user_state = event.users[self.ctx.user.name]
......
Hi,
${realname} has changed his state to '${state}' on the following event:
${url}
Regards,
Ass2m
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment