def on_delete(info): book_key_str = info['book_key'] old_borrower = info.get('old_borrower', None) owner = info['owner'] from bookcache import CacheBookIdsOwned, CacheBookIdsBorrowed, CachedBook CacheBookIdsOwned.remove_book(owner, book_key_str) CachedBook.reset(book_key_str) if old_borrower: CacheBookIdsBorrowed.remove_book(old_borrower, book_key_str)
def change_nickname(self, new_nick): self.wtmb_nickname = new_nick self.put() from bookcache import CachedBook, CacheBookIdsOwned, CacheBookIdsBorrowed for book_key_str in CacheBookIdsOwned.get(self.key()): CachedBook.reset(book_key_str) for book_key_str in CacheBookIdsBorrowed.get(self.key()): CachedBook.reset(book_key_str)
def on_lent(book): mail.send_mail( sender=AppUser.me().email(), to=book.borrower.email(), cc=(WTMB_SENDER, AppUser.me().email()), subject='[whotookmybook] %s' % book.title, body="%s has lent this book to %s" % (book.owner.display_name(), book.borrower.display_name())) from bookcache import CachedBook, CacheBookIdsBorrowed book_key_str = str(book.key()) CacheBookIdsBorrowed.add_book(str(book.borrower.key()), book_key_str) CachedBook.reset(book_key_str)
def on_borrow(book): mail.send_mail( sender=AppUser.me().email(), to=book.owner.email(), cc=(WTMB_SENDER, AppUser.me().email()), subject='[whotookmybook] %s' % book.title, body=textwrap.dedent("""Hi %s\n %s has requested or borrowed this book from you.\n p.s.email sent by http://whotookmybook.appspot.com""" % (book.owner.display_name(), book.borrower.display_name()))) from bookcache import CachedBook, CacheBookIdsBorrowed book_key_str = str(book.key()) CacheBookIdsBorrowed.add_book(str(book.borrower.key()), book_key_str) CachedBook.reset(book_key_str)
def post(self, bookid): bookToLoan = Book.get(bookid) try: bookToLoan.borrow() self.response.headers['content-type'] = "application/json" self.response.out.write(simplejson.dumps(CachedBook.get(bookid))) except IllegalStateTransition: self.error(403)
def post(self, bookid): rtnd_book = Book.get(bookid) try: if rtnd_book.borrower: #move this check to book rtnd_book.return_to_owner() else: logging.warning("%s attempted to return book that wasn't borrowed %s" % (users.get_current_user().email(), rtnd_book.summary())) self.response.headers['content-type'] = "application/json" self.response.out.write(simplejson.dumps(CachedBook.get(bookid))) except IllegalStateTransition: self.error(403)
def on_return(info): returner = info['returner'] book = info['book'] old_borrower = info['old_borrower'] message = None if (returner != book.owner): message = " has returned this book to %s" % book.owner.display_name() else: message = "%s has reclaimed this book" % returner.display_name() mail.send_mail( sender=AppUser.me().email(), to=book.owner.email(), cc=(WTMB_SENDER, AppUser.me().email()), subject='[whotookmybook] %s' % book.title, body=message) book_key_str = str(book.key()) from bookcache import CachedBook, CacheBookIdsBorrowed CacheBookIdsBorrowed.remove_book(str(old_borrower.key()), book_key_str) CachedBook.reset(book_key_str)