rpasdt.common package

Submodules

rpasdt.common.enums module

Common Enum subclasses that can be use to hold model choices (including ugettext_lazy values)

# Examples:

class rpasdt.common.enums.ChoiceEnumMeta(cls, bases, attrs)[source]

Bases: enum.EnumMeta

Metaclass for ChoiceEnum classes.

property choices

Retrieve a tuple of all choices - (value, label) pairs.

property label_to_value

Retrieve a dict of all choices - (label, value) pairs. We lowercase the keys to make the search easier and keep the case in enum definition intact.

property labels

Retrieve a tuple of all labels.

property values

Retrieve a tuple of all values.

class rpasdt.common.enums.DecimalChoiceEnum(value)[source]

Bases: rpasdt.common.enums.DecimalEnum

ChoiceEnum with values / instances restricted to be Decimal objects.

class rpasdt.common.enums.DecimalEnum(value)[source]

Bases: decimal.Decimal, enum.Enum

Enum where members are Decimal objects.

class rpasdt.common.enums.GenericChoiceEnum(value)[source]

Bases: enum.Enum

ChoiceEnum with type restriction on values / instances.

class rpasdt.common.enums.IntChoiceEnum(value)[source]

Bases: enum.IntEnum

ChoiceEnum with values / instances restricted to be integers.

class rpasdt.common.enums.StringChoiceEnum(value)[source]

Bases: rpasdt.common.enums.StringEnum

ChoiceEnum with values / instances restricted to be strings.

class rpasdt.common.enums.StringEnum(value)[source]

Bases: str, enum.Enum

Enum where members are strings.

rpasdt.common.exceptions module

Exception utilities.

rpasdt.common.exceptions.log_error(type: Optional[type] = None, exc: Optional[Exception] = None, exc_traceback: Optional[Any] = None, title: Optional[str] = None)[source]

Intended to be assigned to sys.exception as a hook. Gives programmer opportunity to do something useful with info from uncaught exceptions.

Parameters type: Exception type value: Exception’s value tb: Exception’s traceback title: Additional title

rpasdt.common.utils module

Common methods shared throughout the app.

rpasdt.common.utils.camel_case_split(str)[source]
rpasdt.common.utils.copy_dict_values_into_object(object: Any, dict: dict) None[source]

Update object properties with dict values.

rpasdt.common.utils.eval_if_str(val: Any)[source]
rpasdt.common.utils.export_dataclass_as_json(object: Any, file_path: Optional[str] = None) str[source]
rpasdt.common.utils.format_label(string: str, required_words: Optional[List[str]] = None) str[source]
rpasdt.common.utils.get_default_value(type: Any, default: Optional[Any]) Optional[Any][source]
rpasdt.common.utils.get_enum(value: Union[enum.Enum, str], enum_type: type) enum.Enum[source]
rpasdt.common.utils.get_function_default_kwargs(func) Dict[str, Any][source]
rpasdt.common.utils.get_function_params(func) Mapping[str, inspect.Parameter][source]
rpasdt.common.utils.get_object_type_as_json_exportable(object: Any) Type[source]

Get object type to be json exportable.

It appends to_json method to an object type dynamically.

rpasdt.common.utils.get_object_value(object: Any, field_name: str) Optional[Any][source]
rpasdt.common.utils.group_dict_by_values(dict: Dict)[source]
rpasdt.common.utils.import_dataclass_from_json(type: Type, json_data: Optional[str] = None, file_path: Optional[str] = None) Any[source]
rpasdt.common.utils.multi_sum(iterable, *attributes, **kwargs)[source]
rpasdt.common.utils.object_to_dict(object: Any) dict[source]

Return dict representation of object.

rpasdt.common.utils.read_from_file(file_path: str) str[source]

Read content from the file.

rpasdt.common.utils.set_object_value(object: Any, field_name: str, value: Any) None[source]
rpasdt.common.utils.sort_dict_by_value(data: Dict[any, any], reverse=True)[source]
rpasdt.common.utils.write_to_file(text: str, file_path: str) None[source]

Save provided text into file with given path.

Module contents

Common methods utylized by the app.