From d82a3e2440a8a0ea3bc9e03edf37306819e3d7d0 Mon Sep 17 00:00:00 2001 From: william57m Date: Thu, 20 Nov 2014 09:48:22 -0500 Subject: [PATCH] add mail notification --- webserver/controllers/orders.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/webserver/controllers/orders.py b/webserver/controllers/orders.py index 94e335c..66b40f3 100644 --- a/webserver/controllers/orders.py +++ b/webserver/controllers/orders.py @@ -1,19 +1,18 @@ # -*- coding: utf-8 -*- -from flask import Blueprint, json, make_response, request -from flask.ext.login import AnonymousUserMixin +from flask import Blueprint, make_response, request from flask.ext.babel import gettext from webserver import db, app from webserver.lib.base import jsonify -from webserver.models import Address, Order, StateOrder, Client, LineOrder, Restaurant +from webserver.models import Address, Order, StateOrder, LineOrder, Restaurant from twilio.rest import TwilioRestClient from webserver.config import TwilioConfig +import smtplib from sqlalchemy.orm import lazyload import datetime -import werkzeug # Define blueprint orders = Blueprint('orders', __name__) @@ -142,7 +141,7 @@ def create(): # Get state "En attente" try: - state = db.session.query(StateOrder).filter(StateOrder.name=="En attente").one() + state = db.session.query(StateOrder).filter(StateOrder.name == "En attente").one() except: return make_response(gettext(u"L'état 'En attente' est inexistant."), 400) @@ -171,7 +170,6 @@ def create(): order.lines_order.append(LineOrder(dish_id=dish_id, quantity=quantity)) - # Add menu db.session.add(order) @@ -232,9 +230,22 @@ def update(id): # client.messages.create( # to="+15144429905", # from_="+14387932148", - # body=u"Bonjour votre commande n°%s est passée dans le statut: %s." % (order.number, state.name), + # body=u"Bonjour votre commande n°%s est passée dans le statut: %s." % (order.id, state.name), # ) + # Mail notification + # sender = 'donotreply@etsmtl.ca' + # receivers = ['benjamin.comeau.1@ens.etsmtl.ca'] + # + # body = u"Bonjour votre commande numero %s est passee dans le statut: %s." % (order.id, state.name) + # message = ("From: ETS FOOD \n" + # "To: Benjamin Comeau \n" + # "Subject: Notification de commande\n\n" + body) + # message = message.encode('utf8') + # + # smtpObj = smtplib.SMTP('smtp.etsmtl.ca') + # smtpObj.sendmail(sender, receivers, message) + # Commit try: db.session.commit() @@ -249,6 +260,7 @@ def update(id): return response + # Delete a menu @orders.route('/', methods=['DELETE', 'OPTIONS']) def delete(id): @@ -281,4 +293,4 @@ def delete(id): response.status_code = 200 response.mimetype = 'application/json' - return response \ No newline at end of file + return response