Skip to content

Commit

Permalink
add mail notification
Browse files Browse the repository at this point in the history
  • Loading branch information
william57m committed Nov 20, 2014
1 parent 21682ea commit d82a3e2
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions webserver/controllers/orders.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -171,7 +170,6 @@ def create():

order.lines_order.append(LineOrder(dish_id=dish_id, quantity=quantity))


# Add menu
db.session.add(order)

Expand Down Expand Up @@ -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 <donotreply@etsfood.me> \n"
# "To: Benjamin Comeau <benjamin.comeau.1@etsmtl.me>\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()
Expand All @@ -249,6 +260,7 @@ def update(id):

return response


# Delete a menu
@orders.route('/<int:id>', methods=['DELETE', 'OPTIONS'])
def delete(id):
Expand Down Expand Up @@ -281,4 +293,4 @@ def delete(id):
response.status_code = 200
response.mimetype = 'application/json'

return response
return response

0 comments on commit d82a3e2

Please sign in to comment.