diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py index 5ad795cd..ecceb457 100644 --- a/bookwyrm/connectors/bookwyrm_connector.py +++ b/bookwyrm/connectors/bookwyrm_connector.py @@ -79,10 +79,17 @@ class Connector(AbstractConnector): cover_data = data.get('attachment') if not cover_data: return None - cover_url = cover_data[0].get('url') - response = requests.get(cover_url) + try: + cover_url = cover_data[0].get('url') + except IndexError: + return None + try: + response = requests.get(cover_url) + except ConnectionError: + return None + if not response.ok: - response.raise_for_status() + return None image_name = str(uuid4()) + '.' + cover_url.split('.')[-1] image_content = ContentFile(response.content) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 9b8afaa6..5c26ad45 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -177,10 +177,9 @@ class Connector(AbstractConnector): ''' load that author ''' if not re.match(r'^OL\d+A$', olkey): raise ValueError('Invalid OpenLibrary author ID') - try: - return models.Author.objects.get(openlibrary_key=olkey) - except models.Author.DoesNotExist: - pass + author = models.Author.objects.filter(openlibrary_key=olkey).first() + if author: + return author url = '%s/authors/%s.json' % (self.base_url, olkey) data = get_data(url) diff --git a/bookwyrm/goodreads_import.py b/bookwyrm/goodreads_import.py index fe5ac56e..d5c0ad42 100644 --- a/bookwyrm/goodreads_import.py +++ b/bookwyrm/goodreads_import.py @@ -20,7 +20,7 @@ def create_job(user, csv_file, include_reviews, privacy): ) for index, entry in enumerate(list(csv.DictReader(csv_file))[:MAX_ENTRIES]): if not all(x in entry for x in ('ISBN13', 'Title', 'Author')): - raise ValueError("Author, title, and isbn must be in data.") + raise ValueError('Author, title, and isbn must be in data.') ImportItem(job=job, index=index, data=entry).save() return job @@ -41,8 +41,11 @@ def import_data(job_id): for item in job.items.all(): try: item.resolve() - except HTTPError: - pass + except: + item.fail_reason = 'Error loading book' + item.save() + continue + if item.book: item.save() results.append(item) @@ -51,7 +54,7 @@ def import_data(job_id): outgoing.handle_imported_book( job.user, item, job.include_reviews, job.privacy) else: - item.fail_reason = "Could not find a match for book" + item.fail_reason = 'Could not find a match for book' item.save() finally: create_notification(job.user, 'IMPORT', related_import=job) diff --git a/bookwyrm/templates/import.html b/bookwyrm/templates/import.html index c3644812..8e3f5eb4 100644 --- a/bookwyrm/templates/import.html +++ b/bookwyrm/templates/import.html @@ -14,7 +14,8 @@
-
diff --git a/bookwyrm/templates/import_status.html b/bookwyrm/templates/import_status.html index 7db2ba3d..c1dbb26e 100644 --- a/bookwyrm/templates/import_status.html +++ b/bookwyrm/templates/import_status.html @@ -6,29 +6,44 @@

Import Status

- Import started: {{ job.created_date | naturaltime }} + Import started: {{ job.created_date | naturaltime }} +

+ {% if task.successful %}

- {% if task.ready %} - Import completed: {{ task.date_done | naturaltime }} - {% if task.failed %} -

TASK FAILED

-

- {{ task.info }} + Import completed: {{ task.date_done | naturaltime }} +

+ {% elif task.failed %} +
TASK FAILED
{% endif %}
- {% if job.import_status %} - {% include 'snippets/status.html' with status=job.import_status %} - {% endif %} - {% else %} + {% if not task.ready %} Import still in progress.

- (Hit reload to update!) + (Hit reload to update!) +

{% endif %}
+{% if failed_items %}
+

Failed to load

+ +
+{% endif %} + +
+

Successfully imported

diff --git a/bookwyrm/views.py b/bookwyrm/views.py index 771e6a85..b40a75a7 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -209,10 +209,14 @@ def import_status(request, job_id): if job.user != request.user: raise PermissionDenied task = app.AsyncResult(job.task_id) + items = job.items.order_by('index').all() + failed_items = [i for i in items if i.fail_reason] + items = [i for i in items if not i.fail_reason] return TemplateResponse(request, 'import_status.html', { 'title': 'Import Status', 'job': job, - 'items': job.items.order_by('index').all(), + 'items': items, + 'failed_items': failed_items, 'task': task })
@@ -59,9 +74,10 @@ {{ item.data|dict_key:'Author' }} - {% if item.book %}✓ - {% elif item.fail_reason %} - {{ item.fail_reason }} + {% if item.book %} + + Imported + {% endif %}