コード例 #1
0
ファイル: New_post.py プロジェクト: gaz888/Python-mini-blog
 def post(self):
     title = self.request.get('subject')
     content = self.request.get('content')
     if title and content:
         e = Post(title=title, content=content)
         Post.put_and_update_cache(e)
         self.redirect('/blog/id/' + str(e.key().id()))
     else:
         error = 'Fill both title and content'
         self.render('new_post.html', title=title, content=content, error=error)
コード例 #2
0
ファイル: Get_post.py プロジェクト: gaz888/Python-mini-blog
 def get(self):
     id = self.request.path_info.replace('/blog/id/', '').replace('.json', '').replace('/', '')
     entry = Post.get_by_id_and_update_cache(int(id))
     if self.format == 'html':
         self.render('post.html', entry=entry, id=id, seconds_ago = '%f' % (time.time() - memcache.get(Post.LAST_TIME_QUERIED_POST + id)))
     else:
         self.render_json(entry.as_dict())
コード例 #3
0
 def get_all_posts_query(self):
     allPostsDict = CommonUsed.dfToArrayOfJsonWithoutIdx(self.posts_df)
     Posts = []
     for post in allPostsDict:
         Posts.append(
             Post(postDict['id'], postDict['userId'], postDict['title'],
                  postDict['body']))
     return Posts  # returns array of entities
コード例 #4
0
ファイル: Blog.py プロジェクト: gaz888/Python-mini-blog
 def get(self):
     entries = Post.get_all_order_by_date()
     if self.format == 'html':
         self.render('blog.html', entries=entries, seconds_ago = round(time.time() - memcache.get(Post.LAST_TIME_QUERIED_ALL_POSTS), 1))
     else:
         return self.render_json([e.as_dict() for e in entries])
コード例 #5
0
 def get_single_post_query(self, _id):
     signle_post = self.posts_df.loc[self.posts_df['id'] == _id]
     postDict = CommonUsed.rowToJson(signle_post)
     postEntity = Post(postDict['id'], postDict['userId'],
                       postDict['title'], postDict['body'])
     return postEntity  # returns entity