in catalog/views.py [0:0]
def createProduct(request, storeId):
''' view method for creating a product for a store'''
if canViewThisStore(storeId, request.user.id):
# get the corresponding store
store = Store.objects.get(id=storeId)
if request.method == "POST":
# Create a form instance and populate it with data from the request (binding):
form = CreateProductForm(request.POST)
# Check if the form is valid:
if form.is_valid():
# do the create product, then redirect to product view
product_category_id = request.POST.get("google-product-category-id")
product_category_string = request.POST.get(
"google-product-category-string"
)
create_product(
store.catalog_id,
product_category_id,
product_category_string,
**form.cleaned_data
)
return redirect("viewProducts", storeId)
form = CreateProductForm(initial={"business_name": store.name})
breadcrumbs = [
(store.name, "viewStore", store.id),
("Products", "viewProducts", store.id),
]
context = {
"form": form,
"page_title": "Create Product",
"store": store,
"breadcrumbs": breadcrumbs,
"needsProductCategories": True,
}
return render(request, "core/create.html", context)
else:
return render(request, "403.html")