def import_product_migrations(request): context = {} if request.method == "POST": form = ImportProductMigrationFileUploadForm(request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES['excel_file']) job_file.save() eta = now() + timedelta(seconds=3) task = tasks.import_product_migrations.apply_async( eta=eta, kwargs={ "job_file_id": job_file.id, "user_for_revision": request.user.username }) set_meta_data_for_task( task_id=task.id, title="Import product migrations from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_product_migrations")) return redirect( reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductMigrationFileUploadForm() context["form"] = form return render(request, "productdb/import/import_product_migrations.html", context=context)
def import_product_migrations(request): context = {} if request.method == "POST": form = ImportProductMigrationFileUploadForm(request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES["excel_file"]) job_file.save() task = tasks.import_product_migrations.delay( job_file_id=job_file.id, user_for_revision=request.user.username ) set_meta_data_for_task( task_id=task.id, title="Import product migrations from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_product_migrations"), ) return redirect(reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductMigrationFileUploadForm() context["form"] = form return render(request, "productdb/import/import_product_migrations.html", context=context)
def import_products(request): """import of products using Excel :param request: :return: """ context = {} if request.method == "POST": form = ImportProductsFileUploadForm(request.user, request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES["excel_file"]) job_file.save() task = tasks.import_price_list.delay( job_file_id=job_file.id, create_notification_on_server=not form.cleaned_data["suppress_notification"], update_only=form.cleaned_data["update_existing_products_only"], user_for_revision=request.user.username, ) set_meta_data_for_task( task_id=task.id, title="Import products from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_products"), ) return redirect(reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductsFileUploadForm(request.user) context["form"] = form return render(request, "productdb/import/import_products.html", context=context)
def import_products(request): """ import of products using Excel :param request: :return: """ context = {} if request.method == "POST": form = ImportProductsFileUploadForm(request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES['excel_file']) job_file.save() if request.user.is_superuser: # only the superuser is allowed to add a server notification message create_notification = not form.cleaned_data[ "suppress_notification"] else: # all other users are not allowed to add a server notification create_notification = False task = tasks.import_price_list.delay( job_file_id=job_file.id, create_notification_on_server=create_notification, user_for_revision=request.user.username) set_meta_data_for_task( task_id=task.id, title="Import products from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_products")) return redirect( reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductsFileUploadForm( initial={"suppress_notification": True}) if not request.user.is_superuser: form.fields["suppress_notification"].disabled = True context['form'] = form return render(request, "productdb/import/import_products.html", context=context)
def import_products(request): """import of products using Excel :param request: :return: """ context = {} if request.method == "POST": form = ImportProductsFileUploadForm(request.user, request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES['excel_file']) job_file.save() eta = now() + timedelta(seconds=3) task = tasks.import_price_list.apply_async( eta=eta, kwargs={ "job_file_id": job_file.id, "create_notification_on_server": not form.cleaned_data["suppress_notification"], "update_only": form.cleaned_data["update_existing_products_only"], "user_for_revision": request.user.username }) set_meta_data_for_task( task_id=task.id, title="Import products from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_products")) return redirect( reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductsFileUploadForm(request.user) context['form'] = form return render(request, "productdb/import/import_products.html", context=context)
def import_products(request): """ import of products using Excel :param request: :return: """ context = {} if request.method == "POST": form = ImportProductsFileUploadForm(request.POST, request.FILES) if form.is_valid(): # file is valid, save and execute the import job job_file = JobFile(file=request.FILES['excel_file']) job_file.save() if request.user.is_superuser: # only the superuser is allowed to add a server notification message create_notification = not form.cleaned_data["suppress_notification"] else: # all other users are not allowed to add a server notification create_notification = False task = tasks.import_price_list.delay( job_file_id=job_file.id, create_notification_on_server=create_notification, user_for_revision=request.user.username ) set_meta_data_for_task( task_id=task.id, title="Import products from Excel sheet", auto_redirect=False, redirect_to=reverse("productdb:import_products") ) return redirect(reverse("task_in_progress", kwargs={"task_id": task.id})) else: form = ImportProductsFileUploadForm(initial={"suppress_notification": True}) if not request.user.is_superuser: form.fields["suppress_notification"].disabled = True context['form'] = form return render(request, "productdb/import/import_products.html", context=context)