Skip to content

manager

django_spire.core.management.commands.spire_startapp_pkg.manager

BaseTemplateManager

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def __init__(self, base: Path, template: Path):
    self.base = base
    self.template = template

base = base instance-attribute

template = template instance-attribute

AppManager

Bases: BaseTemplateManager

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def __init__(self, base: Path, template: Path):
    self.base = base
    self.template = template

get_valid_root_apps

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def get_valid_root_apps(self) -> set[str]:
    return {
        app.split('.')[0]
        for app in settings.INSTALLED_APPS
        if '.' in app and app.split('.')[0] != 'django'
    }

is_valid_root_apps

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def is_valid_root_apps(self, components: list[str]) -> None:
    valid = self.get_valid_root_apps()
    root = components[0]

    if root not in valid:
        message = (
            f'Invalid root app "{root}". '
            f'The following are valid root apps: {", ".join(valid)}.'
        )

        raise CommandError(message)

validate_app_name_format

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def validate_app_name_format(self, app: str) -> None:
    if '.' not in app:
        message = (
            'Invalid app name format. '
            'The app path must use dot notation (e.g., "parent.child").'
        )

        raise CommandError(message)

parse_app_name

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def parse_app_name(self, app: str) -> list[str]:
    return app.split('.') if '.' in app else [app]

get_missing_components

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def get_missing_components(
    self,
    components: list[str],
    registry: list[str]
) -> list[str]:
    missing = []
    total = len(components)

    for i in range(total):
        component = '.'.join(components[: i + 1])

        if component not in registry and i > 0:
            missing.append(component)

    return missing

create_custom_app

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def create_custom_app(
    self,
    app: str,
    processor: AppTemplateProcessor,
    reporter: Reporter
) -> None:
    components = app.split('.')

    message = (
        f'Template directory "{self.template}" is missing. '
        'Ensure you have a valid app template.'
    )

    self._create_entity(
        app,
        components,
        processor.replace_app_name,
        reporter,
        message
    )

HTMLTemplateManager

Bases: BaseTemplateManager

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def __init__(self, base: Path, template: Path):
    self.base = base
    self.template = template

create_custom_templates

Source code in django_spire/core/management/commands/spire_startapp_pkg/manager.py
def create_custom_templates(
    self,
    app: str,
    processor: HTMLTemplateProcessor,
    reporter: Reporter
) -> None:
    components = app.split('.')[1:]

    message = (
        f'Template directory "{self.template}" is missing. '
        'Ensure you have a valid templates template.'
    )

    self._create_entity(
        app,
        components,
        processor.replace_template_names,
        reporter,
        message
    )