def import_page(request): ''' import history from goodreads ''' return TemplateResponse( request, 'import.html', { 'import_form': forms.ImportForm(), 'jobs': models.ImportJob.objects.filter( user=request.user).order_by('-created_date'), 'limit': goodreads_import.MAX_ENTRIES, })
def import_data(request): ''' ingest a goodreads csv ''' form = forms.ImportForm(request.POST, request.FILES) if form.is_valid(): try: job = goodreads_import.create_job( request.user, TextIOWrapper(request.FILES['csv_file'], encoding=request.encoding)) except (UnicodeDecodeError, ValueError): return HttpResponseBadRequest('Not a valid csv file') goodreads_import.start_import(job) return redirect('/import_status/%d' % (job.id, )) return HttpResponseBadRequest()
def import_data(request): ''' ingest a goodreads csv ''' form = forms.ImportForm(request.POST, request.FILES) if form.is_valid(): results = [] reviews = [] failures = [] for item in GoodreadsCsv( TextIOWrapper(request.FILES['csv_file'], encoding=request.encoding)): try: item.resolve() except HTTPError: pass if item.book: results.append(item) if item.rating or item.review: reviews.append(item) else: failures.append(item) outgoing.handle_import_books(request.user, results) for item in reviews: review_title = "Review of {!r} on Goodreads".format( item.book.title, ) if item.review else "" outgoing.handle_review( request.user, item.book, review_title, item.review, item.rating, ) return TemplateResponse(request, 'import_results.html', { 'success_count': len(results), 'failures': failures, }) return HttpResponseBadRequest()
def import_page(request): ''' import history from goodreads ''' return TemplateResponse(request, 'import.html', { 'import_form': forms.ImportForm(), })