Example #1
0
    def post(self):
        user = self.check_login_status()

        title = self.request.get("subject")
        post = self.request.get("content")
        if not title or not post:
            self.render(
                "newpost.html", title=title, post=post, user=user, error="A post requires both a title and content."
            )
        else:
            blogpost = BlogPost(title=title, post=post, author_id=user.key().id())

            blogpost.put()
            get_latest(True)
            self.redirect("/blog/%s" % str(blogpost.key().id()))
Example #2
0
 def get(self):
     posts_query = BlogPost.query()
     blogposts = posts_query.fetch(15)   
     posts_dict = []
     for post in blogposts:
         posts_dict.append(post.to_dict()) 
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(posts_dict, cls=DateTimeEncoder))
Example #3
0
 def get_post(self, blog_id):
     perma_key = "post:%s" % blog_id
     query_key = "lastquery:%s" % blog_id
     post = memcache.get(perma_key)
     if not post:
         post = BlogPost.get_by_id(blog_id)
         memcache.set(perma_key, post)
         memcache.set(query_key, time.time())
     return post
Example #4
0
 def get(self, blog_id=None):
     self.response.headers["Content-Type"] = "application/json"
     if blog_id:
         blog_id = int(blog_id)
         post = BlogPost.get_by_id(blog_id)
         self.write(post.to_json())
     else:
         query = "SELECT * FROM BlogPost ORDER BY created DESC LIMIT 10"
         posts = db.GqlQuery(query)
         posts = list(posts)
         self.write(json.dumps([post.to_json() for post in posts]))
Example #5
0
 def get(self, post_id):
     post = memcache.get(post_id)
     lastUpdate = memcache.get('lastUpdate_'+post_id)
     if not post or not lastUpdate:
         post = BlogPost.get_by_id(int(post_id))
         memcache.add(post_id,post)
         lastUpdate = datetime.datetime.now()
         memcache.add('lastUpdate_'+post_id,lastUpdate)
         
     age = int(math.ceil((datetime.datetime.now() - lastUpdate).total_seconds()-1))    
     ageString = 'Queried {} seconds ago'.format(age)
            
     template_values = {'blogposts': [post], 'id':post_id, 'age': ageString}
     self.render(self.templatename, template_values)
Example #6
0
 def get(self):
     posts_query = BlogPost.query()
     blogposts = memcache.get('blogposts')
     lastUpdate = memcache.get('lastUpdate')
     if not blogposts or not lastUpdate:
         blogposts = posts_query.fetch(15)
         memcache.add('blogposts',blogposts)
         lastUpdate = datetime.datetime.now()
         memcache.add('lastUpdate',lastUpdate)
          
     
     age = int(math.ceil((datetime.datetime.now() - lastUpdate).total_seconds()-1))    
     ageString = 'Queried {} seconds ago'.format(age)
     template_values = {'blogposts': blogposts, 'age': ageString}
     #print datetime.datetime.now()
     self.render(self.templatename,template_values)
Example #7
0
 def get(self, post_id):
     post = BlogPost.get_by_id(int(post_id))
     self.response.headers['Content-Type'] = 'application/json'
     self.response.write(json.dumps(post.to_dict(), cls=DateTimeEncoder))
Example #8
0
 def persist(self, subject,content):
     newpost = BlogPost();
     newpost.subject = subject;
     newpost.content = content;
     newpost.put()
     return newpost.key.id()