예제 #1
0
파일: blog.py 프로젝트: susnmos/torweb
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 获取文章详情
     if opt == 'get-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']),
                                 BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             self.write(
                 json_result(
                     0, {
                         'title': post.title,
                         'content': post.content,
                         'labels': BlogPostLabel.get_post_label(post),
                         'category': post.category.name
                     }))
             return
     # 更新文章
     elif opt == 'update-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']),
                                 BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             cate = BlogPostCategory.get_by_name(data['category'])
             post.category = cate
             post.title = data['title']
             post.content = data['content']
             post.save()
             BlogPostLabel.update_post_label(data['labels'], post)
             self.write(json_result(0, 'success'))
             return
     # 创建文章
     elif opt == 'create-post':
         cate = BlogPostCategory.get_by_name(data['category'])
         post = BlogPost.create(title=data['title'],
                                category=cate,
                                content=data['content'])
         BlogPostLabel.add_post_label(data['labels'], post)
         self.write(json_result(0, 'success'))
         return
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #2
0
파일: blog.py 프로젝트: jmpews/torweb
 def post(self, *args, **kwargs):
     json_data = get_cleaned_json_data(self, ['opt', 'data'])
     data = json_data['data']
     opt = json_data['opt']
     # 获取文章详情
     if opt == 'get-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']), BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             self.write(json_result(0, {'title': post.title,
                            'content': post.content,
                            'labels': BlogPostLabel.get_post_label(post),
                            'category': post.category.name}))
             return
     # 更新文章
     elif opt == 'update-post':
         try:
             post = BlogPost.get(BlogPost.id == int(data['post']), BlogPost.is_del == False)
         except:
             self.write(json_result(1, '不存在该post'))
             return
         else:
             cate = BlogPostCategory.get_by_name(data['category'])
             post.category = cate
             post.title = data['title']
             post.content = data['content']
             post.save()
             BlogPostLabel.update_post_label(data['labels'], post)
             self.write(json_result(0, 'success'))
             return
     # 创建文章
     elif opt == 'create-post':
         cate = BlogPostCategory.get_by_name(data['category'])
         post = BlogPost.create(title=data['title'],
                                category=cate,
                                content=data['content'])
         BlogPostLabel.add_post_label(data['labels'], post)
         self.write(json_result(0, 'success'))
         return
     else:
         self.write(json_result(1, 'opt不支持'))
예제 #3
0
파일: blog.py 프로젝트: niuzehai/torweb
 def get(self, post_id, *args, **kwargs):
     post = BlogPost.get(BlogPost.id == post_id)
     # post.content_html = markdowner.convert(post.content)
     post.content_html = markdown.markdown(
         post.content, extensions=[
             'markdown.extensions.fenced_code',
         ])
     post.category_name = post.category.name
     post.labels = BlogPostLabel.get_post_label(post)
     self.render('blog/post-detail.html', post=post)