Skip to content

Commit 2266136

Browse files
committed
feat: 增加设置配置为默认数据
1 parent 0f647d8 commit 2266136

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

common/management/commands/services/hands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
sys.exit(1)
2727

2828
HTTP_HOST = CONFIG.HTTP_BIND_HOST or '127.0.0.1'
29-
HTTP_PORT = CONFIG.HTTP_LISTEN_PORT or 8080
29+
HTTP_PORT = CONFIG.HTTP_LISTEN_PORT or 8896
3030
GUNICORN_MAX_WORKER = CONFIG.GUNICORN_MAX_WORKER or 10
3131
CELERY_FLOWER_HOST = CONFIG.CELERY_FLOWER_HOST or '127.0.0.1'
3232
CELERY_FLOWER_PORT = CONFIG.CELERY_FLOWER_PORT or 5555

config_example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SECRET_KEY:
1212
# LOG_LEVEL: DEBUG
1313

1414
# 用于DEBUG模式下,输出sql日志
15-
# DEBUG_DEV = false
15+
# DEBUG_DEV = true
1616

1717
# Database setting, Support sqlite3, mysql, postgres ....
1818
# 数据库设置
@@ -46,10 +46,10 @@ REDIS_PORT: 6379
4646
#CELERY_BROKER_CACHE_ID: 3
4747

4848
# When Django start it will bind this host and port
49-
# ./manage.py runserver 127.0.0.1:8080
49+
# ./manage.py runserver 127.0.0.1:8896
5050
# 运行时绑定端口
5151
HTTP_BIND_HOST: 0.0.0.0
52-
HTTP_LISTEN_PORT: 8080
52+
HTTP_LISTEN_PORT: 8896
5353
GUNICORN_MAX_WORKER: 4
5454

5555
# 需要将创建的应用写到里面

loadjson/setting.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]

system/management/commands/dump_init_json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.core import serializers
1111
from django.core.management.base import BaseCommand
1212

13+
from settings.models import Setting
1314
from system.models import *
1415

1516

@@ -26,7 +27,8 @@ def get_fields(model):
2627

2728
class Command(BaseCommand):
2829
help = 'dump init json data'
29-
model_names = [UserRole, DeptInfo, Menu, MenuMeta, SystemConfig, DataPermission, FieldPermission, ModelLabelField]
30+
model_names = [UserRole, DeptInfo, Menu, MenuMeta, SystemConfig, DataPermission, FieldPermission, ModelLabelField,
31+
Setting]
3032

3133
def save_json(self, queryset, filename):
3234
stream = open(filename, 'w', encoding='utf8')

system/management/commands/load_init_json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
from django.core.management.commands.loaddata import Command as LoadCommand
1111
from django.db import DEFAULT_DB_ALIAS
1212

13+
from settings.models import Setting
1314
from system.models import *
1415

1516

1617
class Command(LoadCommand):
1718
help = 'load init json data'
18-
model_names = [UserRole, DeptInfo, Menu, MenuMeta, SystemConfig, DataPermission, FieldPermission, ModelLabelField]
19+
model_names = [UserRole, DeptInfo, Menu, MenuMeta, SystemConfig, DataPermission, FieldPermission, ModelLabelField,
20+
Setting]
1921
missing_args_message = None
2022

2123
def add_arguments(self, parser):

init_demo.py renamed to utils/init_demo.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from system.models import *
1515
from django.core import management
1616

17-
import os
18-
1917
# 如果有用户存在,则不支持初始化操作
2018
try:
2119
if UserInfo.objects.exists():
@@ -24,12 +22,6 @@
2422
except:
2523
pass
2624

27-
# 需要删除所有表
28-
try:
29-
os.unlink('./db.sqlite3')
30-
except OSError as e:
31-
print(e)
32-
3325
# 初始化操作
3426
try:
3527
management.call_command('makemigrations', )
@@ -40,7 +32,9 @@
4032
except Exception as e:
4133
print(f'Perform migrate failed, {e} exit')
4234

43-
UserInfo.objects.create_superuser('xadmin', 'demon@xadmin.com', '123456')
35+
UserInfo.objects.create_superuser('xadmin', 'xadmin@dvcloud.xin', 'xAdminPwd!')
4436

4537
management.call_command('load_init_json', )
46-
management.call_command('loaddata', 'loadjson/userinfo.json')
38+
39+
# 加载默认用户数据,一般部署新服的时候,如果有默认数据,则可以进行加载
40+
# management.call_command('loaddata', 'loadjson/userinfo.json')

0 commit comments

Comments
 (0)