feat(src/djinit/utils): add get_full_app_config_path static method to compute full AppConfig pathAdd a static method get_full_app_config_path that builds the full path to an AppConfig class, handling nested app structures and module resolution. Improves reliability of AppConfig path calculation.
- New Features - Added `get_full_app_config_path` method to generate full AppConfig paths. - Enhancements - Centralized AppConfig path calculation logic using existing `calculate_app_module_path`. - Bug Fixes - None
This commit is contained in:
1 file changed
+12
@@ -250,6 +250,18 @@ class CommonUtils(BaseUtils):
|
|||||||
def calculate_app_module_path(app_name: str, nested: bool, nested_dir: str | None) -> str:
|
def calculate_app_module_path(app_name: str, nested: bool, nested_dir: str | None) -> str:
|
||||||
return f"{nested_dir}.{app_name}" if nested and nested_dir else app_name
|
return f"{nested_dir}.{app_name}" if nested and nested_dir else app_name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_full_app_config_path(app_name: str, nested: bool, nested_dir: str | None) -> str:
|
||||||
|
"""Get the full path to the AppConfig class.
|
||||||
|
Example: users -> users.apps.UsersConfig
|
||||||
|
Example: (nested) apps.users -> apps.users.apps.UsersConfig
|
||||||
|
"""
|
||||||
|
module_path = CommonUtils.calculate_app_module_path(app_name, nested, nested_dir)
|
||||||
|
# Handle cases where app_name might be a module path already
|
||||||
|
short_name = app_name.split(".")[-1]
|
||||||
|
config_name = short_name.title().replace("_", "") + "Config"
|
||||||
|
return f"{module_path}.apps.{config_name}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_django_project(directory: str = None) -> bool:
|
def is_django_project(directory: str = None) -> bool:
|
||||||
if directory is None:
|
if directory is None:
|
||||||
|
|||||||
Reference in new issue
Block a user