Esempio n. 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
    }
Esempio n. 2
0
def api_comments(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Comment.find_number('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, comments=())
    comments = yield from Comment.find_all(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, comments=comments)
Esempio n. 3
0
async def api_comments(*, page='1'):
    page_index = get_page_index(page)
    num = await Comment.find_number('count(id)')
    page = Page(num, page_index)
    return dict(page=page,
                comments=() if num == 0 else await Comment.find_all(
                    orderBy='created_at DESC', limit=(page.offset,
                                                      page.limit)))
Esempio n. 4
0
async def api_comments(*,page='1'):
    page_index=get_page_index(page)
    num=await Comment.findNumber('count(id)')
    p=Page(num,page_index)
    if num==0:
        return dict(page=p,comments=())
    comments=await Comment.findAll(orderby='created_at desc',limit=(p.offset,p.limit))
    return dict(page=p,comments=comments)
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,blogs=())
    blogs=yield from Blog.findAll(orderBy='created_at desc',limit=(p.offset,p.limit))
    return dict(page=p,blogs=blogs)
async def api_blogs(*, page="1"):
    page_index = get_page_index(page)
    num = await Blog.findNumber("count(id)")
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = await Blog.findAll(orderBy="created_at desc",
                               limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 7
0
async def api_blogs(*, page='1'):
    page_index = get_page_index(page)
    num = await Blog.find_number('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = await Blog.find_all(orderBy='created_at DESC',
                                limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 8
0
def api_get_users(*, page='1'):
    page_index = get_page_index(page)
    num = yield from User.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, users=())
    users = yield from User.findAll(orderBy='created_at desc',
                                    limit=(p.offset, p.limit))
    return dict(page=p, users=users)
async def api_comments(*, page="1"):
    page_index = get_page_index(page)
    num = await Comment.findNumber("count(*)")
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, comments=())
    comments = await Comment.findAll(orderBy="created_at desc",
                                     limit=(p.offset, p.limit))
    return dict(page=p, comments=comments)
Esempio n. 10
0
async def api_quotes(*, page='1'):
    page_index = get_page_index(page)
    num = await Quote.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, quotes=())
    quotes = await Quote.findAll(orderBy='created_at desc',
                                 limit=(p.offset, p.limit))
    return dict(page=p, quotes=quotes)
Esempio n. 11
0
async def api_blogs(*, page='1'):
    logging.info('york----------------------获取日志列表API')
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = await Blog.findAll(orderBy='created_at desc',
                               limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 12
0
async def index(*, page='1'):
    page_index = get_page_index(page)
    num = await Quote.findNumber('count(id)')
    page = Page(num, page_index)
    if num == 0:
        quotes = []
    else:
        quotes = await Quote.findAll(orderBy='created_at desc',
                                     limit=(page.offset, page.limit))
    return {'__template__': 'index.html', 'page': page, 'quotes': quotes}
Esempio n. 13
0
async def api_get_users(*, page='1'):
    page_index = get_page_index(page)
    num = await User.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, users=())
    users = await User.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    for u in users:
        u.passwd = '******'
    return dict(page=p, users=users)
Esempio n. 14
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. 15
0
def api_comments(*, page='1'):
    #获取页面索引,默认为1:
    page_index = get_page_index(page)
    #查询数据库中Comment表中评论总数:
    num = yield from Comment.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, comments=())
    comments = yield from Comment.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    return dict(page=p, comments=comments)
async def blog_list(*, page='1'):
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index, page_size=5)
    if num == 0:
        return dict(page=p, blogs=())
    else:
        blogs = await Blog.findall(orderBy='created_at desc ',
                                   limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 17
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)
Esempio n. 18
0
async def index(*, page='1'):
    logging.info('york----------------------处理首页URL')
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        blogs = []
    else:
        blogs = await Blog.findAll(orderBy='created_at desc',
                                   limit=(p.offset, p.limit))
    return {'__template__': 'blogs.html', 'page': p, 'blogs': blogs}
Esempio n. 19
0
async def index(*, page='1'):
    page_index = get_page_index(page)
    num = await Blog.find_number('count(id)')
    page = Page(num)
    if num == 0:
        blogs = []
    else:
        blogs = await Blog.find_all(orderBy='created_at DESC',
                                    limit=(page.offset, page.limit))

    return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
Esempio n. 20
0
async def api_blogs(*, page='1'):
    '''
    后端API:获取日志
    '''
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blog=())
    blogs = await Blog.findAll(orderBy='create_at desc',
                               limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 21
0
def api_get_users(*, page='1'):
    #获取页面索引,默认为1:
    page_index = get_page_index(page)
    #查询数据库中User表中用户总数:
    num = yield from User.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, users=())
    #查询数据库中User表中对应分页的用户结果;(limit为mysql的分页查询条件)
    users = yield from User.findAll(orderBy='created_at desc', limit=(p.offset, p.limit))
    for u in users:
        u.passwd = '******'
    return dict(page=p, users=users)
async def api_comments(*, page=1):
    '''
    分页查询评论
    :param page:
    :return:
    '''
    page_index = get_page_index(page)
    num = await Comment.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, comments=())
    comments = await Comment.findall(orderBy='created_at desc',
                                     limit=(p.offset, p.limit))
    return dict(page=p, comments=comments)
async def api_blogs(*, page='1'):
    '''
    根据页码查询日志,默认一页10条,初始页码为1
    如果没有日志返回空dict
    :param page:
    :return:
    '''
    page_index = get_page_index(page)
    num = await Blog.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, blogs=())
    blogs = await Blog.findall(orderBy='created_at desc',
                               limit=(p.offset, p.limit))
    return dict(page=p, blogs=blogs)
Esempio n. 24
0
async def api_get_users(*, page='1'):
    logging.info('york----------------------获取用户信息API')
    page_index = get_page_index(page)

    logging.info('york----------------------page_index', page_index)

    num = await User.findNumber('count(id)')
    p = Page(num, page_index)
    if num == 0:
        return dict(page=p, users=())
    users = await User.findAll(orderBy='created_at desc',
                               limit=(p.offset, p.limit))
    for u in users:
        u.passwd = '******'
        logging.info('york----------u', u)
    return dict(page=p, users=users)
Esempio n. 25
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. 26
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. 27
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
    }