feat: inject base.py accurately into specific project structures
This commit is contained in:
3 files changed
+37
-1
No files matched your search
@@ -285,6 +285,14 @@ class FileCreator(BaseService):
|
||||
core_subfolders = ["utils", "mixins", "middleware"]
|
||||
self._create_subdirectories_with_init(core_dir, core_subfolders, "apps/core/")
|
||||
|
||||
# Inject base model
|
||||
CommonUtils.create_file_from_template(
|
||||
os.path.join(core_dir, "base.py"),
|
||||
"components/base.py-tpl",
|
||||
{},
|
||||
"Created apps/core/base.py",
|
||||
)
|
||||
|
||||
# Create api directory structure
|
||||
api_dir = os.path.join(self.project_root, "api")
|
||||
CommonUtils.create_directory_with_init(api_dir, "Created api/__init__.py")
|
||||
@@ -352,6 +360,14 @@ class FileCreator(BaseService):
|
||||
components = ["admin", "models", "serializers", "tests", "urls", "views"]
|
||||
self._create_subdirectories_with_init(apps_dir, components, "apps/")
|
||||
|
||||
# Inject base model
|
||||
CommonUtils.create_file_from_template(
|
||||
os.path.join(apps_dir, "models", "base.py"),
|
||||
"components/base.py-tpl",
|
||||
{},
|
||||
"Created apps/models/base.py",
|
||||
)
|
||||
|
||||
# Create 'api' directory with v1
|
||||
api_dir = os.path.join(apps_dir, "api")
|
||||
CommonUtils.create_directory_with_init(api_dir, "Created apps/api/__init__.py")
|
||||
@@ -401,6 +417,14 @@ class FileCreator(BaseService):
|
||||
components = ["admin", "api", "models", "tests"]
|
||||
self._create_subdirectories_with_init(project_dir, components, f"{self.module_name}/")
|
||||
|
||||
# Inject base model
|
||||
CommonUtils.create_file_from_template(
|
||||
os.path.join(project_dir, "models", "base.py"),
|
||||
"components/base.py-tpl",
|
||||
{},
|
||||
f"Created {self.module_name}/models/base.py",
|
||||
)
|
||||
|
||||
# Create README files for guidance
|
||||
CommonUtils.create_file_from_template(
|
||||
os.path.join(project_dir, "api", "README.md"),
|
||||
@@ -510,3 +534,15 @@ class FileCreator(BaseService):
|
||||
CommonUtils.create_file_with_content(
|
||||
filepath, json.dumps(config, indent=4), "Created .djinit configuration file"
|
||||
)
|
||||
|
||||
def create_standard_shared(self) -> None:
|
||||
"""Create shared directory and inject base model for standard structure."""
|
||||
shared_dir = os.path.join(self.project_root, "shared")
|
||||
CommonUtils.create_directory_with_init(shared_dir, "Created shared/__init__.py")
|
||||
|
||||
CommonUtils.create_file_from_template(
|
||||
os.path.join(shared_dir, "base.py"),
|
||||
"components/base.py-tpl",
|
||||
{},
|
||||
"Created shared/base.py",
|
||||
)
|
||||
@@ -68,6 +68,7 @@ class SetupCreator:
|
||||
else:
|
||||
steps.append(("Creating Django apps", self.project_creator.create_apps))
|
||||
steps.append(("Creating project URLs", self.file_creator.create_project_urls))
|
||||
steps.append(("Creating shared module", self.file_creator.create_standard_shared))
|
||||
|
||||
steps.extend(
|
||||
[
|
||||
|
||||
@@ -71,7 +71,6 @@ class DjangoHelper:
|
||||
("urls.py", "config/urls.py-tpl", urls_context),
|
||||
("wsgi.py", "config/wsgi.py-tpl", {"project_name": project_name}),
|
||||
("asgi.py", "config/asgi.py-tpl", {"project_name": project_name}),
|
||||
("base.py", "components/base.py-tpl", {}),
|
||||
]
|
||||
CommonUtils.create_files_from_templates(project_config_dir, project_files, f"{project_name}/")
|
||||
|
||||
|
||||
Reference in new issue
Block a user