def submit_new_product() -> redirect: form = ProductForm() attachments = Attachment().fetch_user_attachments() for item in Category().fetch_user_categories(): form.categories.choices.append( [item.category_name, item.category_name]) for item in attachments: form.attachment_file.choices.append( [item.attachment_filename, item.original_attachment_filename]) if not form.validate_on_submit(): flash(list(form.errors.values())[0]) return redirect(url_for('dashboard.create_product')) Product().add(request) flash(['Product Successfully Created']) return redirect(url_for('dashboard.products'))
def update_product(product_id): form = ProductForm() attachments = Attachment().fetch_user_attachments() for item in Category().fetch_user_categories(): form.categories.choices.append( [item.category_name, item.category_name]) for item in attachments: form.attachment_file.choices.append( [item.attachment_filename, item.original_attachment_filename]) if not form.validate_on_submit(): flash(list(form.errors.values())[0]) return redirect( url_for('dashboard.edit_product', product_id=product_id)) if not Product().update(request, product_id): flash(['Something went wrong. Please try again later']) return redirect(url_for('dashboard.products')) flash(['Product Successfully Updated']) return redirect(url_for('dashboard.edit_product', product_id=product_id))