Ejemplo n.º 1
0
def send_order_to_manager(request, order_key):
    order = Order.get(order_key)

    gifts = []
    for gift in order.items:
        gifts.append(OrderItem.get(gift))

    subject = render_to_string('store/order2manager_subject.html', {'order_id':order.key().id()})
    subject = ''.join(subject.splitlines())
    message = render_to_string('store/order2manager_body.html', {'order': order, 'gifts':gifts})

    email = mail.EmailMessage()
    email.subject = subject
    email.html = message
    email.sender = settings.DEFAULT_MAIL_FROM

    try:
        if order.user and order.user.register_user and order.user.register_user.manager:
            email.to = order.user.register_user.manager.email
            email.send()
        else:
            managers = Manager.all()
            for manager in managers:
                email.to = manager.email
                email.send()
    except Exception:
        managers = Manager.all()
        for manager in managers:
            email.to = manager.email
            email.send()

    return Response("OK")
Ejemplo n.º 2
0
def order(request, order_key):
    order_obj = Order.get(order_key)
    if not order_obj:
        redirect(url_for('admin/orders_lists'))
    gifts = []
    for gift in order_obj.items:
        gifts.append(OrderItem.get(gift))
    return render_to_response('admin/order.html', {'order':order_obj, 'gifts':gifts})
Ejemplo n.º 3
0
def make_order(request, item_id = None):
    if not request.session or not request.session.get('order_items_count',0):
        return render_to_response('store/make_order_error.html')

    if not request.user or request.user.is_anonymous():
        return render_to_response('store/login_to_order.html')

    gifts = recalculate_order(request, item_id)
    if request.user and not request.user.is_anonymous():
        form = OrderingUserForm(initial={'name':request.user.first_name, 'telephone':request.user.telephone, 'email':request.user.email})
    else:
        form = OrderingUserForm()
    if request.method == 'POST':
        if form.validate(request.form):
            user = form.save()
            if request.user and not request.user.is_anonymous():
                user.register_user = request.user
            user.put()
            order =Order(user=user)
            for gift in gifts:
                new_gift = OrderItem(gift=gift, count = gift.number)
                if not request.user or request.user.is_anonymous():
                    new_gift.price = gift.price
                else:
                    new_gift.price = gift.real_price
                new_gift.put()
                order.items.append(new_gift.key())
            order.total_price = request.session['order_total_price']
            order.put()
            request.session['order'] = {}
            request.session['order_total_price'] = request.session['order_items_number'] = request.session['order_items_count'] = 0

            def txn():
                taskqueue.add(url=url_for('store/send_order_to_manager',
                                    order_key=str(order.key())),
                                    transactional=True)
            db.run_in_transaction(txn)

            return render_to_response('store/make_order_success.html')
    if item_id:
        if not request.session['order_items_number']:
            return render_to_response('store/make_order_error_text.html')
        return render_to_response('store/make_order_list.html', {'gifts':gifts, 'form':form.as_widget()})
    return render_to_response('store/make_order.html', {'gifts':gifts, 'form':form.as_widget()})