feat(djinit/utils): Use .py-tpl templates for generated Django files
This change updates all template references from *.j2 to *.py-tpl to align with the new file naming convention and adds the required context for URL generation. New Features - Updated template paths to *.py-tpl for init, manage.py, settings, and component files - Added `url_type` context for URL generation templates Enhancements - Modified `create_init_file` to use `init.py-tpl` template - Updated all `create_file_from_template` calls to reference `.py-tpl` templates - Adjusted context for URL templates to include project‑specific data - Switched component URL template to `config/urls.py-tpl` Bug Fixes - None
This commit is contained in:
2 files changed
+17
-17
No files matched your search
@@ -51,7 +51,7 @@ def create_file_from_template(
|
|||||||
|
|
||||||
def create_init_file(directory: str, success_message: str) -> None:
|
def create_init_file(directory: str, success_message: str) -> None:
|
||||||
init_path = os.path.join(directory, "__init__.py")
|
init_path = os.path.join(directory, "__init__.py")
|
||||||
create_file_from_template(init_path, "project/init.j2", {}, success_message, should_format=False)
|
create_file_from_template(init_path, "project/init.py-tpl", {}, success_message, should_format=False)
|
||||||
|
|
||||||
|
|
||||||
def create_directory_with_init(dir_path: str, message: str) -> None:
|
def create_directory_with_init(dir_path: str, message: str) -> None:
|
||||||
|
|||||||
+16
-16
@@ -25,7 +25,7 @@ class DjangoHelper:
|
|||||||
|
|
||||||
manage_py_path = os.path.join(directory, "manage.py")
|
manage_py_path = os.path.join(directory, "manage.py")
|
||||||
create_file_from_template(
|
create_file_from_template(
|
||||||
manage_py_path, "project/manage_py.j2", {"project_name": project_name}, "Created manage.py"
|
manage_py_path, "project/manage.py-tpl", {"project_name": project_name}, "Created manage.py"
|
||||||
)
|
)
|
||||||
os.chmod(manage_py_path, 0o755)
|
os.chmod(manage_py_path, 0o755)
|
||||||
|
|
||||||
@@ -40,17 +40,17 @@ class DjangoHelper:
|
|||||||
|
|
||||||
base_context = {"project_name": project_name, "app_names": []}
|
base_context = {"project_name": project_name, "app_names": []}
|
||||||
settings_files = [
|
settings_files = [
|
||||||
("base.py", "config/settings/base.j2", base_context),
|
("base.py", "config/settings/base.py-tpl", base_context),
|
||||||
("development.py", "config/settings/development.j2", {}),
|
("development.py", "config/settings/development.py-tpl", {}),
|
||||||
("production.py", "config/settings/production.j2", {}),
|
("production.py", "config/settings/production.py-tpl", {}),
|
||||||
]
|
]
|
||||||
create_files_from_templates(settings_dir, settings_files, f"{project_name}/settings/")
|
create_files_from_templates(settings_dir, settings_files, f"{project_name}/settings/")
|
||||||
|
|
||||||
urls_context = {"project_name": project_name, "django_version": DjangoHelper.DJANGO_VERSION}
|
urls_context = {"url_type": "project", "project_name": project_name, "django_version": DjangoHelper.DJANGO_VERSION}
|
||||||
project_files = [
|
project_files = [
|
||||||
("urls.py", "config/urls/base.j2", urls_context),
|
("urls.py", "config/urls.py-tpl", urls_context),
|
||||||
("wsgi.py", "config/wsgi.j2", {}),
|
("wsgi.py", "config/wsgi.py-tpl", {}),
|
||||||
("asgi.py", "config/asgi.j2", {}),
|
("asgi.py", "config/asgi.py-tpl", {}),
|
||||||
]
|
]
|
||||||
create_files_from_templates(project_config_dir, project_files, f"{project_name}/")
|
create_files_from_templates(project_config_dir, project_files, f"{project_name}/")
|
||||||
|
|
||||||
@@ -70,14 +70,14 @@ class DjangoHelper:
|
|||||||
create_init_file(app_dir, f"Created {app_name}/__init__.py")
|
create_init_file(app_dir, f"Created {app_name}/__init__.py")
|
||||||
|
|
||||||
app_files = [
|
app_files = [
|
||||||
("apps.py", "components/apps.j2", context),
|
("apps.py", "components/apps.py-tpl", context),
|
||||||
("models.py", "components/models.j2", context),
|
("models.py", "components/models.py-tpl", context),
|
||||||
("views.py", "components/views.j2", context),
|
("views.py", "components/views.py-tpl", context),
|
||||||
("admin.py", "components/admin.j2", context),
|
("admin.py", "components/admin.py-tpl", context),
|
||||||
("urls.py", "components/urls.j2", context),
|
("urls.py", "config/urls.py-tpl", {"url_type": "component"}),
|
||||||
("serializers.py", "components/serializers.j2", context),
|
("serializers.py", "components/serializers.py-tpl", context),
|
||||||
("routes.py", "components/routes.j2", context),
|
("routes.py", "components/routes.py-tpl", context),
|
||||||
("tests.py", "components/tests.j2", context),
|
("tests.py", "components/tests.py-tpl", context),
|
||||||
]
|
]
|
||||||
|
|
||||||
create_files_from_templates(app_dir, app_files, f"{app_name}/")
|
create_files_from_templates(app_dir, app_files, f"{app_name}/")
|
||||||
|
|||||||
Reference in new issue
Block a user