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"]
|
core_subfolders = ["utils", "mixins", "middleware"]
|
||||||
self._create_subdirectories_with_init(core_dir, core_subfolders, "apps/core/")
|
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
|
# Create api directory structure
|
||||||
api_dir = os.path.join(self.project_root, "api")
|
api_dir = os.path.join(self.project_root, "api")
|
||||||
CommonUtils.create_directory_with_init(api_dir, "Created api/__init__.py")
|
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"]
|
components = ["admin", "models", "serializers", "tests", "urls", "views"]
|
||||||
self._create_subdirectories_with_init(apps_dir, components, "apps/")
|
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
|
# Create 'api' directory with v1
|
||||||
api_dir = os.path.join(apps_dir, "api")
|
api_dir = os.path.join(apps_dir, "api")
|
||||||
CommonUtils.create_directory_with_init(api_dir, "Created apps/api/__init__.py")
|
CommonUtils.create_directory_with_init(api_dir, "Created apps/api/__init__.py")
|
||||||
@@ -401,6 +417,14 @@ class FileCreator(BaseService):
|
|||||||
components = ["admin", "api", "models", "tests"]
|
components = ["admin", "api", "models", "tests"]
|
||||||
self._create_subdirectories_with_init(project_dir, components, f"{self.module_name}/")
|
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
|
# Create README files for guidance
|
||||||
CommonUtils.create_file_from_template(
|
CommonUtils.create_file_from_template(
|
||||||
os.path.join(project_dir, "api", "README.md"),
|
os.path.join(project_dir, "api", "README.md"),
|
||||||
@@ -510,3 +534,15 @@ class FileCreator(BaseService):
|
|||||||
CommonUtils.create_file_with_content(
|
CommonUtils.create_file_with_content(
|
||||||
filepath, json.dumps(config, indent=4), "Created .djinit configuration file"
|
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:
|
else:
|
||||||
steps.append(("Creating Django apps", self.project_creator.create_apps))
|
steps.append(("Creating Django apps", self.project_creator.create_apps))
|
||||||
steps.append(("Creating project URLs", self.file_creator.create_project_urls))
|
steps.append(("Creating project URLs", self.file_creator.create_project_urls))
|
||||||
|
steps.append(("Creating shared module", self.file_creator.create_standard_shared))
|
||||||
|
|
||||||
steps.extend(
|
steps.extend(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ class DjangoHelper:
|
|||||||
("urls.py", "config/urls.py-tpl", urls_context),
|
("urls.py", "config/urls.py-tpl", urls_context),
|
||||||
("wsgi.py", "config/wsgi.py-tpl", {"project_name": project_name}),
|
("wsgi.py", "config/wsgi.py-tpl", {"project_name": project_name}),
|
||||||
("asgi.py", "config/asgi.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}/")
|
CommonUtils.create_files_from_templates(project_config_dir, project_files, f"{project_name}/")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user