Beispiel #1
0
    def post(self):
        bookKey = self.request.get("key")
        logging.info("checkIN call made it for book: %s" % bookKey)
        k = Key(bookKey)
        book = Book.get(k)
        if book is None:
            logging.info("Oops. I couldn't the find book with that key")
        else:
            logging.info("I found your book! %s %s" % (book.title, book.author))
        
        activeUser = userhandlers.getUser(users.get_current_user().user_id())
        borrower = book.borrower
        logging.debug("CHECKIN: active user is %s" % activeUser.nickname)

        # construction the email with the transaction details
        template_values = {'owner':book.owner.nickname,
                           'ownerEmail':book.owner.preferredEmail,
                           'title':book.title, 
                           'author':book.author,
                           'bookProfile':'http://www.frinook.com/book?book='+str(book.key()),
                           'borrower':activeUser.nickname,
                           'borrowerFirst':activeUser.first,
                           'borrowerEmail':activeUser.preferredEmail,
                           }       

        # change the book state depending on who is checking it in.
        # if it's the borrower, the book goes into TRANSIT mode
        # if it's the owner, the book goes into AVAILABLE mode
        if book.status == BOOK_STATUS_TRANSIT:
            book.status = BOOK_STATUS_AVAILABLE
            path = os.path.join(os.path.dirname(__file__), 'completed-email.html')
            book.checkedOut = False
            book.borrower = None
        elif activeUser.userID == book.borrower.userID:
            book.status = BOOK_STATUS_TRANSIT
            path = os.path.join(os.path.dirname(__file__), 'checkin-email.html')
            # log event
            event.createEvent(event.EVENT_BOOK_RETURN, activeUser, book, book.title)
        else:
            book.status = BOOK_STATUS_AVAILABLE
            path = os.path.join(os.path.dirname(__file__), 'completed-email.html')
            book.checkedOut = False
            book.borrower = None
            

        # update the datastore with the new book state
        book.put()        
        
        # send out email notification
        logging.debug("creating email task for checkout... send to owner %s and borrower %s" % (book.owner.preferredEmail,activeUser.preferredEmail))
        body = template.render(path, template_values)
        task = Task(url='/emailqueue', params={'ownerEmail':book.owner.preferredEmail,
                                               'borrowerEmail':borrower.preferredEmail,
                                               'body':body})
        task.add('emailqueue')

        self.response.headers['Content-Type'] = 'text/xml'
        self.response.out.write("<results>good</results>");
Beispiel #2
0
    def post(self):
      activeUser = userhandlers.getUser(users.get_current_user().user_id())
      isbn = self.request.get('isbn').replace('-','').replace(' ', '')
      logging.info("adding isbn: %s" % isbn)

      book = createBook(isbn)
      book.owner = activeUser
      book.userID = activeUser.userID
      book.borrower = None
      book.checkedOut = False
      book.status = BOOK_STATUS_AVAILABLE
      book.put()
      
      # log event
      event.createEvent(event.EVENT_BOOK_ADD, activeUser, book, book.title)
      logging.info("thumbnail is %s" % book.thumbnailURL)
      
      self.response.headers['Content-Type'] = 'text/xml'
      self.response.out.write('<root><thumbnail>'+book.thumbnailURL+'</thumbnail><title>'+book.title+'</title><key>'+str(book.key())+'</key><author>'+book.author+'</author></root>')
Beispiel #3
0
    def post(self):
      activeUser = userhandlers.getUser(users.get_current_user().user_id())
      logging.info("new review: %s" % self.request.get("review"))

      bookKey = self.request.get("book")
      book = db.get(bookKey)
      if activeUser:
          review = BookReview()
          review.text = self.request.get("review")
          review.book = book
          review.reviewerID = activeUser.userID
          review.reviewer = activeUser
          review.put()
      else:
          logging.error("Illegal review request!?! review is... %s" % self.request.get("review"))
      
      # log event
      event.createEvent(event.EVENT_BOOK_REVIEWED, activeUser, book, review.text)
      
      logging.info('review added... now return nickname %s' % activeUser.nickname)  
      self.response.out.write(activeUser.nickname)
Beispiel #4
0
    def post(self):
      activeUser = getUser(users.get_current_user().user_id())
      logging.info("new comment: %s" % self.request.get("comment"))

      userKey = self.request.get("pageOwner")
      user = db.get(userKey)
      if activeUser:
        comment = Comment()
        comment.text = self.request.get("comment")
        comment.commentAuthor = activeUser
        comment.pageOwner = user
        comment.userID = user.userID
        comment.put()        

        # log event
        event.createEvent(event.EVENT_USER_NOTE, activeUser, None, user.nickname)
      
      else:
        logging.error("Illegal comment request!?! Comment is... %s" % self.request.get("comment"))
      
      logging.info('comment added... now return nickname %s' % activeUser.nickname)  
      self.response.out.write(activeUser.nickname)
Beispiel #5
0
    def post(self):
        activeUser = userhandlers.getUser(users.get_current_user().user_id())
        bookKey = self.request.get("key")
        logging.debug("looking for book key %s" % bookKey)
        book = db.get(bookKey)
        logging.info("checkout call made it for book: %s" % bookKey)
        if book is None:
            logging.info("Oops. I couldn't find book with that key")
        else:
            logging.info("I found your book! %s %s" % (book.title, book.author))
        
        book.checkedOut = True
        book.borrower = activeUser
        book.status = BOOK_STATUS_CHECKED_OUT
        book.put() 

        # construction the email with the transaction details
        template_values = {'owner':book.owner.nickname, 
                           'title':book.title,
                           'author':book.author,
                           'borrower':activeUser.nickname,
                           'borrowerFirst':activeUser.first,
                           'borrowerEmail':activeUser.preferredEmail,
                           }       
        path = os.path.join(os.path.dirname(__file__), 'checkout-email.html')
        body = template.render(path, template_values)
        
        # log event
        event.createEvent(event.EVENT_BOOK_CHECKOUT, activeUser, book, book.title)
      
        # send out email notification
        logging.debug("creating email task for checkout... send to owner %s and borrower %s" % (book.owner.preferredEmail,activeUser.preferredEmail))
        task = Task(url='/emailqueue', params={'ownerEmail':book.owner.preferredEmail,
                                               'borrowerEmail':activeUser.preferredEmail,
                                               'body':body})
        task.add('emailqueue')

        self.response.headers['Content-Type'] = 'text/xml'
        self.response.out.write("<results>good</results>");