def handle_main(request_uri: str, relations: areas.Relations) -> yattag.doc.Doc: """Handles the main wsgi page. Also handles /osm/filter-for/* which filters for a condition.""" filter_for, refcounty = setup_main_filter_for(request_uri) doc = yattag.doc.Doc() doc.asis(webframe.get_toolbar(relations).getvalue()) doc.asis(handle_main_filters(relations, refcounty).getvalue()) table = [] table.append([ util.html_escape(_("Area")), util.html_escape(_("House number coverage")), util.html_escape(_("Existing house numbers")), util.html_escape(_("Street coverage")), util.html_escape(_("Existing streets")), util.html_escape(_("Area boundary")) ]) for relation_name in relations.get_names(): row = handle_main_relation(relations, filter_for, relation_name) if row: table.append(row) doc.asis(util.html_table_from_list(table).getvalue()) with doc.tag("p"): with doc.tag( "a", href="https://github.com/vmiklos/osm-gimmisn/tree/master/doc"): doc.text(_("Add new area")) doc.asis(webframe.get_footer().getvalue()) return doc
def is_complete_relation(relations: areas.Relations, relation_name: str) -> bool: """Does this relation have 100% house number coverage?""" assert relation_name in relations.get_names() relation = relations.get_relation(relation_name) if not os.path.exists( relation.get_files().get_housenumbers_percent_path()): return False percent = util.get_content( relation.get_files().get_housenumbers_percent_path()).decode("utf-8") return percent == "100.00"
def check_existing_relation(relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Prevents serving outdated data from a relation that has been renamed.""" doc = yattag.doc.Doc() if not request_uri.startswith("/osm/streets/") \ and not request_uri.startswith("/osm/missing-streets/") \ and not request_uri.startswith("/osm/street-housenumbers/") \ and not request_uri.startswith("/osm/missing-housenumbers/"): return doc tokens = request_uri.split("/") relation_name = tokens[-2] if relation_name in relations.get_names(): return doc with doc.tag("div", id="no-such-relation-error"): doc.text(_("No such relation: {0}").format(relation_name)) return doc