def show_publisher(publisher): resources = [] registry_tmpl = "{registry_api}/package_search?q=organization:{{publisher}}{{search}}&rows={per_page}&start={{offset}}".format( registry_api=config.REGISTRY_API_BASE_URL, per_page=config.PER_PAGE, ) page = int(request.args.get('page', 1)) offset = (page - 1) * config.PER_PAGE search = request.args.get('q') searchstr = ' title:{}'.format(search) if search else '' j = fetch.exec_request(registry_tmpl.format(publisher=publisher, offset=offset, search=searchstr)).json() pagination = Pagination(page, config.PER_PAGE, j["result"]["count"]) for result in j["result"]["results"]: if result["num_resources"] == 0: continue filetype = [extra["value"] for extra in result["extras"] if extra["key"] == "filetype"][0] for resource in result["resources"]: resources.append({ "title": result["title"], "url": resource["url"], "package_name": result["name"], "revision": resource["revision_id"], "filetype": filetype, }) kwargs = { "resources": resources, "publisher": publisher, "pagination": pagination, } return render_template('publisher.html', **kwargs)
def show_home(): publishers = [] j = fetch.exec_request("{registry_api}/organization_list?all_fields=true".format( registry_api=config.REGISTRY_API_BASE_URL, )).json()["result"] search = request.args.get('q') if search: j = [x for x in j if search.lower() in x["title"].lower()] page = int(request.args.get('page', 1)) offset = (page - 1) * config.PER_PAGE results = j[offset:offset + config.PER_PAGE] pagination = Pagination(page, config.PER_PAGE, len(j)) for publisher in results: publishers.append({ "code": publisher["name"], "name": publisher["title"], "num_packages": publisher["packages"], }) kwargs = { "pagination": pagination, "publishers": publishers, } return render_template('publishers.html', **kwargs)