app.model.lib.util#

Functions#

find_duplicates(collection)

is_non_negative_float(string, *, isnan_check)

Check if the given string value represents a finite float.

trim_lines(string)

Trim the whitespace from all the lines in the given string.

createzip(→ io.BytesIO)

Create a zip file from the given CSV files (as bytes)

group_by_unique_name(→ dict)

Group the items in the collection by their name.

humanize_camelcased_string(string)

Separates words in camelCased strings with spaces

download_file(url, filename)

Downloads the data from the given URL into the target filename

gunzip(path[, extracted_path])

Extracts the given gzip file.

untar(path, target_dir, file_list)

Extracts individual files from a tar file into the given `target_dir`.

read_timestamp_date(path)

Reads the contents of a file, if it exists, and interpret them as a

is_ajax(request)

hex_to_rgba(hex_string, opacity)

parse_comma_separated_request_ids(key)

Module Contents#

app.model.lib.util.find_duplicates(collection)[source]#
app.model.lib.util.is_non_negative_float(string: str, *, isnan_check: bool)[source]#

Check if the given string value represents a finite float.

This is used for validating data coming from Excel spreadsheets. It’s a bit hacky, there might be cleaner approaches.

app.model.lib.util.trim_lines(string: str)[source]#

Trim the whitespace from all the lines in the given string.

app.model.lib.util.createzip(csv_data: list[tuple[str, bytes]]) io.BytesIO[source]#

Create a zip file from the given CSV files (as bytes)

app.model.lib.util.group_by_unique_name(collection: Iterable) dict[source]#

Group the items in the collection by their name.

Raises an error if there is more than one element with the same name.

app.model.lib.util.humanize_camelcased_string(string: str)[source]#

Separates words in camelCased strings with spaces

app.model.lib.util.download_file(url: str, filename: str)[source]#

Downloads the data from the given URL into the target filename

app.model.lib.util.gunzip(path: pathlib.Path, extracted_path: pathlib.Path | None = None)[source]#

Extracts the given gzip file.

If no output path is given, removes the .gz suffix and uses that as the output path.

app.model.lib.util.untar(path: pathlib.Path, target_dir: pathlib.Path, file_list: list[str])[source]#

Extracts individual files from a tar file into the given `target_dir`.

File paths inside the tar file are listed in `file_list`.

app.model.lib.util.read_timestamp_date(path)[source]#

Reads the contents of a file, if it exists, and interpret them as a timestamp. Returns the time formatted as a date.

app.model.lib.util.is_ajax(request)[source]#
app.model.lib.util.hex_to_rgba(hex_string, opacity)[source]#
app.model.lib.util.parse_comma_separated_request_ids(key)[source]#