Skip to content

config

django_spire.core.management.commands.spire_startapp_pkg.config

PathConfig dataclass

Configuration for template directory paths.

This class holds the paths to the app and HTML template directories used for generating new Django apps.

app_template instance-attribute

html_template instance-attribute

default classmethod

Creates a default PathConfig with standard template locations.

Returns:

  • PathConfig

    PathConfig instance with paths to default app and HTML templates.

Source code in django_spire/core/management/commands/spire_startapp_pkg/config.py
@classmethod
def default(cls) -> PathConfig:
    """
    Creates a default PathConfig with standard template locations.

    :return: PathConfig instance with paths to default app and HTML templates.
    """

    base = Path(django_spire.__file__).parent

    return cls(
        app_template=base / 'core/management/commands/spire_startapp_pkg/template/app',
        html_template=base / 'core/management/commands/spire_startapp_pkg/template/templates'
    )

AppConfig dataclass

Configuration for a new Django app being created.

This class contains all the information needed to generate a new app, including its name, path, components, destinations, and user-provided inputs.

app_name instance-attribute

app_path instance-attribute

components instance-attribute

destination instance-attribute

template_destination instance-attribute

user_inputs instance-attribute

app_label property

Gets the Django app label.

Returns:

  • str

    The app label, either from user input or derived from app name.

model_name property

Gets the model class name.

Returns:

  • str

    The model name, either from user input or TitleCase version of app name.

AppConfigFactory

Factory class for creating AppConfig instances.

This class handles the creation of AppConfig objects by resolving paths and processing user inputs.

Initializes the factory with a path resolver.

Parameters:

  • path_resolver (PathResolver) –

    Path resolver for determining file system locations.

Source code in django_spire/core/management/commands/spire_startapp_pkg/config.py
def __init__(self, path_resolver: PathResolver):
    """
    Initializes the factory with a path resolver.

    :param path_resolver: Path resolver for determining file system locations.
    """

    self._path_resolver = path_resolver

create_config

Creates an AppConfig from an app path and user inputs.

Parameters:

  • app_path (str) –

    Dot-separated app path (e.g., 'app.human_resource.employee').

  • user_inputs (dict[str, str]) –

    Dictionary of user-provided configuration values.

Returns:

  • AppConfig

    Configured AppConfig instance ready for app generation.

Source code in django_spire/core/management/commands/spire_startapp_pkg/config.py
def create_config(self, app_path: str, user_inputs: dict[str, str]) -> AppConfig:
    """
    Creates an AppConfig from an app path and user inputs.

    :param app_path: Dot-separated app path (e.g., 'app.human_resource.employee').
    :param user_inputs: Dictionary of user-provided configuration values.
    :return: Configured AppConfig instance ready for app generation.
    """

    components = app_path.split('.')
    app_name = user_inputs.get('app_name', components[-1])

    return AppConfig(
        app_name=app_name,
        app_path=app_path,
        components=components,
        destination=self._path_resolver.get_app_destination(components),
        template_destination=self._path_resolver.get_template_destination(components),
        user_inputs=user_inputs
    )