Exemple #1
0
def new_order(request):
    # Link used when User make order
    try:
        if not request.user.is_authenticated():
            raise AccessError
        if not check_basket(request.user):
            raise BasketError
        addr = request.POST.get('addr')
        address = DeliveryAddress.objects.get(user=request.user, pk=int(addr))
        order = Order()
        order.address = str(address)
        order.first_name = address.first_name
        order.middle_name = address.middle_name
        order.last_name = address.last_name
        order.user = request.user
        order.name = ''
        order.comment = ''
        order.status = STATUS_WAIT
        order.save()
        basket = Basket.objects.filter(user=request.user)
        for item in basket:
            order_item = OrderItem()
            order_item.order = order
            order_item.product_name = item.product.name
            order_item.product_origin = item.product
            order_item.product_url = item.product.get_absolute_url
            order_item.amount = item.product.amount
            order_item.product_pn = item.product.shop_pn
            order_item.quantity = item.quantity
            order_item.save()
            item.product.quantity -= item.quantity
            item.product.save()
        basket.delete()
        recipients = [settings.SHOP_MANAGER]
        mail_dict = {'order': order}
        subject = 'emails/neworder_admin_subject.txt'
        body = 'emails/neworder_admin_body.txt'
        send_template_mail(subject,body,mail_dict,recipients)
        try:
            recipients = [request.user.email]
            mail_dict = {'order': order}
            subject = 'emails/neworder_client_subject.txt'
            body = 'emails/neworder_client_body.txt'
            send_template_mail(subject,body,mail_dict,recipients)
        except:
            pass
        payload = {'success': True,'id':order.pk, 'location':order.get_absolute_url()}
    except AccessError:
        payload = {'success': False}
    except BasketError:
        payload = {'success': False, 'message':_('Product in basket not available')}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Exemple #2
0
def new_order(request):
    # Link used when User make order
    try:
        if not request.user.is_authenticated():
            raise AccessError
        if not check_basket(request.user):
            raise BasketError
        addr = request.POST.get('addr')
        address = DeliveryAddress.objects.get(user=request.user, pk=int(addr))
        order = Order()
        order.address = str(address)
        order.first_name = address.first_name
        order.middle_name = address.middle_name
        order.last_name = address.last_name
        order.user = request.user
        order.name = ''
        order.comment = ''
        order.status = STATUS_WAIT
        order.save()
        basket = Basket.objects.filter(user=request.user)
        for item in basket:
            order_item = OrderItem()
            order_item.order = order
            order_item.product_name = item.product.name
            order_item.amount = item.product.amount
            order_item.product_pn = item.product.shop_pn
            order_item.quantity = item.quantity
            order_item.save()
            item.product.quantity -= item.quantity
            item.product.save()
        basket.delete()
        payload = {'success': True,'id':order.pk, 'location':order.get_absolute_url()}
    except AccessError:
        payload = {'success': False}
    except BasketError:
        payload = {'success': False, 'message':_('Product in basket not available')}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)