Fixes celery media path

This commit is contained in:
Mouse Reeve 2020-09-30 19:43:42 -07:00
parent 4fda5c8e22
commit 0b8f8e3659
4 changed files with 18 additions and 2 deletions

View file

@ -249,7 +249,10 @@ def update_from_mappings(obj, data, mappings):
continue continue
# extract the value in the right format # 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 # assign the formatted value to the model
obj.__setattr__(mapping.local_field, value) obj.__setattr__(mapping.local_field, value)

View file

@ -143,17 +143,24 @@ class Connector(AbstractConnector):
def expand_book_data(self, book): def expand_book_data(self, book):
work = book work = book
# go from the edition to the work, if necessary
if isinstance(book, models.Edition): if isinstance(book, models.Edition):
work = book.parent_work 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) edition_options = self.load_edition_data(work.openlibrary_key)
for edition_data in edition_options.get('entries'): for edition_data in edition_options.get('entries'):
olkey = edition_data.get('key').split('/')[-1] 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(): if models.Edition.objects.filter(openlibrary_key=olkey).count():
continue continue
# creates and populates the book from the data
edition = self.create_book(olkey, edition_data, models.Edition) edition = self.create_book(olkey, edition_data, models.Edition)
# ensures that the edition is associated with the work
edition.parent_work = work edition.parent_work = work
edition.save() edition.save()
# get author data from the work if it's missing from the edition
if not edition.authors and work.authors: if not edition.authors and work.authors:
edition.authors.set(work.authors.all()) edition.authors.set(work.authors.all())

View file

@ -144,3 +144,6 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.0/howto/static-files/ # https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/' 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'))

View file

@ -14,8 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.conf.urls.static import static
from django.urls import path from django.urls import path
from celerywyrm import settings
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)