Esempio n. 1
0
def api_edit_blog(request, *, id, name, summary, content):
    """edit the blog:
        if exist id:    update the blog
        else:           save the blog
    """
    check_admin(request)
    if not name or not name.strip():
        raise APIValueError('name', 'blog name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'blog summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'blog content cannot be empty.')
    # save the blog
    if id == '':
        blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image,
                    name=name.strip(), summary=summary.strip(), content=content.strip())
        yield from save_model(blog)
    # update the blog
    else:
        blog = yield from find_model(model='blog', id=id)
        blog.name = name
        blog.summary = summary
        blog.content = content
        yield from update_model(blog)
    return blog
Esempio n. 2
0
def index(request):
    logging.debug(request.headers.cookies)
    cookie = request.headers.cookies(COOKIE_NAME)
    logging.debug(cookie)
    if cookie:
        vars = cookie.split('-')
        print(vars)
    else:
        logging.debug("no cookie")

    summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    blogs = [
        Blog(id='1',
             name='Test Blog',
             summary=summary,
             created_at=time.time() - 120),
        Blog(id='2',
             name='Something New',
             summary=summary,
             created_at=time.time() - 3600),
        Blog(id='3',
             name='Learn Swift',
             summary=summary,
             created_at=time.time() - 7200)
    ]
    return {'__template__': 'blogs.html', 'blogs': blogs}
Esempio n. 3
0
def index(request,*,page='1'):
    cookie_str = request.cookies.get(COOKIE_NAME)
    user = ''
    if cookie_str:
        if 'deleted' in cookie_str:
            user=''
        else:
            user = yield from cookie2user(cookie_str)
    #summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    #blogs = [
     #   Blog(id='1', name='Test Blog', summary=summary, created_at=time.time()-120),
      #  Blog(id='2', name='Something New', summary=summary, created_at=time.time()-3600),
       # Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time()-7200)
    #]def index(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'blogs': blogs,
        'user': user
    }
Esempio n. 4
0
def post_blog():
    form = request.form
    if 'id' in form:
        Blog.delete(form['id'])
    blog = Blog(name=request.cookie['name'], title=form['title'],
                content=form['content'])
    blog.insert()
    return redirect('/hello/' + blog.id)
Esempio n. 5
0
def api_blogs(*,page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    p = Page(num,page_index)
    if num ==0:
        return dict(page=p,blog=())
    blogs = yield from Blog.findAll(orderBy='created_at desc',limit=(p.offset,p.limit))
    return dict(page=p,blogs=blogs)
Esempio n. 6
0
def api_blogs(*,page='1'):
    page_index=get_page_index(page)
    num=yield from Blog.findNumber('count(id)')
    p=Page(num,page_index)
    if num==0:
        return dict(page=p,blogs=())
    blogs=yield from Blog.findAll(orderBy='created_at desc',limit=(p.offset,p.limit))
    return dict(page=p,blogs=blogs)
Esempio n. 7
0
def index(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc',
                                        limit=(page.offset, page.limit))
    return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
Esempio n. 8
0
def post_blog(request):
    dic = request.form
    if "id" in dic:
        Blog.delete(dic["id"])
    dic["name"] = request.cookie["name"].value
    blog = Blog(**dic)
    blog.insert()
    request.status = "303 See Other"
    request.header.append(("Location", "/hello/" + blog.id))
    return request
Esempio n. 9
0
def index(request):
    num=yield from Blog.findNumber('count(id)')
    if num==0:
        blogs=[]
    else:
        blogs=yield from Blog.findAll()
    return {
        '__template__': 'blogs.html',
        'blogs': blogs
    }
Esempio n. 10
0
def api_blogs(*, page='1'):
    #获取页面索引,默认为1:
    page_index = get_page_index(page)
    #查询数据库中Blog表中文章总数:
    num = yield from Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    #查询数据库中Blog表中对应分页的文章结果;(limit为mysql的分页查询条件)
    blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
def api_create_blog(request, *, name, summary, content):
    check_admin(request)
    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 = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
    yield from blog.save()
    return blog
Esempio n. 12
0
async def index(request):
    summary = '郭浩伟爱着程锡慧,他将会为了他们的家庭努力,好好工作,好好生活。'
    blogs = [
        Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120),
        Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600),
        Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200)
    ]
    return {
        '__template__': 'blogs.html',
        'blogs': blogs
    }
Esempio n. 13
0
async def index(request):
    summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    blogs = [
        Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120),
        Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600),
        Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200)
    ]
    return {
        '__template__': 'blogs.html',
        'blogs': blogs
    }
Esempio n. 14
0
def  api_create_blog(request, *,name,summary,content):
     #校验登录属性
     check_admin(request)
     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 = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
     yield from blog.save()
     return blog
Esempio n. 15
0
def index(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs
    }
