Beispiel #1
0
def send_to_manager(request, order_id):
    order = Order.get_by_id(order_id)
    if not order:
        return render_to_response({
            'api':{
                'success': False,
                'msg': 'Order %s not found' % order_id
            }
        }, status=404)
    managers = Manager.query()
    if not managers.count():
        return render_json_response({
            'api':{
                'success': False,
                'msg': 'Managers not found.'
            }
        }, status=404)
    subject = render_to_string('order/msg/subject.html', {'order':order})
    msg = render_to_string('order/msg/body.html', {'order': order})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = msg
    email.sender = settings.DEFAULT_MAIL_FROM
    for manager in managers:
       if manager.communication.email:
           email.to = manager.communication.email
           email.send()
    return render_json_response({
        'api':{
            'success': True,
            'msg': 'Order notifications were sent'
        }
    })
Beispiel #2
0
def get_order(request, id):
    order = Order.get_by_id(id)
    if request.method == 'PUT':
        model = simplejson.loads(request.data)
        status = model.get('status', 0)
        if order.status != status:
            order.status = status
            order.put()
    return render_json_response(order.to_json())