Generate reviews from import data.

This commit is contained in:
Adam Kelly 2020-04-01 15:41:19 +01:00
parent 1a5af7899b
commit 9933dbba54
2 changed files with 14 additions and 0 deletions

View file

@ -88,6 +88,14 @@ class GoodreadsItem:
if self.line['Exclusive Shelf']:
return GOODREADS_SHELVES[self.line['Exclusive Shelf']]
@property
def review(self):
return self.line['My Review']
@property
def rating(self):
return int(self.line['My Rating'])
def __repr__(self):
return "<GoodreadsItem {!r}>".format(self.line['Title'])

View file

@ -357,16 +357,22 @@ def import_data(request):
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)):
if item.book:
results.append(item)
if item.rating:
reviews.append(item)
else:
failures.append(item)
outgoing.handle_import_books(request.user, results)
for item in reviews:
outgoing.handle_review(
request.user, item.book, "", item.review, item.rating)
return TemplateResponse(request, 'import_results.html', {
'success_count': len(results),
'failures': failures,