def locations_import_confirm(request, id, template_name='locations/import-confirm.html'): """ Confirm the locations import and continue with the process. This can only be accessed via a hidden post form from the preview page. That will hold the original mappings selected by the user. """ locport = get_object_or_404(LocationImport, pk=id) if request.method == "POST": form = ImportMapForm(request.POST, locport=locport) if form.is_valid(): cleaned_data = form.cleaned_data file_path = str(locport.get_file().file.name) if not settings.CELERY_IS_ACTIVE: # if celery server is not present # evaluate the result and render the results page result = ImportLocationsTask() locations, stats = result.run(request.user, file_path, cleaned_data) return render_to_response(template_name, { 'locations': locations, 'stats': stats, 'now': datetime.now(), }, context_instance=RequestContext(request)) else: result = ImportLocationsTask.delay(request.user, file_path, cleaned_data) return redirect('locations_import_status', result.task_id) else: return redirect('locations_import_preview', locport.id)
def locations_import_preview(request, id, template_name='locations/import-map-fields.html'): """ This will generate a form based on the uploaded CSV for field mapping. A preview will be generated based on the mapping given. """ locport = get_object_or_404(LocationImport, pk=id) if request.method == 'POST': form = ImportMapForm(request.POST, locport=locport) if form.is_valid(): # Show the user a preview based on the mapping cleaned_data = form.cleaned_data #file_path = os.path.join(settings.MEDIA_ROOT, locport.get_file().file.name) file_path = locport.get_file().file.name locations, stats = parse_locs_from_csv(file_path, cleaned_data) # return the form to use it for the confirm view template_name = 'locations/import-preview.html' return render_to_response(template_name, { 'locations': locations, 'stats': stats, 'locport': locport, 'form': form, 'now': datetime.now(), }, context_instance=RequestContext(request)) else: form = ImportMapForm(locport=locport) return render_to_response(template_name, { 'form': form, 'locport': locport, 'now': datetime.now(), }, context_instance=RequestContext(request))
def locations_import_confirm(request, id, template_name='locations/import-confirm.html'): """ Confirm the locations import and continue with the process. This can only be accessed via a hidden post form from the preview page. That will hold the original mappings selected by the user. """ locport = get_object_or_404(LocationImport, pk=id) if request.method == "POST": form = ImportMapForm(request.POST, locport=locport) if form.is_valid(): cleaned_data = form.cleaned_data file_path = os.path.join(settings.MEDIA_ROOT, locport.get_file().file.name) if not settings.CELERY_IS_ACTIVE: # if celery server is not present # evaluate the result and render the results page result = ImportLocationsTask() locations, stats = result.run(request.user, file_path, cleaned_data) return render_to_response( template_name, { 'locations': locations, 'stats': stats, 'now': datetime.now(), }, context_instance=RequestContext(request)) else: result = ImportLocationsTask.delay(request.user, file_path, cleaned_data) return redirect('locations_import_status', result.task_id) else: return redirect('locations_import_preview', locport.id)