Пример #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
    }
Пример #2
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)
Пример #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,blog=())
    blogs = yield from Blog.findAll(orderBy='created_at desc',limit=(p.offset,p.limit))
    return dict(page=p,blogs=blogs)
Пример #4
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}
Пример #5
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
    }
Пример #6
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)
Пример #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
    }
Пример #8
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
    }
Пример #9
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
    }
Пример #10
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
    }