def setAction(self, book, status, price=None): user = self.user if not user: raise Exception("Not signed in") ub = UserBooks.gql("WHERE user_id = :1 AND book_id = :2 AND status=:3", user, book, status).get() if not ub: ub = UserBooks(user_id=user, book_id=book, status=status, price=price) ub.put() self.sendMessages(ub) elif price: ub.price = price ub.put() return [str(ub.key()), ub.price]
def getActions(self, book, status): ub = UserBooks.gql("WHERE status=:1 AND book_id=:2", status, book)
def sendMessages(self, ub): status = self.HAVE if ub.status == self.WANT else self.WANT for j in UserBooks.gql("WHERE book_id=:1 AND status=:2", ub.book_id, status): response = "match found" UserUsers.addMessage(j.user_id, ub, response) UserUsers.addMessage(ub.user_id, j, response)