Example #1
0
 def delete(self, key):
     # FIXME: dirty
     if not users.is_current_user_admin():
         return
     book = Book.get_by_key_name("Book_" + key)
     if book:
         for comment in book.comments: comment.delete()
         for stock in book.stocks: stock.delete()
         book.delete()
     Activity(type='delete', book=book).put()
     self.response.out.write("ok")
     return
Example #2
0
 def post(self):
     book = Book.get_by_key_name("Book_" + self.request.get('book'))
     if not book: return
     body = self.request.get('body')
     if not body: return
     comment = Comment(
         book = book,
         body = body
         )
     comment.put()
     Activity(type='comment', book=book).put()
     user = users.get_current_user()
     template_values = {
         'comment': comment,
         'user': user,
         }
     path = os.path.join(os.path.dirname(__file__), '..', 'view', 'comment/index.html')
     result = template.render(path, template_values)
     self.response.out.write(result)
Example #3
0
 def put(self, key):
     if not users.get_current_user():
         self.response.out.write("deny")
         return
     book = Book.get_by_key_name("Book_" + key)
     if not book:
         self.response.out.write("ng")
         return
     if self.request.get('description'):
         stock = book.mystock()
         if stock:
             stock.description = self.request.get('description')
             stock.put()
             self.response.out.write(self.request.get('ok'))
             return
         else:
             self.response.out.write('no stock');
             return
     else:
         type = book.lent_or_return()
         Activity(type=type, book=book).put()
     return
Example #4
0
    def get(self, key):
        if key == 'add':
            self.post()
            return
        # result = memcache.get("index")
        result = False
        if result:
            self.response.out.write(result)
            return

        user = users.get_current_user()
        if user:
            greeting = ("<a href=\"%s\">logout %s</a>" %
                        (users.create_logout_url("/"), user.nickname()))
        else:
            greeting = ("<a href=\"%s\">login</a>" %
                        users.create_login_url("/"))

        logging.info("cache not hit()")
        book = Book.get_by_key_name("Book_" + key)
        template_values = None
        if book:
            template_values = {
                'user': user,
                'book': book,
                'greeting': greeting,
                }
            path = os.path.join(os.path.dirname(__file__), '..', 'view', 'book/index.html')
            result = template.render(path, template_values)
        else:
            template_values = {
                'user': user,
                'key':  key,
                'greeting': greeting,
                }
            path = os.path.join(os.path.dirname(__file__), '..', 'view', 'book/not_found.html')
            result = template.render(path, template_values)
        # memcache.set("index", result, 600)
        self.response.out.write(result)