Exemplo n.º 1
0
def home(request):
    if request.method == 'POST':
        logger.info('create order request: {}'.format(request.POST))
        order_form = OrderForm(request.POST)

        if 'calculate_order' in request.POST:
            logger.info('calculate_order request: {}'.format(request.POST))

            if not order_form.is_valid():
                return render(request, 'home.html', {'form': order_form})

            cost = get_order_cost(request.POST)
            return render(request, 'home.html', {
                'form': order_form,
                'cost': cost
            })

        else:
            if not order_form.is_valid():
                return render(request, 'home.html', {'form': order_form})

            order = order_form.save()

            # send email about new order
            text_content, html_content = get_content_for_mail(order)
            send_email('New gruzimo order {}'.format(order.id), text_content,
                       html_content, '*****@*****.**',
                       settings.EMAIL_SEND_USER)

            messages.success(request, 'Ваша заявка отправлена')
            return redirect('home')

    else:
        order_form = OrderForm()
    return render(request, 'home.html', {'form': order_form})
Exemplo n.º 2
0
def updateOrder(request, pk):
    order = Order.objects.get(id=pk)
    form = OrderForm(request.POST, instance=order)
    if request.method == 'POST':
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            return redirect('home')
    else:
        form = OrderForm(instance=order)
    context = {
        'form': form,
    }
    return render(request, 'accounts/order_form.html', context=context)
Exemplo n.º 3
0
def add_order(request):
    if request.method == "POST":
        form = OrderForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        form = OrderForm()
        context = {'form': form}
        return render(request, 'crmaccounts/add_order.html', context)
Exemplo n.º 4
0
def createOrder(request):
    form = OrderForm()
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')

    context = {'form': form}
    return render(request, 'orders/order_create.html', context)
Exemplo n.º 5
0
def update_order(request, pk):
    order = Orders.objects.get(id=pk)
    form = OrderForm(instance=order)
    if request.method == "POST":
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            return redirect('/')
    context = {'form': form}
    return render(request, 'crmaccounts/update_order.html', context)
Exemplo n.º 6
0
def deleteorder(request, pk):
    order = Order.objects.get(id=pk)   #gets and order with a specific id from the Order class.  the id is given value pk to return to the function as an argument.
    form = OrderForm(instance = order)

    if request.method == 'POST':           #same save function as above refers to the method in the html form tag.
        order.delete()       #the delete function for an item in our database. in this case, the one with tthe specific one from above.
        return redirect('/')

    context = {
    'order': order,
    'form': form,
    }
    return render(request, 'accounts/deleteorderform.html', context)
Exemplo n.º 7
0
def update_order(request, pk):
    order = Order.objects.get(id=pk)
    form = OrderForm(instance=order)
    if request.method == "POST":
        print(request.POST)
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            return redirect("home")
    context = {"form": form}
    return render(request, "accounts/order_form.html", context)
Exemplo n.º 8
0
def update_order(request, pk):
    order = Order.objects.get(id = pk)
    form = OrderForm(instance = order)

    if request.method == 'POST':
        form = OrderForm(request.POST, instance = order)
        if form.is_valid():
            form.save()
            return redirect('/') #redirect to dashboard

    return render(request, 'accounts/order_form.html', {'form':form, 'header': 'Update Order:'})
Exemplo n.º 9
0
def updateOrder(request, pk):
    order = Order.objects.get(id=pk)
    form = OrderForm(instance=order)
    if request.method == 'POST':
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            logger.info("order updated by admin")
            return redirect('customer', order.customer.pk)
    context = {'form': form}
    return render(request, 'accounts/update_order.html', context)
Exemplo n.º 10
0
def updateOrder(request, pk):
    order = Order.objects.get(id=pk)
    form = OrderForm(instance=order)

    if request.method == 'POST':
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            return redirect('/')

    context = {'form': form}
    return render(request, 'orders/order_update.html', context)
Exemplo n.º 11
0
def createOrder(request, pk):
    customer = Customer.objects.get(id=pk)
    if request.method == 'POST':
        form = OrderForm(request.POST, initial={'customer': customer})
        if form.is_valid():
            form.save()
            return redirect('home')
    else:
        form = OrderForm(initial={'customer': customer})
    context = {
        'form': form,
    }
    return render(request, 'accounts/order_form.html', context=context)
def updateOrder(request, pk):
    updateOrder = db_functions.updateOrder(pk)
    if request.method == "POST":
        form = OrderForm(request.POST, instance=updateOrder)
        if form.is_valid():
            form.save()
            # print("debug on line 69")
            return redirect('home')
    else:
        form = OrderForm(instance=updateOrder)
        context = {
            'form': form,
        }
        return render(request, "accounts/order_form.html", context)
Exemplo n.º 13
0
def updateOrder(request, pk):

    order = Order.objects.get(id=pk)
    form = OrderForm(instance=order)

    if request.method == 'POST':
        #print('Priting POST: ', request.POST)
        form = OrderForm(request.POST, instance=order)
        if form.is_valid():
            form.save()
            return redirect('/')

    context = {'form': form}
    return render(request, 'accounts/order_form.html', context)
Exemplo n.º 14
0
def updateOrder(request, order_pk):

    order_id = Order.objects.get(pk=order_pk)
    form = OrderForm(instance=order_id)

    if request.method == "POST":
        form = OrderForm(request.POST, instance=order_id)
        if form.is_valid():
            form.save()
            return redirect('home')

    context = {'form': form}

    return render(request, 'accounts/order_form.html', context)
def individualCustomerUpdateOrder(request, pk, customer_id):
    updateOrder = db_functions.updateOrder(pk)
    if request.method == "POST":
        form = OrderForm(request.POST, instance=updateOrder)
        if form.is_valid():
            form.save()
            # print("debug on line 83")
            return redirect('customer', pk=customer_id)
    else:
        form = OrderForm(instance=updateOrder)
        context = {
            'form': form,
        }
        return render(request, "accounts/order_form.html", context)
Exemplo n.º 16
0
def updateorder(request, pk):

    order = Order.objects.get(id=pk)
    form = OrderForm(instance = order)      #prefills the form with the stuff to the specific order id

    if request.method == 'POST':           #same save function as above
        form = OrderForm(request.POST, instance= order)  #again saves that specific instance instead of making a new one.
        if form.is_valid():
            form.save()
            return redirect('/')

    context={
    'form': form,
    }
    return render(request, 'accounts/updateorderform.html', context)
Exemplo n.º 17
0
def create_order(request, pk):
    OrderFormSet = inlineformset_factory(Customer,
                                         Order,
                                         fields=('product', 'status'),
                                         extra=10)
    customer = Customer.objects.get(id=pk)
    formset = OrderFormSet(queryset=Order.objects.none(), instance=customer)
    #form = OrderForm(initial={'customer':customer})
    if request.method == 'POST':
        #print('Printing POST:', request.POST)
        form = OrderForm(request.POST)
        formset = OrderFormSet(request.POST, instance=customer)
        if formset.is_valid():
            formset.save()
            return redirect('/')

    context = {'form': formset}
    return render(request, 'accounts/order_form.html', context)