def api_interfaces(*, page='1'): #获取API信息 page_index = get_page_index(page) num = yield from Interface.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, Interfaces=()) interfaces = yield from Interface.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, ineterfaces=interfaces)
def interface_response(name): #格局APIid获取API返回 interfaces = yield from Interface.findAll('name=?', [name], orderBy='created_at desc') #interface = yield from Interface.findByCondition(name) #for interface in interfaces: # return interface.content #interface = None #for interface in interfaces: if len(interfaces) == 1: interface = interfaces[0] elif len(interfaces) > 1: raise APIValueError('name', 'The API name is not unique') else: raise APIValueError('name', 'Can\'t find %s API' % name) interface.content_type = 'application/json' return interface.content
def index(*, page='1'): #获取到要展示的API页数是第几页 page_index = get_page_index(page) #查找API表里的条目数 num = yield from Interface.findNumber('count(id)') #通过Page类计算当前页的相关信息 page = Page(num, page_index) #如果表里没有条目,则不需要 if num == 0: interfaces = [] else: #根据计算出来的offset(取的初始条目index)和limit(取的条数),来取出条目 interfaces = yield from Interface.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) #返回给浏览器 return { '__template__': 'interfaces.html', 'page': page, 'interfaces': interfaces }