Skip to content

Helper Utilities

mo_helper_kit provides utility functions to assist with various development tasks. Use these helpers to reduce repeated plumbing in API and tooling code.

Stability Warning

`mo_helper_kit` is not part of the core offering and is currently experimental and subject to change without any prior notice. Refer to this page to keep informed on development with helper utilities.

Implementation

Start by importing the helper kit in your API or utility module:

from django_mindoff.components.helper_kit import mo_helper_kit

1. Pascal To Snake

Convert PascalCase/CamelCase names to snake_case.

Usage:

snake = mo_helper_kit.pascal_to_snake("CreateOrderAPI")
# create_order_a_p_i

Parameters:

  • name (str): Input class/style name.

Possible responses:

  • Returns normalized snake_case string.

2. Get App Module Path

Resolve installed app import path from short app label.

Usage:

app_module = get_app_module_path("orders")

Parameters:

  • app_name (str): App label (last segment of installed app path).

Possible responses:

  • Returns full import path from INSTALLED_APPS.
  • Raises ValueError when app cannot be resolved.

3. Get Current App Name

Resolve current Django app label from caller file path.

Usage:

app_name = mo_helper_kit.get_current_app_name()

Possible responses:

  • Returns app label as str.
  • Raises ValueError when frame path cannot be mapped to a Django app.

4. Get Exact Traceback

Build filtered traceback text for project-owned frames.

Usage:

tb_text = mo_helper_kit.get_exact_traceback(skip=0)

Parameters:

  • skip (int | None, default=None): Frame index in filtered project stack. None returns all matching frames.

Behavior:

  • Filters stack using settings.MINDOFF_TRACEBACK_DIRS (default: apps, config).

Possible responses:

  • Returns formatted traceback string.
  • Returns fallback message when no project frame matches.

5. Get Api Class From Url Name

Resolve API class from a registered URL name and version.

Usage:

api_cls = mo_helper_kit.get_api_class_from_url_name(
    api_url_name="orders__create_order",
    version=1,
)

Parameters:

  • api_url_name (str): Named URL route (e.g., <app>__<api>).
  • version (int, default=1): Router version key.

Possible responses:

  • Returns API view class.
  • Raises LookupError when route name is not found.
  • Raises KeyError/TypeError for invalid version-router callback shape.

6. Get Api Class Attributes

Collect merged class attributes for API class resolved by URL name/version.

Usage:

attrs = mo_helper_kit.get_api_class_attributes(
    api_url_name="orders__create_order",
    version=1,
)

Parameters:

  • api_url_name (str): Named URL route.
  • version (int, default=1): Version key for router-based APIs.

Behavior:

  • Walks API class MRO and returns non-callable, non-private attributes.

Possible responses:

  • Returns merged attribute dictionary.

Example Usage

from django_mindoff.components.helper_kit import mo_helper_kit

api_cls = mo_helper_kit.get_api_class_from_url_name(
    api_url_name="orders__create_order",
    version=1,
)

api_attrs = mo_helper_kit.get_api_class_attributes(
    api_url_name="orders__create_order",
    version=1,
)

tb_text = mo_helper_kit.get_exact_traceback(skip=0)

Troubleshooting

  • API class introspection requires correctly named URL routes and valid version mappings.
  • Ensure versioned route wiring is in place in views.py and urls.py.