def retry_import(request): ''' ingest a goodreads csv ''' job = get_object_or_404(models.ImportJob, id=request.POST.get('import_job')) items = [] for item in request.POST.getlist('import_item'): items.append(get_object_or_404(models.ImportItem, id=item)) job = goodreads_import.create_retry_job( request.user, job, items, ) goodreads_import.start_import(job) return redirect('/import-status/%d' % job.id)
def import_data(request): ''' ingest a goodreads csv ''' form = forms.ImportForm(request.POST, request.FILES) if form.is_valid(): include_reviews = request.POST.get('include_reviews') == 'on' privacy = request.POST.get('privacy') try: job = goodreads_import.create_job( request.user, TextIOWrapper(request.FILES['csv_file'], encoding=request.encoding), include_reviews, privacy, ) except (UnicodeDecodeError, ValueError): return HttpResponseBadRequest('Not a valid csv file') goodreads_import.start_import(job) return redirect('/import_status/%d' % (job.id, )) return HttpResponseBadRequest()