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:
1. Pascal To Snake¶
Convert PascalCase/CamelCase names to snake_case.
Usage:
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:
Parameters:
app_name(str): App label (last segment of installed app path).
Possible responses:
- Returns full import path from
INSTALLED_APPS. - Raises
ValueErrorwhen app cannot be resolved.
3. Get Current App Name¶
Resolve current Django app label from caller file path.
Usage:
Possible responses:
- Returns app label as
str. - Raises
ValueErrorwhen frame path cannot be mapped to a Django app.
4. Get Exact Traceback¶
Build filtered traceback text for project-owned frames.
Usage:
Parameters:
skip(int | None, default=None): Frame index in filtered project stack.Nonereturns 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
LookupErrorwhen route name is not found. - Raises
KeyError/TypeErrorfor invalid version-router callback shape.
6. Get Api Class Attributes¶
Collect merged class attributes for API class resolved by URL name/version.
Usage:
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.pyandurls.py.