Exemple #1
0
def view_item(request, vendor_id):
    success_message = None
    error_message = None

    bank = request.user.get_profile().bank
    vend = get_object_or_404(Vendor, pk=vendor_id, bank=bank)

    if request.method == 'POST':

        form = VendorForm(request.POST, instance=vend)
        if form.is_valid():
            # do some processing (like saving it)
            form.save()
            success_message = "Data saved successfully."
        else:
            # form is not valid, display an error
            error_message = "There were errors in your submission."

    else:
        form = VendorForm(instance=vend)


    return render(
        'vendor/item.html', 
        {   'module': 'vendor',
            'vendor': vend,
            'success_message': success_message,
            'error_message': error_message,
            'form': form }, 
        request,
        template_pdf='vendor/item_pdf.html', 
    )
Exemple #2
0
def add(request):
    error_message = None
    success_message = None
    success_id = None
    success_name = None

    profile = request.user.get_profile()

    # ignore requests from users 
    # who don't have access
    if profile.level < 1:
        raise Http404 

    bank = request.user.get_profile().bank

    if request.method == 'POST':
        # so some posty stuff
        form = VendorForm(request.POST)
        if form.is_valid():
            # do some processing (like saving it)

            # use commit=False to allow us to
            # modify the new vendor before saving it
            new_ex = form.save(commit=False)
            new_ex.bank = bank
            new_ex.save()

            success_id = new_ex.id
            success_name = new_ex.name
            form = VendorForm()  # create a new blank form for the next one.
        else:
            # form is not valid, display an error
           error_message = "There were errors in your submission."
    else:
        # create a blank form
        form = VendorForm()

    return render('vendor/add.html', 
              { 'form': form,
                'success_id': success_id,
                'success_name': success_name,
                'error_message': error_message,
                'success_message': success_message },
              request)
Exemple #3
0
def modify_products(request, id):
    product = Product.objects.get(pk=id)
    vendor_qty = VendorQty.objects.get(Vendor=request.user, product=product)
    product_form = ProductsAdd(instance=product)
    vendor_form = VendorForm(instance=vendor_qty)
    if request.method == 'POST':
        product_form = ProductsAdd(request.POST, instance=product)
        vendor_form = VendorForm(request.POST, instance=vendor_qty)
        if product_form.is_valid() and vendor_form.is_valid():
            product_form.save()
            vendor_form.save()
            return redirect('vendor:view_products')
        else:
            print('Forms are invalid')
    return render(request, 'vendor/modify_product.html', {
        'product_form': product_form,
        'vendor_form': vendor_form
    })