spire_startapp_pkg
django_spire.core.management.commands.spire_startapp_pkg
__all__ = ['AppConfig', 'AppConfigFactory', 'AppGenerator', 'AppRegistry', 'AppValidator', 'FileSystem', 'PathConfig', 'PathResolver', 'PermissionInheritanceHandler', 'Reporter', 'TemplateBuilder', 'TemplateEngine', 'TemplateGenerator', 'TemplateProcessor', 'UserInputCollector', 'generate_replacement_map']
module-attribute
TemplateBuilder
Builds and displays tree structures for app and template creation.
This class generates visual representations of the file structure that will be created for new apps and their associated templates.
Initializes the TemplateBuilder with a reporter for output.
Parameters:
-
reporter(Reporter) –Reporter instance for displaying output to the user.
Source code in django_spire/core/management/commands/spire_startapp_pkg/builder.py
build_app_tree_structure
Displays a tree structure of the app files that will be created.
This method shows the user what Python files, directories, and modules will be generated for the new Django app before creation.
Parameters:
-
base(Path) –Base directory where the app will be created.
-
components(list[str]) –List of app path components (e.g., ['app', 'human_resource', 'employee']).
-
registry(list[str]) –List of already registered apps in the Django project.
-
template(Path) –Path to the app template directory.
Source code in django_spire/core/management/commands/spire_startapp_pkg/builder.py
build_html_tree_structure
Displays a tree structure of the HTML template files that will be created.
This method shows the user what HTML templates, cards, forms, and pages will be generated for the new Django app before creation.
Parameters:
-
base(Path) –Base directory where templates will be created.
-
components(list[str]) –List of app path components.
-
registry(list[str]) –List of already registered apps in the Django project.
-
template(Path) –Path to the HTML template directory.
Source code in django_spire/core/management/commands/spire_startapp_pkg/builder.py
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
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
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
FileSystem
Implementation of file system operations for app generation.
This class provides concrete implementations of file system operations needed to create directories, copy templates, and manage files.
copy_tree
Copies an entire directory tree from source to destination.
Ignores Python cache directories and compiled files during the copy.
Parameters:
-
src(Path) –Source directory path to copy from.
-
dst(Path) –Destination directory path to copy to.
Source code in django_spire/core/management/commands/spire_startapp_pkg/filesystem.py
create_directory
Creates a directory and all necessary parent directories.
Parameters:
-
path(Path) –Directory path to create.
Source code in django_spire/core/management/commands/spire_startapp_pkg/filesystem.py
exists
has_content
iterate_files
Recursively finds all files matching a pattern in a directory.
Parameters:
-
path(Path) –Directory path to search within.
-
pattern(str) –Glob pattern to match files (e.g., '.py', '.template').
Returns:
Source code in django_spire/core/management/commands/spire_startapp_pkg/filesystem.py
read_file
rename
write_file
Writes content to a text file.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/filesystem.py
AppGenerator
Generates Django app structures from templates.
This class handles the creation of new Django apps by copying template files and processing them with user-provided configuration.
Initializes the AppGenerator with required dependencies.
Parameters:
-
filesystem(FileSystem) –File system for file operations.
-
processor(TemplateProcessor) –Template processor for replacing placeholders.
-
reporter(Reporter) –Reporter for user feedback and output.
-
path_config(PathConfig) –Configuration containing template paths.
Source code in django_spire/core/management/commands/spire_startapp_pkg/generator.py
generate
Generates a new Django app from templates.
Creates the app directory, copies template files, and processes them with user configuration. Skips generation if the app already exists.
Parameters:
-
config(AppConfig) –Configuration for the app to generate.
Source code in django_spire/core/management/commands/spire_startapp_pkg/generator.py
TemplateGenerator
Generates HTML templates for Django apps.
This class handles the creation of HTML template files including forms, cards, pages, and items for new Django apps.
Initializes the TemplateGenerator with required dependencies.
Parameters:
-
filesystem(FileSystem) –File system for file operations.
-
processor(TemplateProcessor) –Template processor for replacing placeholders.
-
reporter(Reporter) –Reporter for user feedback and output.
-
path_config(PathConfig) –Configuration containing template paths.
Source code in django_spire/core/management/commands/spire_startapp_pkg/generator.py
generate
Generates HTML templates for a new Django app.
Creates the template directory, copies template files, and processes them with user configuration. Skips generation if templates already exist.
Parameters:
-
config(AppConfig) –Configuration for the templates to generate.
Source code in django_spire/core/management/commands/spire_startapp_pkg/generator.py
PermissionInheritanceHandler
Handles permission inheritance configuration for nested Django apps.
This class manages the interactive collection of permission inheritance settings when creating child apps that may inherit permissions from parent apps.
Initializes the handler with a reporter for user interaction.
Parameters:
-
reporter(Reporter) –Reporter instance for displaying prompts and messages.
Source code in django_spire/core/management/commands/spire_startapp_pkg/permissions.py
reporter = reporter
instance-attribute
collect_inheritance_data
Collects permission inheritance configuration from the user.
Prompts the user to determine if the new app should inherit permissions from its parent app, and if so, collects the necessary parent model information.
Parameters:
Returns:
Source code in django_spire/core/management/commands/spire_startapp_pkg/permissions.py
TemplateEngine
Renders template strings with variable replacements.
This class uses Python's string.Template to safely substitute placeholders in template files with actual values.
render
Renders a template string by replacing placeholders with values.
Parameters:
-
text(str) –Template string containing ${variable} placeholders.
-
replacements(dict[str, str]) –Dictionary mapping placeholder names to their values.
Returns:
-
str–Rendered string with all placeholders replaced.
Source code in django_spire/core/management/commands/spire_startapp_pkg/processor.py
TemplateProcessor
Processes template files for Django app generation.
This class handles the replacement of placeholders in template files and manages file renaming based on user configuration.
Initializes the processor with an engine and file system.
Parameters:
-
engine(TemplateEngine) –Template engine for rendering strings.
-
filesystem(FileSystem) –File system for file operations.
Source code in django_spire/core/management/commands/spire_startapp_pkg/processor.py
process_app_templates
Processes all template files in an app directory.
Replaces placeholders in .template files, renames them, and updates content in .py files based on user inputs.
Parameters:
-
directory(Path) –Root directory containing template files.
-
components(list[str]) –List of app path components.
-
user_inputs(dict[str, str] | None, default:None) –Optional dictionary of user-provided configuration values.
Source code in django_spire/core/management/commands/spire_startapp_pkg/processor.py
process_html_templates
Processes all HTML template files in a directory.
Replaces placeholders in .template files and renames them to remove the .template extension.
Parameters:
-
directory(Path) –Root directory containing HTML template files.
-
components(list[str]) –List of app path components.
-
user_inputs(dict[str, str] | None, default:None) –Optional dictionary of user-provided configuration values.
Source code in django_spire/core/management/commands/spire_startapp_pkg/processor.py
AppRegistry
Manages Django app registration information.
This class provides methods to query which apps are installed in the Django project and validate app component hierarchies.
get_installed_apps
Gets a list of all installed app names.
Returns:
Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
get_missing_components
Identifies which app components in a path are not registered.
For a path like ['app', 'human_resource', 'employee'], this checks if 'app', 'app.human_resource', and 'app.human_resource.employee' are registered, and returns those that are missing.
Parameters:
Returns:
Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
get_valid_root_apps
Gets all valid root app names from INSTALLED_APPS.
Returns root-level apps (first component before a dot) that can be used as parent apps, excluding Django's built-in apps.
Returns:
Source code in django_spire/core/management/commands/spire_startapp_pkg/registry.py
Reporter
Handles user interaction and console output for the app creation command.
This class manages all console output including status messages, tree structures, confirmations, and styled text for the app creation process.
Initializes the reporter with a Django management command.
Parameters:
-
command(BaseCommand) –Django BaseCommand instance for accessing stdout and styling.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
ICON_FILE = '📄'
class-attribute
instance-attribute
ICON_FOLDER_CLOSED = '📁'
class-attribute
instance-attribute
ICON_FOLDER_OPEN = '📂'
class-attribute
instance-attribute
INDENTATION = ' '
class-attribute
instance-attribute
command = command
instance-attribute
style_error = command.style.ERROR
instance-attribute
style_notice = command.style.NOTICE
instance-attribute
style_success = command.style.SUCCESS
instance-attribute
style_warning = command.style.WARNING
instance-attribute
format_app_item
format_html_item
Formats an HTML template file or directory name for display.
Applies variable replacements and removes .template extensions.
Parameters:
-
item(Path) –Path to the item to format.
-
replacement(dict[str, str]) –Dictionary of placeholder replacements.
Returns:
-
str–Formatted item name with placeholders replaced.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
prompt_confirmation
report_app_creation_success
Reports successful creation of an app.
Parameters:
-
app(str) –Name of the app that was created.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_app_exists
Reports that an app already exists at the destination.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_creating_app
Reports that an app is being created.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_creating_templates
Reports that templates are being created for an app.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_installed_apps_suggestion
Suggests which app to add to INSTALLED_APPS in settings.py.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_missing_components
Reports which app components are not yet registered.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_templates_creation_success
Reports successful creation of templates for an app.
Parameters:
-
app(str) –Name of the app whose templates were created.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_templates_exist
Reports that templates already exist for an app.
Parameters:
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
report_tree_structure
Displays a tree structure of files and directories that will be created.
Shows a hierarchical view of the app structure with appropriate icons and formatting for files and directories.
Parameters:
-
title(str) –Title to display above the tree structure.
-
base(Path) –Base directory path.
-
components(list[str]) –List of app path components.
-
registry(list[str]) –List of registered apps.
-
template(Path) –Path to template directory.
-
formatter(Callable[[Path], str]) –Function to format item names for display.
-
transformation(Callable[[int, str], str] | None, default:None) –Optional function to transform component names.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
transform_app_component
Transforms an app component name (default: no transformation).
Parameters:
Returns:
-
str–Transformed component name.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
transform_html_component
Transforms an HTML component name (replaces first component with 'templates').
Parameters:
Returns:
-
str–Transformed component name.
Source code in django_spire/core/management/commands/spire_startapp_pkg/reporter.py
PathResolver
Resolves file system paths for app and template creation.
This class determines where new Django apps and their templates should be created based on project structure and configuration.
Initializes the path resolver with base directories.
Parameters:
-
base_dir(Path | None, default:None) –Optional base directory for the Django project (defaults to settings.BASE_DIR).
-
template_dir(Path | None, default:None) –Optional template directory (defaults to base_dir/templates).
Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
get_app_destination
Gets the destination path for a new app based on its components.
For components ['app', 'human_resource', 'employee'], returns Path('base_dir/app/human_resource/employee').
Parameters:
Returns:
-
Path–Full path where the app should be created.
Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
get_base_dir
get_template_destination
Gets the destination path for templates based on app components.
Excludes the first component (root app) from the path. For components ['app', 'human_resource', 'employee'], returns Path('templates/human_resource/employee').
Parameters:
Returns:
-
Path–Full path where templates should be created.
Source code in django_spire/core/management/commands/spire_startapp_pkg/resolver.py
get_template_dir
Gets the project's template directory.
Returns:
-
Path–Template directory path for the Django project.
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
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:
Source code in django_spire/core/management/commands/spire_startapp_pkg/user_input.py
AppValidator
Validates Django app paths and configurations.
This class performs validation checks to ensure app paths are properly formatted, don't conflict with existing apps, and use valid root apps.
Initializes the validator with required dependencies.
Parameters:
-
reporter(Reporter) –Reporter for displaying error messages.
-
registry(AppRegistry) –Registry for checking installed apps.
-
path_resolver(PathResolver) –Path resolver for determining file locations.
-
filesystem(FileSystem) –File system for checking file existence.
Source code in django_spire/core/management/commands/spire_startapp_pkg/validator.py
validate_app_format
Validates that an app path uses dot notation.
Parameters:
-
app_path(str) –App path to validate.
Raises:
-
CommandError–If the app path doesn't contain dots.
Source code in django_spire/core/management/commands/spire_startapp_pkg/validator.py
validate_app_path
Validates that an app path doesn't already exist.
Parameters:
Raises:
-
CommandError–If an app already exists at the destination path.
Source code in django_spire/core/management/commands/spire_startapp_pkg/validator.py
validate_root_app
Validates that the root app component is registered in Django.
Parameters:
Raises:
-
CommandError–If the root app is not a valid registered app.
Source code in django_spire/core/management/commands/spire_startapp_pkg/validator.py
generate_replacement_map
Generate replacement mappings for template processing.