Esempio n. 16
0
def index(request):
    summary = 'abc'
    blogs = [
        Blog(id='1', name='Test Blog', summary=summary,
             created_at=time.time() - 120),
        Blog(id='2', name='Something New', summary=summary,
             created_at=time.time() - 3600),
        Blog(id='3', name='Python', summary=summary,
             created_at=time.time() - 4800)
    ]
    return {
        '__template__': 'blogs.html',
        'blogs': blogs
    }
Esempio n. 17
0
def index(*, page='1'):
    #获取页面索引,默认为1;因为首页默认索引页为1,其实这里没用上:
    page_index = get_page_index(page)
    #获取数据库中的文章总数:
    num = yield from Blog.findNumber('count(id)')
    page = Page(num, page_index)
    if num == 0:
        blogs = []
    else:
        #查询数据库中Blog表中对应分页的文章结果;(limit为mysql的分页查询条件)
        blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit))
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs
    }
Esempio n. 18
0
def api_create_comment(id, request, *, content):
    blog=yield from Blog.findAll(id)
    print(blog)
    print(content)
    comment=Comment(blog_id=id,user_id='0015302547958723f7da9d783434468901251428ea85d4c000',user_name='xuehh',user_image='http://www.gravatar.com/avatar/067bf298c6244dd085d9b4b7d9f3e0ba?d=mm&s=120',content=content.strip())
    yield from comment.save()
    return comment
Esempio n. 19
0
def getBlog(id):
    blog = yield from Blog.find(id)
    comments = yield from Comment.findAll('blog_id=?', [id],
                                          orderBy='create_time desc')
    for c in comments:
        c.htmlContent = text2Html(c.content)
    return {'__template__': 'blog.html', 'blog': blog, 'comments': comments}
def index(request):
    summary = "The summary of the Project. liguangyu's Demo"
    blogs = [
        Blog(id=1,
             name='Test Blog',
             summary=summary,
             created_at=time.time() - 120),
        Blog(id=2,
             name='Something New',
             summary=summary,
             created_at=time.time() - 3600),
        Blog(id=3,
             name='Learn Swift',
             summary=summary,
             created_at=time.time() - 72000)
    ]
    return {'__template__': 'blogs.html', 'blogs': blogs}
Esempio n. 21
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 = www.markdown2.markdown(blog.content)
    return {'__template__': 'blog.html', 'blog': blog, 'comments': comments}
Esempio n. 22
0
def api_delete_blog(request, *, id):
    #校验当前用户权限:
    check_admin(request)
    #数据库Blog表中查询指定文章信息:
    blog = yield from Blog.find(id)
    #将Blog信息从数据库删除:
    yield from blog.remove()
    return dict(id=id)
Esempio n. 23
0
def index(*, tag='', page='1', size='3'):
    num = yield from Blog.findNumber('count(id)')
    page = Page(num, set_valid_value(page), set_valid_value(size, 3))
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc',
                                        limit=(page.offset, page.limit))
        #blogs = yield from Blog.findAll(orderBy='created_at desc',limit=(page.offest,page.limit))
        for blog in blogs:
            blog.content = marked_filter(blog.content)
    return {
        '__template__': 'blogs.html',
        'page': page,
        'blogs': blogs,
        'tag': tag
    }
Esempio n. 24
0
def api_create_blog(request, *, name, summary, content):
    #校验当前用户权限:
    check_admin(request)
    #校验传递值中参数‘name’是否为空或空串,为空则抛出异常:
    if not name or not name.strip():
        #参数‘name’为空则抛出异常:
        raise APIValueError('name', 'name cannot be empty.')
    #校验传递值中参数‘summary’是否为空或空串,为空则抛出异常:
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    #校验传递值中参数‘content’是否为空或空串,为空则抛出异常:
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    #创建Blog实例:
    blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
    #将Blog信息存储到数据库:
    yield from blog.save()
    return blog
Esempio n. 25
0
def find_number(model, selectField, where=None, args=None):
    if model == 'blog':
        count = yield from Blog.findnumber(selectField=selectField, where=where, args=args)
        return count
    if model == 'user':
        count = yield from User.findnumber(selectField=selectField, where=where, args=args)
        return count
    if model == 'comment':
        count = yield from Comment.findnumber(selectField=selectField, where=where, args=args)
        return count
