Skip to content

user_input

django_spire.core.management.commands.spire_startapp_pkg.user_input

UserInputCollector

Collects user input for Django app creation through an interactive wizard.

This class guides users through a step-by-step process to gather all necessary configuration for creating a new Django app.

Initializes the collector with a reporter and validator.

Parameters:

  • reporter (Reporter) –

    Reporter instance for displaying prompts and messages.

  • validator (AppValidator) –

    Validator for checking user input validity.

Source code in django_spire/core/management/commands/spire_startapp_pkg/user_input.py
def __init__(self, reporter: Reporter, validator: AppValidator):
    """
    Initializes the collector with a reporter and validator.

    :param reporter: Reporter instance for displaying prompts and messages.
    :param validator: Validator for checking user input validity.
    """

    self.reporter = reporter
    self.validator = validator

reporter = reporter instance-attribute

validator = validator instance-attribute

collect_all_inputs

Collects all required user inputs for app creation.

Guides the user through an 8-step wizard to gather app path, names, labels, and configuration options.

Returns:

  • dict[str, str]

    Dictionary containing all collected user inputs.

Source code in django_spire/core/management/commands/spire_startapp_pkg/user_input.py
def collect_all_inputs(self) -> dict[str, str]:
    """
    Collects all required user inputs for app creation.

    Guides the user through an 8-step wizard to gather app path, names,
    labels, and configuration options.

    :return: Dictionary containing all collected user inputs.
    """

    self.reporter.write('\n[App Creation Wizard]\n\n', self.reporter.style_success)

    app_path = self._collect_app_path()
    components = app_path.split('.')

    app_name = self._collect_app_name(components)
    app_label = self._collect_app_label(components, app_name)
    model_name = self._collect_model_name(app_name)
    model_name_plural = self._collect_model_name_plural(model_name)
    db_table_name = self._collect_db_table_name(components, app_name)  # Changed from app_label to components, app_name
    model_permission_path = self._collect_model_permission_path(app_path, model_name)

    permission_data = self._collect_permission_inheritance(components)

    verbose_name, verbose_name_plural = self._derive_verbose_names(model_name, model_name_plural)

    return {
        'app_path': app_path,
        'app_name': app_name,
        'model_name': model_name,
        'model_name_plural': model_name_plural,
        'app_label': app_label,
        'db_table_name': db_table_name,
        'model_permission_path': model_permission_path,
        'verbose_name': verbose_name,
        'verbose_name_plural': verbose_name_plural,
        **permission_data,
    }