def index(): featured_charms = app.store_api.find( category="featured", fields=SEARCH_FIELDS )["results"] context = { "categories": CATEGORIES, "featured_charms": featured_charms, "ops_badges": OPS_BADGES, "ops_badges_json": json.dumps(OPS_BADGES), } featured_packages = [] for i, item in enumerate(featured_charms): charm = logic.add_store_front_data(featured_charms[i], False) featured_packages.append(charm) context["featured_charms"] = featured_packages return render_template("store.html", **context)
def get_packages(): query = request.args.get("q", default=None, type=str) if query: results = app.store_api.find(query=query, fields=SEARCH_FIELDS).get("results") else: results = app.store_api.find(fields=SEARCH_FIELDS).get("results", []) packages = [] total_packages = 0 for i, item in enumerate(results): total_packages += 1 package = logic.add_store_front_data(results[i], False) packages.append(package) return { "packages": sorted(packages, key=lambda c: c["name"]), "q": query, "size": total_packages, }
def get_package(entity_name, channel_request, fields): # Get entity info from API package = app.store_api.get_item_details(entity_name, channel=channel_request, fields=fields) # If the package is not published, return a 404 if not package["default-release"]: abort(404) # Fix issue #1010 if channel_request: channel_map = app.store_api.get_item_details(entity_name, fields=["channel-map"]) package["channel-map"] = channel_map["channel-map"] package = logic.add_store_front_data(package, True) for channel in package["channel-map"]: channel["channel"]["released-at"] = logic.convert_date( channel["channel"]["released-at"]) return package
def details_overview(entity_name): # Get entity info from API package = app.store_api.get_item_details(entity_name, fields=FIELDS) package = logic.add_store_front_data(package) for channel in package["channel-map"]: channel["channel"]["released-at"] = logic.convert_date( channel["channel"]["released-at"]) readme = package["default-release"]["revision"]["readme-md"] # Remove Markdown comments readme = re.sub("(<!--.*-->)", "", readme, flags=re.DOTALL) readme = md_parser(readme) readme = increase_headers(readme) return render_template( "details/overview.html", package=package, readme=readme, package_type=package["type"], )
def details_library(entity_name, library_name): package = app.store_api.get_item_details(entity_name, fields=FIELDS) package = logic.add_store_front_data(package) lib_parts = library_name.split(".") lib_group = ".".join(lib_parts[:-2]) lib_name = "." + ".".join(lib_parts[-2:]) libraries = get_charm_libraries() library = next( (lib for lib in libraries[lib_group] if lib["name"] == lib_name), None, ) docstrings = logic.process_python_docs(library, module_name=library_name) return render_template( "details/libraries/library.html", entity_name=entity_name, package=package, libraries=libraries, library=library, docstrings=docstrings, )
def details_history(entity_name): package = app.store_api.get_item_details(entity_name, fields=FIELDS) package = logic.add_store_front_data(package) return render_template("details/history.html", package=package)