Exemple #1
0
async def do_manage_alter(json,opr_type):
    id=json['id']
    if opr_type=='delete':
        s=await blog_tb.delete(id)
        if s:
            return jsonResponse(message='删除成功')
        return apiError(message='删除失败')
    if opr_type=='add_category':
        cate=Category(name=json['name'])
        s = await man.cate_tb.insert(cate)
        if s:
            return jsonResponse(message='操作成功')
        return apiError(message='操作失败')
Exemple #2
0
async def do_manage_alter(json, opr_type):
    id = json['id']
    if opr_type == 'delete':
        s = await blman.deleteBlog(id)
        if s:
            return jsonResponse(message='删除成功')
        return apiError(message='删除失败')
Exemple #3
0
 def autoErrorResponse(self):
     if not self.success:
         if self.code == 3:
             self.errorPageResponse = pageSign()
         else:
             self.errorPageResponse = pageError(message=self.message)
         self.errorJsonResponse = apiError(message=self.message)
Exemple #4
0
async def do_me_delete_blog(blog_id, cookies):
    chk = await checkRequiredData(bid=blog_id,
                                  from_public=False,
                                  cookies=cookies)
    if not chk.success:
        return chk.errorJsonResponse
    b = await Blog.find(blog_id)
    r = await Blog.delete(b.id)
    if not r:
        return apiError(message='删除失败')
    return jsonResponse(message='删除成功')
Exemple #5
0
async def do_editor_post(blog_id, blog_heading, blog_summary, blog_content,
                         is_public, type, label, cookies):
    chk = await checkRequiredData(bid=blog_id,
                                  from_public=False,
                                  cookies=cookies)
    if not chk.success:
        return chk.errorJsonResponse
    b = await Blog.find(blog_id)
    u = await User.find(b.user_id)
    if blog_heading.strip() == '':
        return apiError(message='文章标题不能为空')
    if blog_summary.strip() == '':
        blog_summary = blog_content[:200] if len(
            blog_content) >= 200 else blog_content
    r = await b.update(name=blog_heading,
                       summary=blog_summary,
                       content=blog_content,
                       public=is_public,
                       type=type,
                       label=label)
    if not r:
        log('failed to update blog %s' % blog_id)
        return apiError(message='更新失败')
    return jsonResponse(message='更新成功,<a href="/me">前往主页?</a>')
Exemple #6
0
async def create_blog_post(blog_heading, blog_summary, blog_content, is_public,
                           type, label, cookies):
    chk = await checkRequiredData(from_public=False, cookies=cookies)
    if not chk.success:
        return chk.errorJsonResponse
    uid = cookies['user_id']
    u = await User.find(uid)
    if blog_heading.strip() == '':
        return apiError(message='文章标题不能为空')
    b = await Blog.easyBlog(u,
                            name=blog_heading,
                            summary=blog_summary,
                            content=blog_content,
                            public=is_public,
                            type=type,
                            label=label)
    return jsonResponse(success=True,
                        message='文章上传成功,<a href="/me">前往主页?</a>',
                        data=b)
Exemple #7
0
async def do_comment_post(blog_id, content, cookies):
    chk = await checkRequiredData(bid=blog_id,
                                  from_public=False,
                                  cookies=cookies)
    if not chk.success:
        return chk.errorJsonResponse
    user_id = cookies['user_id']
    logging.info('cookies:%s' % cookies)
    u = await User.find(user_id)
    if content.strip() == '':
        return apiError(message='评论不能为空!')
    comment = Comment(user_id=user_id,
                      user_name=u.name,
                      user_image=u.image,
                      blog_id=blog_id,
                      content=content)
    logging.info('comments-object formed:%s' % comment)
    await comment.save()
    await comment.lightInfo()
    tem = env.get_template(pages['comment_show'])
    co = tem.render(comment=comment)
    return jsonResponse(data={'comment': co})
Exemple #8
0
async def do_get_blog(blog_id):
    blog=await blog_tb.findByPK(blog_id)
    if blog:
        return jsonResponse(data=blog.toJson())
    return apiError(message='blog not found.')
Exemple #9
0
async def do_get_blog(blog_id):
    blog = await blman.getBlogByID(blog_id)
    if blog:
        return jsonResponse(data=blog.toJson())
    return apiError(message='blog not found.')