def get_all_enum_proxies(): """Produce a collection of all the application Enums (subclasses of `Enum`) in proxy form. Note: Subclasses of `Enum` will only be found if they were previously imported. :return: A list of dicts of the form:: { 'name': <Enum.__name__>, 'items: [ { 'name': <EnumItem.name>, 'key': <EnumItem.key>, 'value': <EnumItem.value>, 'metadata': <EnumItem.metadata>, }, ], 'metadata': {...}, } """ enum_proxies = [] for enum_cls in sorted(cu.subclasses(Enum), key=lambda obj: obj.__name__): if is_dynamic_enum(enum_cls): # Explicitly refresh the dynamic enums enum_cls.__refresh__() items = [create_enum_item_proxy( su.snake_to_spinal(enum_cls.lookup(x[0])), x[0], x[1], enum_cls.metadata(x[0])) for x in enum_cls.verbose()] enum_metadata = enum_cls.__metadata__ if hasattr(enum_cls, '__metadata__') else None enum_proxies.append(create_enum_proxy(enum_cls.__name__, items, enum_metadata)) return enum_proxies
def make_enum_item_id(enum_cls, item_name): """Create an external identifier for an `EnumItem` that is suitable to transmit to the API client.""" return su.snake_to_spinal(item_name)