Skip to content

Commit d072961

Browse files
E7EE477C11C98D403F318118733EAA5CE7EE477C11C98D403F318118733EAA5C
authored andcommitted
fix: 修复在 Windows 下执行 python manage.py gen_all 命令出现编码错误的bug mtianyan#2
1 parent 1b34a83 commit d072961

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

tyadmin_api_cli/deal_antd_pages.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def gen_antd_pages(project_name_settings, user_label_list, focus_model=None, tem
768768
opera = opera.replace("$时间处理占位$", "".join(date_row_list))
769769
columns.append(opera)
770770
dest_path = f'{os.path.dirname(__file__)}/antd_page_templates/{template_type}'
771-
with open(f'{dest_path}/index.jsx') as fr:
771+
with open(f'{dest_path}/index.jsx', encoding='utf-8') as fr:
772772

773773
content = fr.read()
774774
if fileds_num > 8:
@@ -872,7 +872,7 @@ def gen_antd_pages(project_name_settings, user_label_list, focus_model=None, tem
872872
new_content = new_content.replace("$Password占位$", '')
873873
new_content = new_content.replace("$更新密码方法占位$", '')
874874
new_content = new_content.replace("$Password更新Form$", '')
875-
with open(f'{dest_path}/service.js') as fr:
875+
with open(f'{dest_path}/service.js', encoding='utf-8') as fr:
876876
content = fr.read()
877877

878878
new_services = content.replace("$占位path$", get_lower_case_name(model_name))
@@ -889,21 +889,21 @@ def gen_antd_pages(project_name_settings, user_label_list, focus_model=None, tem
889889
}""")
890890
else:
891891
new_services = new_services.replace("$更新密码service占位$", "")
892-
with open(f'{dest_path}/components/CreateForm.jsx') as fr:
892+
with open(f'{dest_path}/components/CreateForm.jsx', encoding='utf-8') as fr:
893893
create_form = fr.read()
894894
create_form = create_form.replace("$占位模型显示名$", str(model_ver_name))
895895
if fileds_num > 8:
896896
create_form = create_form.replace("$宽度占位$", 'width={1200}')
897897
else:
898898
create_form = create_form.replace("$宽度占位$", "width={800}")
899-
with open(f'{dest_path}/components/UpdateForm.jsx') as fr:
899+
with open(f'{dest_path}/components/UpdateForm.jsx', encoding='utf-8') as fr:
900900
update_form = fr.read()
901901
update_form = update_form.replace("$占位模型显示名$", str(model_ver_name))
902902
if fileds_num > 8:
903903
update_form = update_form.replace("$宽度占位$", 'width={1200}')
904904
else:
905905
update_form = update_form.replace("$宽度占位$", "width={800}")
906-
with open(f'{dest_path}/components/UpdatePasswordForm.jsx') as fr:
906+
with open(f'{dest_path}/components/UpdatePasswordForm.jsx', encoding='utf-8') as fr:
907907
change_password_form = fr.read()
908908

909909
target_path = f'{settings.BASE_DIR}/tyadmin/src/pages/AutoGenPage'
@@ -913,16 +913,16 @@ def gen_antd_pages(project_name_settings, user_label_list, focus_model=None, tem
913913
cur_path_co = f'{target_path}/{model_name}List/components'
914914
if not os.path.exists(cur_path_co):
915915
os.mkdir(cur_path_co)
916-
with open(f'{target_path}/{model_name}List/index.jsx', 'w') as fw:
916+
with open(f'{target_path}/{model_name}List/index.jsx', 'w', encoding='utf-8') as fw:
917917
fw.write(new_content)
918-
with open(f'{target_path}/{model_name}List/service.js', 'w') as fw:
918+
with open(f'{target_path}/{model_name}List/service.js', 'w', encoding='utf-8') as fw:
919919
fw.write(new_services)
920-
with open(f'{target_path}/{model_name}List/components/CreateForm.jsx', 'w') as fw:
920+
with open(f'{target_path}/{model_name}List/components/CreateForm.jsx', 'w', encoding='utf-8') as fw:
921921
fw.write(create_form)
922-
with open(f'{target_path}/{model_name}List/components/UpdateForm.jsx', 'w') as fw:
922+
with open(f'{target_path}/{model_name}List/components/UpdateForm.jsx', 'w', encoding='utf-8') as fw:
923923
fw.write(update_form)
924924
if one._meta.app_label == user._meta.app_label:
925-
with open(f'{target_path}/{model_name}List/components/UpdatePasswordForm.jsx', 'w') as fw:
925+
with open(f'{target_path}/{model_name}List/components/UpdatePasswordForm.jsx', 'w', encoding='utf-8') as fw:
926926
fw.write(change_password_form)
927927

928928

tyadmin_api_cli/gen_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Meta:
8585
# if os.path.exists(f'{settings.BASE_DIR}/tyadmin_api/auto_filters.py'):
8686
# print("已存在filters.py跳过")
8787
# else:
88-
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_filters.py', 'w') as fw:
88+
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_filters.py', 'w', encoding='utf-8') as fw:
8989
fw.write(filters_txt)
9090

9191

tyadmin_api_cli/gen_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def gen_serializer(project_name_settings, user_label_list):
136136
# if os.path.exists(f'{settings.BASE_DIR}/tyadmin_api/auto_serializers.py'):
137137
# print("已存在serializers跳过")
138138
# else:
139-
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_serializers.py', 'w') as fw:
139+
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_serializers.py', 'w', encoding='utf-8') as fw:
140140
fw.write(serializers_txt)
141141

142142

tyadmin_api_cli/gen_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def gen_url(project_name_settings, user_label_list):
4040
# if os.path.exists(f'{settings.BASE_DIR}/tyadmin_api/auto_url.py'):
4141
# print("已存在urls跳过")
4242
# else:
43-
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_url.py', 'w') as fw:
43+
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_url.py', 'w', encoding='utf-8') as fw:
4444
fw.write(url_txt)
4545

4646

tyadmin_api_cli/gen_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_serializer_class(self):
7373
# if os.path.exists(f'{settings.BASE_DIR}/tyadmin_api/auto_views.py'):
7474
# print("已存在views跳过")
7575
# else:
76-
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_views.py', 'w') as fw:
76+
with open(f'{settings.BASE_DIR}/tyadmin_api/auto_views.py', 'w', encoding='utf-8') as fw:
7777
fw.write(viewset_txt)
7878

7979

0 commit comments

Comments
 (0)