def updateProduct()

in catalog/views.py [0:0]


def updateProduct(request, productId, storeId):
    ''' view method for updating a specific product for a store '''
    # get the store
    store = Store.objects.get(id=storeId)

    if request.method == "POST":
        form = UpdateProductForm(request.POST)
        # Check if the form is valid:
        if form.is_valid():
            # do the create product, then redirect to product view
            if form.cleaned_data:
                product = update_product(productId, **form.cleaned_data)
                sync_catalog_async.delay(storeId, items=[productId])
            return redirect("viewProducts", storeId)

    product = Product.objects.filter(id=productId).values()[0]
    form = UpdateProductForm(initial={**product})

    breadcrumbs = [
        (store.name, "viewStore", store.id),
        ("Products", "viewProducts", store.id),
    ]
    context = {
        "form": form,
        "page_title": "Update Product",
        "breadcrumbs": breadcrumbs,
        "button": "Update",
    }

    return render(request, "core/update.html", context)