Esempio n. 1
0
def order_lists(request):
    added_count = Order.all().filter('status =', ST_ADDED).count()
    if not added_count: added_count = 0
    accepted_count = Order.all().filter('status =', ST_ACCEPTED).count()
    if not accepted_count: accepted_count = 0
    completed_count = Order.all().filter('status =', ST_COMPLETED).count()
    if not completed_count: completed_count = 0
    return render_to_response('admin/orders_lists.html', {'added_count':added_count, 'accepted_count':accepted_count, 'completed_count':completed_count})
Esempio n. 2
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")
Esempio n. 3
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})
Esempio n. 4
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()})
Esempio n. 5
0
def user_delete(request, key):
    try:
        user = UserProfile.get(key)
    except BadKeyError:
        return redirect('admin/users')
    if user:
        ord_usr = OrderingUser.all().filter('register_user ='******'user ='******'admin/users')
Esempio n. 6
0
 def thx():
     order_obj = Order.get(order_key)
     if order_obj:
         order_obj.status = ST_COMPLETED
         order_obj.put()
Esempio n. 7
0
 def thx():
     order_obj = Order.get(order_key)
     if order_obj:
         order_obj.status = ST_ACCEPTED
         order_obj.manager = request.user.key()
         order_obj.put()
Esempio n. 8
0
def order_delete(request, order_key):
    order_obj = Order.get(order_key)
    if order_obj:
        order_obj.delete()
    return order_lists(request)
Esempio n. 9
0
def orders_completed(request):
    orders = Order.all().filter('status =', ST_COMPLETED).order('-modiff_time')
    return render_to_response('admin/orders.html', {'orders':orders, 'title':u'Выполненные заказы'})
Esempio n. 10
0
def orders_accepted(request):
    orders = Order.all().filter('status =', ST_ACCEPTED).order('-modiff_time')
    return render_to_response('admin/orders.html', {'orders':orders, 'title':u'Заказы в процессе выполнения'})
Esempio n. 11
0
def orders_added(request):
    orders = Order.all().filter('status =', ST_ADDED).order('-add_time')
    return render_to_response('admin/orders.html', {'orders':orders, 'title':u'Новые заказы'})