Esempio n. 26
0
def index(*,page='1'):
    # summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    # blogs = [
    #     Blog(id='1', name='Test Blog', summary=summary, created_at=time.time()-120),
    #     Blog(id='2', name='Something New', summary=summary, created_at=time.time()-3600),
    #     Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time()-7200)
    # ]
    page_index = get_page_index(page)
    num = yield from Blog.findNumber('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = yield from Blog.findAll(orderBy='created_at desc',limit=(page.offset,page.limit))
    return {
        '__template__': 'blogs.html',
        'page':page,
        'blogs': blogs
    }
Esempio n. 27
0
def find_model(model, id):
    if model == 'blog':
        blog = yield from Blog.find(id)
        return blog
    if model == 'user':
        user = yield from User.find(id)
        return user
    if model == 'comment':
        comment = yield from Comment.find(id)
        return comment
Esempio n. 28
0
def find_models(model, where=None, args=None, **kw):
    if model == 'user':
        users = yield from User.findall(where=where, args=args, **kw)
        return users
    if model == 'blog':
        blogs = yield from Blog.findall(where=where, args=args, **kw)
        return blogs
    if model == 'comment':
        comments = yield from Comment.findall(where=where, args=args, **kw)
        return comments
Esempio n. 29
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
    }
Esempio n. 30
0
async def index(request):
    '''
    用户浏览页:首页
    '''
    summary = 'Lorem ipsum dolor sit amet, consectetur adpipislicin elit sed wo tempo inciditundng up labore et doloire mabndf aliquea'
    blogs = [
        Blog(id='1',
             name='Test Blog',
             summary=summary,
             create_at=time.time() - 120),
        Blog(id='2',
             name='Something New',
             summary=summary,
             create_at=time.time() - 3600),
        Blog(id='3',
             name='Learn Swift',
             summary=summary,
             create_at=time.time() - 7200)
    ]
    return {'__template__': 'blogs.html', 'blogs': blogs}
Esempio n. 31
0
def hello(blog_id=None):
    name = request.cookie.get('name')
    sign = request.cookie.get('sign')
    if not sign or sign != app.signed_cookie.get(name):
        return redirect('/')

    if request.path == '/hello':
        blog = Blog.get(name=name)
        if blog is None:
            return render('hello.html', name=name)
        return redirect('/hello/' + blog.id)

    if blog_id.startswith('File'):
        blog = Blog(title=blog_id, content="")
        return render('hello.html', name=name, blog=blog)

    blog = Blog.get(blog_id)
    files = os.listdir(os.path.join(os.getcwd(), 'file'))
    files = ((f, quote(f).replace('%', '-')) for f in files)
    blogs = Blog.get_all(name=name)
    return render('hello.html', name=name, blog=blog, files=files, blogs=blogs)
Esempio n. 32
0
def hello(request):
    try:
        name = request.cookie["name"].value
        sign = request.cookie["sign"].value
        assert name in signed_cookie and signed_cookie[name] == sign
        if request.path == "/hello":
            blog = Blog.get(name=name)
            if blog is None:
                return render_for_response(request, "hello.html", name=name)
            request.status = "303 See Other"
            request.header.append(("Location", "/hello/" + blog.id))
            return request

        files = os.listdir(os.path.join(os.getcwd(), "file"))
        blog = Blog.get(id=request.path.replace("/hello/", ""))
        blogs = Blog.get_all(name=name)
        return render_for_response(request, "hello.html", files=files, name=name, blog=blog, blogs=blogs)
    except (KeyError, AssertionError):
        request.status = "303 See Other"
        request.header.append(("Location", "/"))
        return request
Esempio n. 33
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
Esempio n. 34
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
async def createBlog(request, *, name, summary, content, id):
    #check_admin(request)
    if 0 == id:
        blog = Blog(user_id=request.__user__.id,
                    user_name=request.__user__.name,
                    user_image=request.__user__.image,
                    name=name.strip(),
                    summary=summary.strip(),
                    content=content.strip())
        await blog.save()
    else:
        blog = await Blog.find(id)
        if blog:
            blog.update({
                'name': name,
                'summary': summary,
                'content': content
            })
            await blog.save()
        else:
            return Exception('No blog found')
    return blog
Esempio n. 36
0
def hello(request):
    try:
        name = request.cookie['name'].value
        sign = request.cookie['sign'].value
        assert name in signed_cookie and signed_cookie[name] == sign
        if request.path == '/hello':
            blog = Blog.get(name=name)
            if blog is None:
                return render_for_response(request, 'hello.html', name=name)
            request.status = '303 See Other'
            request.header.append(('Location', '/hello/' + blog.id))
            return request

        files = os.listdir(os.path.join(os.getcwd(), 'file'))
        blog = Blog.get(id=request.path.replace('/hello/', ''))
        blogs = Blog.get_all(name=name)
        return render_for_response(request, 'hello.html', files=files,
                                   name=name, blog=blog, blogs=blogs)
    except (KeyError, AssertionError):
        request.status = '303 See Other'
        request.header.append(('Location', '/'))
        return request
