Skip to content
Snippets Groups Projects
utils.py 860 B
Newer Older
from orchestrator.forms.validators import Choice

from gso.services.crm import all_customers


def customer_selector() -> Choice:
    customers = {}
    for customer in all_customers():
        customers[customer["id"]] = customer["name"]

    return Choice("Select a customer", zip(customers.keys(), customers.items()))  # type: ignore


def iso_from_ipv4(ipv4_address: IPv4Address) -> str:
Karel van Klink's avatar
Karel van Klink committed
    """Calculate an {term}`ISO` address, based on an IPv4 address.
Karel van Klink's avatar
Karel van Klink committed
    :param IPv4Address ipv4_address: The address that's to be converted
    :returns: An {term}`ISO`-formatted address.
    """
    padded_octets = [f"{x:>03}" for x in str(ipv4_address).split(".")]
    joined_octets = "".join(padded_octets)
    re_split = ".".join(re.findall("....", joined_octets))
    return ".".join(["49.51e5.0001", re_split, "00"])