From ae9a541ed5a4d43601bbf75c9643cc4546d991a2 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Tue, 16 Oct 2012 10:41:30 -0400 Subject: [PATCH] too many ways we might add to wishlist to test for. adding argument for notification. [[#37780515] --- core/goodreads.py | 2 +- core/librarything.py | 2 +- core/models.py | 4 ++-- frontend/views.py | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/goodreads.py b/core/goodreads.py index a6e0cae0..ef827add 100644 --- a/core/goodreads.py +++ b/core/goodreads.py @@ -296,7 +296,7 @@ def load_goodreads_shelf_into_wishlist(user, shelf_name='all', goodreads_user_id match = re.search('/show/(\d+)', link) if match: identifier= models.Identifier.get_or_add(type = 'gdrd', value = match.group(1), edition = edition, work = edition.work) - user.wishlist.add_work(edition.work, 'goodreads') + user.wishlist.add_work(edition.work, 'goodreads', True) logger.info("Work with isbn %s added to wishlist.", isbn) else: logger.error("unable to extract goodreads id from %s", link) diff --git a/core/librarything.py b/core/librarything.py index f1dca5a2..6d61d7f5 100644 --- a/core/librarything.py +++ b/core/librarything.py @@ -228,7 +228,7 @@ def load_librarything_into_wishlist(user, lt_username, max_books=None): identifier= models.Identifier.get_or_add(type = 'ltwk', value = book['work_id'], work = edition.work) if book['lc_call_number']: 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') + user.wishlist.add_work(edition.work, 'librarything', True) if edition.new: tasks.populate_edition.delay(edition.isbn_13) logger.info("Work with isbn %s added to wishlist.", isbn) diff --git a/core/models.py b/core/models.py index 7df145c5..0866ae10 100755 --- a/core/models.py +++ b/core/models.py @@ -928,7 +928,7 @@ class Wishlist(models.Model): def __unicode__(self): return "%s's Wishlist" % self.user.username - def add_work(self, work, source): + def add_work(self, work, source, notify=False): try: w = Wishes.objects.get(wishlist=self,work=work) except: @@ -936,7 +936,7 @@ class Wishlist(models.Model): work.update_num_wishes() # only send notification in case of new wishes # and only when they result from user action, not (e.g.) our tests - if source=='user' or source=='pledging': + if notify: wishlist_added.send(sender=self, work=work, supporter=self.user) def remove_work(self, work): diff --git a/frontend/views.py b/frontend/views.py index 0b9d19a6..4888d102 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -987,9 +987,10 @@ class PledgeCompleteView(TemplateView): correct_transaction_type = False # add the work corresponding to the Transaction on the user's wishlist if it's not already on the wishlist + # fire add-wishlist notification if needed if user is not None and correct_transaction_type and (campaign is not None) and (work is not None): # ok to overwrite Wishes.source? - user.wishlist.add_work(work, 'pledging') + user.wishlist.add_work(work, 'pledging', True) worklist = slideshow(8) works = worklist[:4] @@ -1512,7 +1513,7 @@ def wishlist(request): if edition.new: # add related editions asynchronously tasks.populate_edition.delay(edition.isbn_13) - request.user.wishlist.add_work(edition.work,'user') + request.user.wishlist.add_work(edition.work,'user', True) except bookloader.LookupFailure: logger.warning("failed to load googlebooks_id %s" % googlebooks_id) except Exception, e: @@ -1540,7 +1541,7 @@ def wishlist(request): except models.WasWork.DoesNotExist: raise Http404 - request.user.wishlist.add_work(work,'user') + request.user.wishlist.add_work(work,'user', True) return HttpResponseRedirect('/') class InfoPageView(TemplateView):