mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-30 07:46:13 +00:00
fix(module_generator): 修复模板文件名生成逻辑
将get_file_name参数从List[str]改为str,并修正模板匹配逻辑 确保文件名生成更准确且处理空文件名情况
This commit is contained in:
@@ -664,7 +664,7 @@ class GenTableService:
|
|||||||
# 修复:确保get_file_name返回的文件名不为空
|
# 修复:确保get_file_name返回的文件名不为空
|
||||||
output_files = []
|
output_files = []
|
||||||
for template in template_list:
|
for template in template_list:
|
||||||
file_name = Jinja2TemplateUtil.get_file_name([template], gen_table_schema)
|
file_name = Jinja2TemplateUtil.get_file_name(template, gen_table_schema)
|
||||||
if file_name: # 只有当文件名不为空时才添加到列表中
|
if file_name: # 只有当文件名不为空时才添加到列表中
|
||||||
output_files.append(file_name)
|
output_files.append(file_name)
|
||||||
|
|
||||||
@@ -683,7 +683,7 @@ class GenTableService:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
gen_path = gen_table.gen_path or ""
|
gen_path = gen_table.gen_path or ""
|
||||||
file_name = Jinja2TemplateUtil.get_file_name([template], gen_table)
|
file_name = Jinja2TemplateUtil.get_file_name(template, gen_table)
|
||||||
# 修复:检查文件名是否为空
|
# 修复:检查文件名是否为空
|
||||||
if not file_name:
|
if not file_name:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -269,12 +269,12 @@ class Jinja2TemplateUtil:
|
|||||||
return templates
|
return templates
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_file_name(cls, template: List[str], gen_table: GenTableOutSchema):
|
def get_file_name(cls, template: str, gen_table: GenTableOutSchema):
|
||||||
"""
|
"""
|
||||||
根据模板生成文件名。
|
根据模板生成文件名。
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
- template (List[str]): 模板列表。
|
- template (str): 模板路径字符串,例如 'python/controller.py.j2'。
|
||||||
- gen_table (GenTableOutSchema): 生成表的配置信息。
|
- gen_table (GenTableOutSchema): 生成表的配置信息。
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
@@ -287,23 +287,23 @@ class Jinja2TemplateUtil:
|
|||||||
vue_path = cls.FRONTEND_PROJECT_PATH
|
vue_path = cls.FRONTEND_PROJECT_PATH
|
||||||
python_path = f'{cls.BACKEND_PROJECT_PATH}/{package_name.replace(".", "/")}' if package_name else cls.BACKEND_PROJECT_PATH
|
python_path = f'{cls.BACKEND_PROJECT_PATH}/{package_name.replace(".", "/")}' if package_name else cls.BACKEND_PROJECT_PATH
|
||||||
|
|
||||||
if 'controller.py.j2' in template:
|
if template.endswith('controller.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/controller.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/controller.py'
|
||||||
elif 'crud.py.j2' in template:
|
elif template.endswith('crud.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/crud.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/crud.py'
|
||||||
elif 'model.py.j2' in template:
|
elif template.endswith('model.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/model.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/model.py'
|
||||||
elif 'service.py.j2' in template:
|
elif template.endswith('service.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/service.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/service.py'
|
||||||
elif 'param.py.j2' in template:
|
elif template.endswith('param.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/param.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/param.py'
|
||||||
elif 'schema.py.j2' in template:
|
elif template.endswith('schema.py.j2'):
|
||||||
return f'{python_path}/app/api/v1/{module_name}/{business_name}/schema.py'
|
return f'{python_path}/app/api/v1/{module_name}/{business_name}/schema.py'
|
||||||
elif 'sql.j2' in template:
|
elif template.endswith('sql.sql.j2'):
|
||||||
return f'{cls.BACKEND_PROJECT_PATH}/sql/{module_name}/{business_name}_menu.sql'
|
return f'{cls.BACKEND_PROJECT_PATH}/sql/{module_name}/{business_name}_menu.sql'
|
||||||
elif 'api.ts.j2' in template:
|
elif template.endswith('api.ts.j2'):
|
||||||
return f'{vue_path}/src/api/{module_name}/{business_name}.ts'
|
return f'{vue_path}/src/api/{module_name}/{business_name}.ts'
|
||||||
elif 'index.vue.j2' in template or 'index-tree.vue.j2' in template:
|
elif template.endswith('index.vue.j2') or template.endswith('index-tree.vue.j2'):
|
||||||
return f'{vue_path}/src/views/{module_name}/{business_name}/index.vue'
|
return f'{vue_path}/src/views/{module_name}/{business_name}/index.vue'
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user