diff --git a/api/views.py b/api/views.py index 8267359c..f151ae75 100755 --- a/api/views.py +++ b/api/views.py @@ -53,7 +53,7 @@ def widget(request,isbn): work = identifier.work edition = identifier.edition campaigns = work.campaigns.all() - except models.Identifer.DoesNotExist: + except models.Identifier.DoesNotExist: edition = None work = None campaigns = [] diff --git a/core/bookloader.py b/core/bookloader.py index 9b3330cf..fbea04a5 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -524,7 +524,7 @@ def load_gutenberg_edition(title, gutenberg_etext_id, ol_work_id, seed_isbn, url sister_edition = add_by_isbn(seed_isbn) if sister_edition.new: # add related editions asynchronously - regluit.core.tasks.populate_edition.delay(sister_edition) + regluit.core.tasks.populate_edition.delay(sister_edition.isbn_13) work = sister_edition.work # attach the olwk identifier to this work if it's not none. if ol_work_id is not None: diff --git a/core/goodreads.py b/core/goodreads.py index 2229f090..f1a24ff1 100644 --- a/core/goodreads.py +++ b/core/goodreads.py @@ -293,7 +293,7 @@ def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id else: logger.error("unable to extract goodreads id from %s", link) if edition.new: - regluit.core.tasks.populate_edition.delay(edition) + regluit.core.tasks.populate_edition.delay(edition.isbn_13) except Exception, e: logger.info ("Exception adding ISBN %s: %s", isbn, e) diff --git a/core/librarything.py b/core/librarything.py index d22041f1..f1dca5a2 100644 --- a/core/librarything.py +++ b/core/librarything.py @@ -230,7 +230,7 @@ def load_librarything_into_wishlist(user, lt_username, max_books=None): identifier= models.Identifier.get_or_add(type = 'lccn', value = book['lc_call_number'], edition = edition, work = edition.work) user.wishlist.add_work(edition.work, 'librarything') if edition.new: - tasks.populate_edition.delay(edition) + tasks.populate_edition.delay(edition.isbn_13) logger.info("Work with isbn %s added to wishlist.", isbn) except Exception, e: logger.info ("error adding ISBN %s: %s", isbn, e) diff --git a/core/management/commands/goodreads_load_books.py b/core/management/commands/goodreads_load_books.py index e0c5c5ec..ce818baf 100644 --- a/core/management/commands/goodreads_load_books.py +++ b/core/management/commands/goodreads_load_books.py @@ -16,4 +16,4 @@ class Command(BaseCommand): user = User.objects.get(username=user_name) max_books = int(max_books) - tasks.load_goodreads_shelf_into_wishlist.delay(user, shelf_name, goodreads_user_id, max_books) \ No newline at end of file + tasks.load_goodreads_shelf_into_wishlist.delay(user.id, shelf_name, goodreads_user_id, max_books) \ No newline at end of file diff --git a/core/management/commands/librarything_load_books.py b/core/management/commands/librarything_load_books.py index 6702879f..8c6d4590 100644 --- a/core/management/commands/librarything_load_books.py +++ b/core/management/commands/librarything_load_books.py @@ -13,4 +13,4 @@ class Command(BaseCommand): user = User.objects.get(username=user_name) max_books = int(max_books) - tasks.load_librarything_into_wishlist.delay(user, lt_username, max_books) \ No newline at end of file + tasks.load_librarything_into_wishlist.delay(user.id, lt_username, max_books) \ No newline at end of file diff --git a/core/tasks.py b/core/tasks.py index d74420e6..e42678bb 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -2,25 +2,31 @@ from time import sleep from celery.decorators import task -from regluit.core import bookloader +from django.contrib.auth.models import User + +from regluit.core import bookloader, models from regluit.core import goodreads, librarything @task -def populate_edition(edition): +def populate_edition(isbn): """given an edition this task will populate the database with additional information about related editions and subjects related to this edition """ - bookloader.add_related(edition.isbn_13) - bookloader.add_openlibrary(edition.work) + bookloader.add_related(isbn) + edition=models.Edition.get_by_isbn(isbn) + if edition: + bookloader.add_openlibrary(edition.work) return edition @task -def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id=None, max_books=None, +def load_goodreads_shelf_into_wishlist(user_id, shelf_name='all', goodreads_user_id=None, max_books=None, expected_number_of_books=None): + user=User.objects.get(id=user_id) return goodreads.load_goodreads_shelf_into_wishlist(user,shelf_name,goodreads_user_id,max_books, expected_number_of_books) - + @task -def load_librarything_into_wishlist(user, lt_username, max_books=None): +def load_librarything_into_wishlist(user_id, lt_username, max_books=None): + user=User.objects.get(id=user_id) return librarything.load_librarything_into_wishlist(user, lt_username, max_books) @task diff --git a/core/tests.py b/core/tests.py index 1288fe7a..9d8c0768 100755 --- a/core/tests.py +++ b/core/tests.py @@ -90,7 +90,7 @@ class BookLoaderTests(TestCase): def test_populate_edition(self): edition = bookloader.add_by_googlebooks_id('c_dBPgAACAAJ') - edition = tasks.populate_edition.run(edition) + edition = tasks.populate_edition.run(edition.isbn_13) self.assertTrue(edition.work.editions.all().count() > 20) self.assertTrue(edition.work.subjects.all().count() > 10) self.assertTrue(edition.work.publication_date) diff --git a/experimental/zotero_books.py b/experimental/zotero_books.py index e311695b..fa387090 100644 --- a/experimental/zotero_books.py +++ b/experimental/zotero_books.py @@ -101,7 +101,7 @@ class MyZotero(Zotero2): if isbn: edition = bookloader.add_by_isbn(isbn) # let's not trigger too much traffic to Google books for now - regluit.core.tasks.populate_edition.delay(edition) + regluit.core.tasks.populate_edition.delay(edition.isbn_13) user.wishlist.add_work(edition.work, 'zotero') logger.info("Work with isbn %s added to wishlist.", isbn) except Exception, e: diff --git a/frontend/templates/faq.html b/frontend/templates/faq.html index cb40face..8bf26f00 100644 --- a/frontend/templates/faq.html +++ b/frontend/templates/faq.html @@ -19,7 +19,9 @@