Esempio n. 37
0
def get_blog(id):
    #通过id在数据库Blog表中查询对应内容:
    blog = yield from Blog.find(id)
    #通过id在数据库Comment表中查询对应内容:
    comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
    for c in comments:
        #将content值从text格式转换成html格式:
        c.html_content = text2html(c.content)
    blog.html_content = markdown2.markdown(blog.content)
    return {
        '__template__': 'blog.html',
        'blog': blog,
        'comments': comments
    }
Esempio n. 38
0
def apiUpdateBlog(id, request, *, name, summary, content):
    checkAdmin(request)
    blog = yield from Blog.find(id)
    if not name or not name.strip():
        raise APIValueError('文章标题', '文章标题不能为空')
    if not summary or not summary.strip():
        raise APIValueError('文章概要', '文章概要不能为空')
    if not content or not content.strip():
        raise APIValueError('文章内容', '文章内容不能为空')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    yield from blog.merge()
    return blog
Esempio n. 39
0
    def post(self):
        #print request.form
        """
        try:
            print session['name']
        except:
            print 'Add blog has no username'
        """
        tag_list = []
        this_blog_name = request.form['name']
        for i in Constant.tags:
            if this_blog_name.lower().find(i) != -1:
                tag_list.append(i)

        blog = Blog(
            user_id='00140408322081006c255e61b634c5a8937be2afc6119f7000',  # TODO
            user_name='Test',
            tag=";".join(tag_list),
            name=request.form['name'],
            summary=request.form['summary'],
            content=request.form['content'],
        )
        blog.insert()
Esempio n. 40
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 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
Esempio n. 41
0
def post_blog(request):
    dic = request.form
    if 'id' in dic:
        Blog.delete(dic['id'])
    dic['name'] = request.cookie['name'].value
    blog = Blog(**dic)
    blog.insert()
    request.status = '303 See Other'
    request.header.append(('Location', '/hello/' + blog.id))
    return request
Esempio n. 42
0
async def api_create_blog(request, *, name, summary, content):
    check_admin(request)
    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 = Blog(user_id=request.__user__.id,
                user_name=request.__user__.name,
                user_image=request.__user__.image,
                name=name.strip(),
                summary=summary.strip(),
                content=content.strip())
    await blog.save()
    return blog
Esempio n. 43
0
def apiCreateComment(id, request, *, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('请先登录')
    if not content or not content.strip():
        raise APIValueError('内容为空')
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('文章不存在')
    comment = Comment(blogId=blog.id,
                      userId=user.id,
                      userName=user.name,
                      userImage=user.image,
                      content=content.strip())
    yield from Comment.save(comment)
    return content
Esempio n. 44
0
async def api_create_comment(blog_id, request, *, content):
    check_admin(request)
    user = request.__user__
    if user is None:
        raise APIPermissionError()
    if not content or not content.strip():
        raise APIValueError('content')
    blog = Blog.find(blog_id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog_id,
                      user_id=request.__user__.id,
                      user_name=request.__user__.name,
                      user_image=request.__user__.image,
                      content=content)
    await comment.save()
    return comment
Esempio n. 45
0
def api_create_comment(id, request, *, content):
    #获取请求中的用户信息:
    user = request.__user__
    #用户信息为None则抛出异常:
    if user is None:
        raise APIPermissionError('Please signin first.')
    #参数中内容信息为空,抛出异常:
    if not content or not content.strip():
        raise APIValueError('content')
    #数据库Blog表中查询指定文章信息:
    blog = yield from Blog.find(id)
    #查询无结果则抛出异常:
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    #创建comment实例:
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    #将Comment信息存储到数据库:
    yield from comment.save()
    return comment
Esempio n. 46
0
def api_update_blog(id, request, *, name, summary, content):
    #校验当前用户权限:
    check_admin(request)
    #数据库Blog表中查询指定文章信息:
    blog = yield from Blog.find(id)
    #校验传递值中参数‘name’是否为空或空串,为空则抛出异常:
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    #校验传递值中参数‘summary’是否为空或空串,为空则抛出异常:
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    #校验传递值中参数‘content’是否为空或空串,为空则抛出异常:
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    #将传递值中的信息赋值到blog实例中:
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    #将Blog信息更新到数据库:
    yield from blog.update()
    return blog
Esempio n. 47
0
def delete_blog():
    Blog.delete(request.referer[-32:])
    return redirect('/hello')
Esempio n. 48
0
def update_blog():
    blog = Blog.get(id=request.referer[-32:])
    return render('update_blog.html', blog=blog)
Esempio n. 49
0
def update_blog(request):
    blog = Blog.get(id=request.referer[-32:])
    return render_for_response(request, "update_blog.html", blog=blog)
Esempio n. 50
0
def delete_blog(request):
    Blog.delete(request.referer[-32:])
    request.path = "/hello"
    return hello(request)
Esempio n. 51
0
def api_get_blog(*, id):
    blog = yield from Blog.find(id)
    return blog