def _onRemoveSite(self): i = self.siteListWidget.currentItem() if i: appid = unicode(i.data(Qt.UserRole).toPyObject()) if QtSingleApplication.isOtherRunning(appid): QMessageBox.information( self, tr('SiteEditorWindow', 'Cannot delete app'), tr('SiteEditorWindow', 'You cannot delete an app while it is running')) return name = unicode(i.text()) answer = QMessageBox.warning( self, tr('SiteEditorWindow', 'Are you sure you want to delete web app?'), tr( 'SiteEditorWindow', '<strong>Are you sure you want to delete %s?</strong><br/><br/>' 'All cookies, preferences, and other stored data associated will be deleted.' % name), QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.Yes: self.siteListWidget.removeItemWidget(i) desktopPath = desktop.getPath('%s-%s.desktop' % (APP_NAME.lower(), appid)) if os.path.exists(desktopPath): os.remove(desktopPath) iconPath = os.path.join(desktop.dataPath(), '%s.png' % self.desktopEntry.appid) if os.path.exists(iconPath): os.remove(iconPath) jar = PersistableCookieJar(identifier=appid) jar.deleteFilesThreaded() self.siteListWidget.takeItem(self.siteListWidget.row(i))
def fill_missing_header_items(ctx: context.Context, streets: str, additional_housenumbers: bool, relation_name: str, items: List[yattag.doc.Doc]) -> None: """Generates the 'missing house numbers/streets' part of the header.""" prefix = ctx.get_ini().get_uri_prefix() if streets != "only": doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/missing-housenumbers/" + relation_name + "/view-result"): doc.text(tr("Missing house numbers")) items.append(doc) if additional_housenumbers: doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/additional-housenumbers/" + relation_name + "/view-result"): doc.text(tr("Additional house numbers")) items.append(doc) if streets != "no": doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/missing-streets/" + relation_name + "/view-result"): doc.text(tr("Missing streets")) items.append(doc) doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/additional-streets/" + relation_name + "/view-result"): doc.text(tr("Additional streets")) items.append(doc)
def handle_main_street_additional_count( ctx: context.Context, relation: areas.Relation) -> yattag.doc.Doc: """Handles the street additional count part of the main page.""" prefix = ctx.get_ini().get_uri_prefix() url = prefix + "/additional-streets/" + relation.get_name( ) + "/view-result" additional_count = "" if ctx.get_file_system().path_exists( relation.get_files().get_streets_additional_count_path()): additional_count = util.get_content( relation.get_files().get_streets_additional_count_path()).decode( "utf-8") doc = yattag.doc.Doc() if additional_count: date = get_last_modified( relation.get_files().get_streets_additional_count_path()) with doc.tag("strong"): with doc.tag("a", href=url, title=tr("updated") + " " + date): doc.text(tr("{} streets").format(additional_count)) return doc with doc.tag("strong"): with doc.tag("a", href=url): doc.text(tr("additional streets")) return doc
def invalid_refstreets_to_html( invalids: Tuple[List[str], List[str]]) -> yattag.doc.Doc: """Produces HTML enumerations for 2 string lists.""" doc = yattag.doc.Doc() osm_invalids, ref_invalids = invalids if osm_invalids: doc.stag("br") with doc.tag("div", id="osm-invalids-container"): doc.text( tr("Warning: broken OSM <-> reference mapping, the following OSM names are invalid:" )) with doc.tag("ul"): for osm_invalid in osm_invalids: with doc.tag("li"): doc.text(osm_invalid) if ref_invalids: doc.stag("br") with doc.tag("div", id="ref-invalids-container"): doc.text( tr("Warning: broken OSM <-> reference mapping, the following reference names are invalid:" )) with doc.tag("ul"): for ref_invalid in ref_invalids: with doc.tag("li"): doc.text(ref_invalid) if osm_invalids or ref_invalids: doc.stag("br") doc.text( tr("Note: an OSM name is invalid if it's not in the OSM database.") ) doc.text( tr("A reference name is invalid if it's in the OSM database.")) return doc
def getPath(filename=None): """ Returns the full path of a new or existing desktop file. If filename is None, return the path to where the file would be. """ directory = None for d in xdg.BaseDirectory.xdg_data_dirs: d = os.path.join(d, 'applications') if os.access(d, os.W_OK): directory = d break if not directory: for d in xdg.BaseDirectory.xdg_data_dirs: if os.access(d, os.W_OK): directory = os.path.join(d, 'applications') os.mkdir(directory) break if not directory: errors.showError(tr('None', 'Unable to find desktop menu folder'), tr('None', '%s was unable to find where you store your FreeDesktop.org menu items. Perhaps ' \ 'you are not running a FreeDesktop.org-compliant desktop?' % APP_NAME)) return if filename: return os.path.realpath(os.path.join(directory, filename)) else: return directory
def additional_streets_view_txt(ctx: context.Context, relations: areas.Relations, request_uri: str, chkl: bool) -> Tuple[str, str]: """Expected request_uri: e.g. /osm/additional-streets/ujbuda/view-result.txt.""" tokens = request_uri.split("/") relation_name = tokens[-2] relation = relations.get_relation(relation_name) output = "" if not ctx.get_file_system().path_exists( relation.get_files().get_osm_streets_path()): output += tr("No existing streets") elif not ctx.get_file_system().path_exists( relation.get_files().get_ref_streets_path()): output += tr("No reference streets") else: streets = relation.get_additional_streets() lexical_sort_key = util.get_lexical_sort_key() streets.sort( key=lambda street: lexical_sort_key(street.get_osm_name())) for street in streets: if chkl: output += "[ ] {}\n".format(street.get_osm_name()) else: output += "{}\n".format(street.get_osm_name()) return output, relation_name
def handle_main_housenr_additional_count( ctx: context.Context, relation: areas.Relation) -> yattag.doc.Doc: """Handles the housenumber additional count part of the main page.""" if not relation.get_config().should_check_additional_housenumbers(): return yattag.doc.Doc() prefix = ctx.get_ini().get_uri_prefix() url = prefix + "/additional-housenumbers/" + relation.get_name( ) + "/view-result" additional_count = "" if ctx.get_file_system().path_exists( relation.get_files().get_housenumbers_additional_count_path()): path = relation.get_files().get_housenumbers_additional_count_path() additional_count = util.get_content(path).decode("utf-8").strip() doc = yattag.doc.Doc() if additional_count: date = get_last_modified( relation.get_files().get_housenumbers_additional_count_path()) with doc.tag("strong"): with doc.tag("a", href=url, title=tr("updated") + " " + date): doc.text(tr("{} house numbers").format(additional_count)) return doc with doc.tag("strong"): with doc.tag("a", href=url): doc.text(tr("additional house numbers")) return doc
def handle_main_street_percent( ctx: context.Context, relation: areas.Relation) -> Tuple[yattag.doc.Doc, str]: """Handles the street percent part of the main page.""" prefix = ctx.get_ini().get_uri_prefix() url = prefix + "/missing-streets/" + relation.get_name() + "/view-result" percent = "N/A" if ctx.get_file_system().path_exists( relation.get_files().get_streets_percent_path()): percent = util.get_content( relation.get_files().get_streets_percent_path()).decode("utf-8") doc = yattag.doc.Doc() if percent != "N/A": date = get_last_modified( relation.get_files().get_streets_percent_path()) with doc.tag("strong"): with doc.tag("a", href=url, title=tr("updated") + " " + date): doc.text(util.format_percent(percent)) return doc, percent with doc.tag("strong"): with doc.tag("a", href=url): doc.text(tr("missing streets")) return doc, "0"
def _browse(self): file = QFileDialog.getOpenFileName( self, tr('SiteEditorWindow', 'Select icon'), os.getcwd(), tr('SiteEditorWindow', 'Images (*.png *.jpg)')) self.iconLocationLineEdit.setText(file) self.refreshIconPreview() if self.isWidget or not self.isNew: self._interactiveSave()
def handle_404() -> yattag.doc.Doc: """Displays a not-found page.""" doc = yattag.doc.Doc() util.write_html_header(doc) with doc.tag("html"): with doc.tag("body"): with doc.tag("h1"): doc.text(tr("Not Found")) with doc.tag("p"): doc.text(tr("The requested URL was not found on this server.")) return doc
def handle_overpass_error(ctx: context.Context, http_error: str) -> yattag.doc.Doc: """Handles a HTTP error from Overpass.""" doc = yattag.doc.Doc() with doc.tag("div", id="overpass-error"): doc.text(tr("Overpass error: {0}").format(http_error)) sleep = overpass_query.overpass_query_need_sleep(ctx) if sleep: doc.stag("br") doc.text(tr("Note: wait for {} seconds").format(sleep)) return doc
def missing_housenumbers_update(ctx: context.Context, relations: areas.Relations, relation_name: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/update-result.""" references = ctx.get_ini().get_reference_housenumber_paths() relation = relations.get_relation(relation_name) relation.write_ref_housenumbers(references) doc = yattag.doc.Doc() doc.text(tr("Update successful: ")) prefix = ctx.get_ini().get_uri_prefix() link = prefix + "/missing-housenumbers/" + relation_name + "/view-result" doc.asis(util.gen_link(link, tr("View missing house numbers")).getvalue()) return doc
def missing_housenumbers_view_chkl(ctx: context.Context, relations: areas.Relations, request_uri: str) -> Tuple[str, str]: """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/view-result.chkl.""" tokens = request_uri.split("/") relation_name = tokens[-2] relation = relations.get_relation(relation_name) relation.get_config().set_letter_suffix_style(util.LetterSuffixStyle.LOWER) output = "" if not ctx.get_file_system().path_exists( relation.get_files().get_osm_streets_path()): output += tr("No existing streets") elif not ctx.get_file_system().path_exists( relation.get_files().get_osm_housenumbers_path()): output += tr("No existing house numbers") elif not ctx.get_file_system().path_exists( relation.get_files().get_ref_housenumbers_path()): output += tr("No reference house numbers") else: ongoing_streets, _ignore = relation.get_missing_housenumbers() table = [] for result in ongoing_streets: range_list = util.get_housenumber_ranges(result[1]) # Street name, only_in_reference items. row = "[ ] " if not relation.get_config().get_street_is_even_odd( result[0].get_osm_name()): result_sorted = sorted([i.get_number() for i in range_list], key=util.split_house_number) row += result[0].get_osm_name() + " [" + ", ".join( result_sorted) + "]" table.append(row) else: elements = util.format_even_odd(range_list, doc=None) if len(elements) > 1 and len( range_list) > get_chkl_split_limit(): for element in elements: row = "[ ] " + result[0].get_osm_name( ) + " [" + element + "]" table.append(row) else: row += result[0].get_osm_name() + " [" + "], [".join( elements) + "]" table.append(row) table.sort(key=util.get_lexical_sort_key()) output += "\n".join(table) return output, relation_name
def handle_street_housenumbers(ctx: context.Context, relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/street-housenumbers/ormezo/view-query.""" tokens = request_uri.split("/") relation_name = tokens[-2] action = tokens[-1] relation = relations.get_relation(relation_name) osmrelation = relation.get_config().get_osmrelation() doc = yattag.doc.Doc() doc.asis( webframe.get_toolbar(ctx, relations, "street-housenumbers", relation_name, osmrelation).getvalue()) prefix = ctx.get_ini().get_uri_prefix() if action == "view-query": with doc.tag("pre"): doc.text(relation.get_osm_housenumbers_query()) elif action == "update-result": query = relation.get_osm_housenumbers_query() buf, err = overpass_query.overpass_query(ctx, query) if err: doc.asis(util.handle_overpass_error(ctx, err).getvalue()) else: relation.get_files().write_osm_housenumbers(ctx, buf) doc.text(tr("Update successful: ")) link = prefix + "/missing-housenumbers/" + relation_name + "/view-result" doc.asis( util.gen_link(link, tr("View missing house numbers")).getvalue()) else: # assume view-result if not ctx.get_file_system().path_exists( relation.get_files().get_osm_housenumbers_path()): with doc.tag("div", id="no-osm-housenumbers"): doc.text(tr("No existing house numbers")) else: with relation.get_files().get_osm_housenumbers_csv_stream( ctx) as sock: doc.asis( util.html_table_from_list( util.tsv_to_list(sock)).getvalue()) date = get_housenumbers_last_modified(relation) doc.asis(webframe.get_footer(date).getvalue()) return doc
def write_html_head(ctx: context.Context, doc: yattag.doc.Doc, title: str) -> None: """Produces the <head> tag and its contents.""" prefix = ctx.get_ini().get_uri_prefix() with doc.tag("head"): doc.stag("meta", charset="UTF-8") doc.stag("meta", name="viewport", content="width=device-width, initial-scale=1") with doc.tag("title"): doc.text(tr("Where to map?") + title) doc.stag("link", rel="icon", type="image/vnd.microsoft.icon", sizes="16x12", href=prefix + "/favicon.ico") doc.stag("link", rel="icon", type="image/svg+xml", sizes="any", href=prefix + "/favicon.svg") css_path = os.path.join(ctx.get_ini().get_workdir(), "osm.min.css") with open(css_path, "r") as stream: with doc.tag("style"): doc.text(stream.read()) with doc.tag("noscript"): with doc.tag("style", type="text/css"): doc.text(".no-js { display: block; }") doc.text(".js { display: none; }") with doc.tag("script", defer="", src=prefix + "/static/bundle.js"): pass
def get_PIN(): global user_pin if not user_pin: user_pin = getpass.getpass( tr('Please provide user PIN for the device (will not be echoed): ') ) return user_pin
def handle_main(request_uri: str, ctx: context.Context, 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(ctx, relations).getvalue()) doc.asis(handle_main_filters(ctx, relations, refcounty).getvalue()) table = [] table.append([ util.html_escape(tr("Area")), util.html_escape(tr("House number coverage")), util.html_escape(tr("Additional house numbers")), util.html_escape(tr("Street coverage")), util.html_escape(tr("Additional streets")), util.html_escape(tr("Area boundary")) ]) for relation_name in relations.get_names(): row = handle_main_relation(ctx, 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(tr("Add new area")) doc.asis(webframe.get_footer().getvalue()) return doc
def fill_existing_header_items(ctx: context.Context, streets: str, relation_name: str, items: List[yattag.doc.Doc]) -> None: """Generates the 'existing house numbers/streets' part of the header.""" prefix = ctx.get_ini().get_uri_prefix() if streets != "only": doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/street-housenumbers/" + relation_name + "/view-result"): doc.text(tr("Existing house numbers")) items.append(doc) doc = yattag.doc.Doc() with doc.tag("a", href=prefix + "/streets/" + relation_name + "/view-result"): doc.text(tr("Existing streets")) items.append(doc)
def missing_streets_update(ctx: context.Context, relations: areas.Relations, relation_name: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/missing-streets/ujbuda/update-result.""" relation = relations.get_relation(relation_name) relation.write_ref_streets(ctx.get_ini().get_reference_street_path()) doc = yattag.doc.Doc() with doc.tag("div", id="update-success"): doc.text(tr("Update successful.")) return doc
def get_html_title(request_uri: str) -> str: """Determines the HTML title for a given function and relation name.""" tokens = request_uri.split("/") function = "" relation_name = "" if len(tokens) > 3: function = tokens[2] relation_name = tokens[3] title = "" if function == "missing-housenumbers": title = " - " + tr("{0} missing house numbers").format(relation_name) elif function == "missing-streets": title = " - " + relation_name + " " + tr("missing streets") elif function == "street-housenumbers": title = " - " + relation_name + " " + tr("existing house numbers") elif function == "streets": title = " - " + relation_name + " " + tr("existing streets") return title
def handle_streets(ctx: context.Context, relations: areas.Relations, request_uri: str) -> yattag.doc.Doc: """Expected request_uri: e.g. /osm/streets/ormezo/view-query.""" tokens = request_uri.split("/") relation_name = tokens[-2] action = tokens[-1] relation = relations.get_relation(relation_name) osmrelation = relation.get_config().get_osmrelation() doc = yattag.doc.Doc() doc.asis( webframe.get_toolbar(ctx, relations, "streets", relation_name, osmrelation).getvalue()) if action == "view-query": with doc.tag("pre"): doc.text(relation.get_osm_streets_query()) elif action == "update-result": query = relation.get_osm_streets_query() buf, err = overpass_query.overpass_query(ctx, query) if err: doc.asis(util.handle_overpass_error(ctx, err).getvalue()) else: relation.get_files().write_osm_streets(ctx, buf) streets = relation.get_config().should_check_missing_streets() if streets != "only": doc.text(tr("Update successful: ")) link = ctx.get_ini().get_uri_prefix( ) + "/missing-housenumbers/" + relation_name + "/view-result" doc.asis( util.gen_link(link, tr("View missing house numbers")).getvalue()) else: doc.text(tr("Update successful.")) else: # assume view-result with relation.get_files().get_osm_streets_csv_stream(ctx) as sock: table = util.tsv_to_list(sock) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis( webframe.get_footer(get_streets_last_modified(relation)).getvalue()) return doc
def numbered_streets_to_table( self, numbered_streets: util.NumberedStreets ) -> Tuple[List[List[yattag.doc.Doc]], int]: """Turns a list of numbered streets into a HTML table.""" todo_count = 0 table = [] table.append([ util.html_escape(tr("Street name")), util.html_escape(tr("Missing count")), util.html_escape(tr("House numbers")) ]) rows = [] for result in numbered_streets: # street, only_in_ref row = [] row.append(result[0].to_html()) number_ranges = util.get_housenumber_ranges(result[1]) row.append(util.html_escape(str(len(number_ranges)))) doc = yattag.doc.Doc() if not self.get_config().get_street_is_even_odd( result[0].get_osm_name()): for index, item in enumerate( sorted(number_ranges, key=util.split_house_number_range)): if index: doc.text(", ") doc.asis(util.color_house_number(item).getvalue()) else: util.format_even_odd(number_ranges, doc) row.append(doc) todo_count += len(number_ranges) rows.append(row) # It's possible that get_housenumber_ranges() reduces the # of house numbers, e.g. 2, 4 and # 6 may be turned into 2-6, which is just 1 item. Sort by the 2nd col, which is the new # number of items. table += sorted(rows, reverse=True, key=lambda cells: int(cells[1].getvalue())) return table, todo_count
def handle_no_ref_streets(prefix: str, relation_name: str) -> yattag.doc.Doc: """Handles the no-ref-streets error on a page using JS.""" doc = yattag.doc.Doc() link = prefix + "/missing-streets/" + relation_name + "/update-result" with doc.tag("div", id="no-ref-streets"): with doc.tag("a", href=link): doc.text(tr("No street list: create from reference...")) # Emit localized strings for JS purposes. with doc.tag("div", style="display: none;"): string_pairs = [ ("str-reference-wait", tr("No reference streets: creating from reference...")), ("str-reference-error", tr("Error from reference: ")), ] for key, value in string_pairs: kwargs: Dict[str, str] = {} kwargs["id"] = key kwargs["data-value"] = value with doc.tag("div", **kwargs): pass return doc
def get_missing_housenumbers_html(ctx: context.Context, relation: areas.Relation) -> yattag.doc.Doc: """Gets the cached HTML of the missing housenumbers for a relation.""" doc = yattag.doc.Doc() if is_missing_housenumbers_html_cached(ctx, relation): with relation.get_files().get_housenumbers_htmlcache_stream( "rb") as stream: doc.asis(util.from_bytes(stream.read())) return doc ret = relation.write_missing_housenumbers() todo_street_count, todo_count, done_count, percent, table = ret with doc.tag("p"): prefix = ctx.get_ini().get_uri_prefix() relation_name = relation.get_name() doc.text( tr("OpenStreetMap is possibly missing the below {0} house numbers for {1} streets." ).format(str(todo_count), str(todo_street_count))) doc.text( tr(" (existing: {0}, ready: {1}).").format( str(done_count), util.format_percent(str(percent)))) doc.stag("br") with doc.tag( "a", href="https://github.com/vmiklos/osm-gimmisn/tree/master/doc"): doc.text(tr("Filter incorrect information")) doc.text(".") doc.stag("br") with doc.tag( "a", href=prefix + "/missing-housenumbers/{}/view-turbo".format(relation_name)): doc.text(tr("Overpass turbo query for the below streets")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.txt".format( relation_name)): doc.text(tr("Plain text format")) doc.stag("br") with doc.tag("a", href=prefix + "/missing-housenumbers/{}/view-result.chkl".format( relation_name)): doc.text(tr("Checklist format")) doc.asis(util.html_table_from_list(table).getvalue()) doc.asis( util.invalid_refstreets_to_html( relation.get_invalid_refstreets()).getvalue()) doc.asis( util.invalid_filter_keys_to_html( relation.get_invalid_filter_keys()).getvalue()) with relation.get_files().get_housenumbers_htmlcache_stream( "wb") as stream: stream.write(util.to_bytes(doc.getvalue())) return doc
def get_footer(last_updated: str = "") -> yattag.doc.Doc: """Produces the end of the page.""" items: List[yattag.doc.Doc] = [] doc = yattag.doc.Doc() doc.text(tr("Version: ")) doc.asis( util.git_link( version.VERSION, "https://github.com/vmiklos/osm-gimmisn/commit/").getvalue()) items.append(doc) items.append(util.html_escape( tr("OSM data © OpenStreetMap contributors."))) if last_updated: items.append(util.html_escape(tr("Last update: ") + last_updated)) doc = yattag.doc.Doc() doc.stag("hr") with doc.tag("div"): for index, item in enumerate(items): if index: doc.text(" ¦ ") doc.asis(item.getvalue()) return doc
def _urlEditingFinished(self): url = unicode(self.urlLineEdit.text()) if url != unicode(self.desktopEntry.getBaseUrl): if not (url.startswith('http://') or url.startswith('https://')): url = 'http://%s' % url self.urlLineEdit.setText(url) if url and '.' in url and not unicode( self.iconLocationLineEdit.text()).strip(): self.iconStatusLabel.setText( tr('SiteEditorWindow', 'Finding icon...')) self.grabber = IconGrabber(url, self._onIconFound)
def missing_housenumbers_view_txt(ctx: context.Context, relations: areas.Relations, request_uri: str) -> str: """Expected request_uri: e.g. /osm/missing-housenumbers/ormezo/view-result.txt.""" tokens = request_uri.split("/") relation_name = tokens[-2] relation = relations.get_relation(relation_name) relation.get_config().set_letter_suffix_style(util.LetterSuffixStyle.LOWER) output = "" if not ctx.get_file_system().path_exists( relation.get_files().get_osm_streets_path()): output += tr("No existing streets") elif not ctx.get_file_system().path_exists( relation.get_files().get_osm_housenumbers_path()): output += tr("No existing house numbers") elif not ctx.get_file_system().path_exists( relation.get_files().get_ref_housenumbers_path()): output += tr("No reference house numbers") else: output = cache.get_missing_housenumbers_txt(ctx, relation) return output
def handle_no_osm_housenumbers(prefix: str, relation_name: str) -> yattag.doc.Doc: """Handles the no-osm-housenumbers error on a page using JS.""" doc = yattag.doc.Doc() link = prefix + "/street-housenumbers/" + relation_name + "/update-result" with doc.tag("div", id="no-osm-housenumbers"): with doc.tag("a", href=link): doc.text( tr("No existing house numbers: call Overpass to create...")) # Emit localized strings for JS purposes. with doc.tag("div", style="display: none;"): string_pairs = [ ("str-overpass-wait", tr("No existing house numbers: waiting for Overpass...")), ("str-overpass-error", tr("Error from Overpass: "******"id"] = key kwargs["data-value"] = value with doc.tag("div", **kwargs): pass return doc
def invalid_filter_keys_to_html(invalids: List[str]) -> yattag.doc.Doc: """Produces HTML enumerations for a string list.""" doc = yattag.doc.Doc() if invalids: doc.stag("br") with doc.tag("div", id="osm-filter-key-invalids-container"): doc.text( tr("Warning: broken filter key name, the following key names are not OSM names:" )) with doc.tag("ul"): for invalid in invalids: with doc.tag("li"): doc.text(invalid) return doc
def handle_main_relation(ctx: context.Context, relations: areas.Relations, filter_for: Callable[[bool, areas.Relation], bool], relation_name: str) -> List[yattag.doc.Doc]: """Handles one relation (one table row) on the main page.""" relation = relations.get_relation(relation_name) # If checking both streets and house numbers, then "is complete" refers to both street and # housenr coverage for "hide complete" purposes. complete = True streets = relation.get_config().should_check_missing_streets() row = [] # List[yattag.doc.Doc] row.append(util.html_escape(relation_name)) if streets != "only": cell, percent = handle_main_housenr_percent(ctx, relation) doc = yattag.doc.Doc() doc.asis(cell.getvalue()) row.append(doc) complete &= float(percent) >= 100.0 row.append(handle_main_housenr_additional_count(ctx, relation)) else: row.append(yattag.doc.Doc()) row.append(yattag.doc.Doc()) if streets != "no": cell, percent = handle_main_street_percent(ctx, relation) row.append(cell) complete &= float(percent) >= 100.0 else: row.append(yattag.doc.Doc()) if streets != "no": row.append(handle_main_street_additional_count(ctx, relation)) else: row.append(yattag.doc.Doc()) doc = yattag.doc.Doc() with doc.tag("a", href="https://www.openstreetmap.org/relation/" + str(relation.get_config().get_osmrelation())): doc.text(tr("area boundary")) row.append(doc) if not filter_for(complete, relation): row.clear() return row