Example #1
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
    }
Example #2
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
Example #3
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)
Example #4
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)
Example #5
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}
Example #6
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
    }
Example #7
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)
Example #8
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
    }
Example #9
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
    }
Example #10
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
    }
Example #11
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
    }