From 0b8f8e3659d7994c61d61c9f7789f793ebdde92b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 30 Sep 2020 19:43:42 -0700 Subject: [PATCH] Fixes celery media path --- bookwyrm/connectors/abstract_connector.py | 5 ++++- bookwyrm/connectors/openlibrary.py | 7 +++++++ celerywyrm/settings.py | 3 +++ celerywyrm/urls.py | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index e9c25f8e0..6d114387a 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -249,7 +249,10 @@ def update_from_mappings(obj, data, mappings): continue # extract the value in the right format - value = mapping.formatter(value) + try: + value = mapping.formatter(value) + except: + continue # assign the formatted value to the model obj.__setattr__(mapping.local_field, value) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index d74735d20..fcfe387aa 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -143,17 +143,24 @@ class Connector(AbstractConnector): def expand_book_data(self, book): work = book + # go from the edition to the work, if necessary if isinstance(book, models.Edition): work = book.parent_work + # we can mass download edition data from OL to avoid repeatedly querying edition_options = self.load_edition_data(work.openlibrary_key) for edition_data in edition_options.get('entries'): olkey = edition_data.get('key').split('/')[-1] + # make sure the edition isn't already in the database if models.Edition.objects.filter(openlibrary_key=olkey).count(): continue + + # creates and populates the book from the data edition = self.create_book(olkey, edition_data, models.Edition) + # ensures that the edition is associated with the work edition.parent_work = work edition.save() + # get author data from the work if it's missing from the edition if not edition.authors and work.authors: edition.authors.set(work.authors.all()) diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index 7f7bba2b2..a17ff8bb8 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -144,3 +144,6 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, env('STATIC_ROOT', 'static')) +MEDIA_URL = '/images/' +MEDIA_ROOT = os.path.join(BASE_DIR, env('MEDIA_ROOT', 'images')) diff --git a/celerywyrm/urls.py b/celerywyrm/urls.py index 1e506dee7..21c8dee86 100644 --- a/celerywyrm/urls.py +++ b/celerywyrm/urls.py @@ -14,8 +14,11 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin +from django.conf.urls.static import static from django.urls import path +from celerywyrm import settings + urlpatterns = [ path('admin/', admin.site.urls), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)