Beispiel #1
0
def api_delete_blog(request, id):
    check_admin(request)
    blog = yield from Blog.find(id)
    if blog is None:
        return APIResourceNotFoundError('blog')
    yield from blog.remove()
    return dict(id=id)
def api_delete_blog(request,* ,id):
	check_admin(request)

	blog = yield from Blog.find(id)

	yield from blog.remove()

	return dict(id = id)
Beispiel #3
0
def get_blog(id):
    blog = yield from Blog.find(id)
    comments = yield from Comment.findAll('blog_id=?', [id],
                                          orderBy='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {'__template__': 'blog.html', 'blog': blog, 'comments': comments}
Beispiel #4
0
def get_blog(id):
    blog = yield from Blog.find(id)
    comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    for c in comments:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    }
Beispiel #5
0
def api_create_comment(id, request, *, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('Please signin first.')
    if not content or not content.strip():
        raise APIValueError('content')
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()
    return comment
def api_create_comment(id,request,*,content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('please signin first...')
    if not content or not content.strip():
        raise APIValueError('content')
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment  = Comment(blog_id = blog.id ,user_id = user.id,user_name=user.name,user_image = user.image,content = content.strip())
    yield from comment.save()
    return comment
Beispiel #7
0
def api_update_blog(id, request, *, name, summary, content):
    check_admin(request)
    blog = yield from Blog.find(id)
    if not name or not name.strip():
        raise APIValueError('name', 'name can not be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary can not be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content can not be empty.')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    yield from blog.update()
    return blog
Beispiel #8
0
def api_update_blog(id, request, *, name, summary, content):
	logging.info('creating new blogs here with api-blogs-id')
	check_admin(request)
	blog = yield from Blog.find(id)
	if not name or not name.strip():
		raise APIValueError('name', 'name cannot be empty.')
	if not summary or not summary.strip():
		raise APIValueError('summary', 'summary cannot be empty.')
	if not content or not content.strip():
		raise APIValueError('content', 'content cannot be empty.')
	blog.name = name.strip()
	blog.summary = summary.strip()
	blog.content = content.strip()
	yield from blog.update()
	return blog
def api_edit_blog(request, *, id, name, summary, content):
	check_admin(request)

	if not name or not name.strip():
		raise APIValueError('name','name can not be empty')
	if summary is None or not summary.strip():
		raise APIValueError('summary','summary can not be empty')
	if content is None or not content.strip():
		raise APIValueError('content', 'content can not be empty')

	blog = yield from Blog.find(id)

	blog.name = name
	blog.summary = summary
	blog.content = content

	yield from blog.update()

	return blog
Beispiel #10
0
async def get_blogs_of_tag(name, *, page="1"):
    tag = await Tag.findAll("`name`=?", [name])
    page_index = get_page_index(page)
    num = await BlogTag.findNumber("count(id)", "`tag_id`=?", [tag[0].id])
    p = Page(num, page_index)
    if num == 0:
        blogs = []
    else:
        blogs = []
        tag_blogs = await BlogTag.findAll("`tag_id`=?", [tag[0].id],
                                          limit=(p.offset, p.limit))
        for tag_blog in tag_blogs:
            blogs.append(await (Blog.find(tag_blog.blog_id)))
        blogs = sorted(blogs, key=lambda x: x.created_at, reverse=True)

        for blog in blogs:
            blog_tags = await BlogTag.findAll("`blog_id`=?", [blog.id])
            blog.tags = []
            for blog_tag in blog_tags:
                blog.tags.append(
                    dict(blog_tag=blog_tag,
                         tag=await Tag.find(blog_tag.tag_id)))
    return {"__template__": "blogs.html", "page": p, "blogs": blogs}
Beispiel #11
0
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog
def api_get_blog(*,id):
    blog = Blog.find(id)
    return blog
Beispiel #13
0
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog
Beispiel #14
0
def api_delete_blog(request, *, id):
    check_admin(request)
    blog = yield from Blog.find(id)
    yield from blog.remove()
    return dict(id=id)