Skip to content

Commit

Permalink
Merge pull request #69 from TaleLin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
colorful3 authored Jul 19, 2019
2 parents b72774e + e099dba commit 0c6d155
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__
*.pytest_cache/
*.db
*.pyc
*.cpython-36.pyc
*.cpython-36.pyc
app/assets/*
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Flask = "==1.0.2"
Flask-SQLAlchemy = "==2.3.2"
Flask-WTF = "==0.14.2"
Flask-Cors = "==2.1.0"
Lin-CMS = "==0.1.1b4"
Lin-CMS = "==0.2.0b1"

[dev-packages]
pytest = "*"
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Lin-CMS 是林间有风团队经过大量项目实践所提炼出的一套**内

## 最新版本

核心库:0.1.1b4
核心库:0.2.0b1

示例工程:0.1.0-beta.3
示例工程:0.2.0-beta.1


### 文档地址
Expand Down Expand Up @@ -174,3 +174,9 @@ pipenv shell
“心上无垢,林间有风"

这证明你已经成功的将 Lin 运行起来了,Congratulations!

## 下个版本开发计划

- [x] 系统访问日志、错误日志
- [ ] 完善文档
- [ ] 重构核心库结构
2 changes: 1 addition & 1 deletion app/api/cms/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def set_avatar():
form = AvatarUpdateForm().validate_for_api()
user = get_current_user()
with db.auto_commit():
user.avatar = form.avatar.data
user._avatar = form.avatar.data
return Success(msg='更新头像成功')


Expand Down
12 changes: 9 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ def log_response(resp):
return resp


def create_app(register_all=True):
def create_app(register_all=True, environment='production'):
app = Flask(__name__, static_folder='./assets')
app.config.from_object('app.config.setting')
app.config.from_object('app.config.secure')
app.config['ENV'] = environment
env = app.config.get('ENV')
if env == 'production':
app.config.from_object('app.config.setting.ProductionConfig')
app.config.from_object('app.config.secure.ProductionSecure')
elif env == 'development':
app.config.from_object('app.config.setting.DevelopmentConfig')
app.config.from_object('app.config.secure.DevelopmentSecure')
app.config.from_object('app.config.log')
if register_all:
register_blueprints(app)
Expand Down
24 changes: 21 additions & 3 deletions app/config/secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@
"""

# 安全性配置
SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms'
from app.config.setting import BaseConfig

SQLALCHEMY_ECHO = False

SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'
class DevelopmentSecure(BaseConfig):
"""
开发环境安全性配置
"""
SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms'

SQLALCHEMY_ECHO = False

SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'


class ProductionSecure(BaseConfig):
"""
生产环境安全性配置
"""
SQLALCHEMY_DATABASE_URI = 'mysql+cymysql://root:123456@localhost:3306/lin-cms'

SQLALCHEMY_ECHO = False

SECRET_KEY = '\x88W\xf09\x91\x07\x98\x89\x87\x96\xa0A\xc68\xf9\xecJJU\x17\xc5V\xbe\x8b\xef\xd7\xd8\xd3\xe6\x95*4'
67 changes: 51 additions & 16 deletions app/config/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,54 @@

from datetime import timedelta

# 分页配置
COUNT_DEFAULT = 10
PAGE_DEFAULT = 0

# 令牌配置
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)

# 屏蔽 sql alchemy 的 FSADeprecationWarning
SQLALCHEMY_TRACK_MODIFICATIONS = False

# 插件模块暂时没有开启,以下配置可忽略
# plugin config写在字典里面
PLUGIN_PATH = {
'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20},
'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete', 'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com', 'bucket_name': 'not complete', 'upload_folder': 'app', 'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']}
}

class BaseConfig(object):
"""
基础配置
"""
# 分页配置
COUNT_DEFAULT = 10
PAGE_DEFAULT = 0

# 屏蔽 sql alchemy 的 FSADeprecationWarning
SQLALCHEMY_TRACK_MODIFICATIONS = False


class DevelopmentConfig(BaseConfig):
"""
开发环境普通配置
"""
DEBUG = True

# 令牌配置
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)

# 插件模块暂时没有开启,以下配置可忽略
# plugin config写在字典里面
PLUGIN_PATH = {
'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20},
'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete',
'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com',
'bucket_name': 'not complete', 'upload_folder': 'app',
'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']}
}


class ProductionConfig(BaseConfig):
"""
生产环境普通配置
"""
DEBUG = False

# 令牌配置
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)

# 插件模块暂时没有开启,以下配置可忽略
# plugin config写在字典里面
PLUGIN_PATH = {
'poem': {'path': 'app.plugins.poem', 'enable': True, 'version': '0.0.1', 'limit': 20},
'oss': {'path': 'app.plugins.oss', 'enable': True, 'version': '0.0.1', 'access_key_id': 'not complete',
'access_key_secret': 'not complete', 'endpoint': 'http://oss-cn-shenzhen.aliyuncs.com',
'bucket_name': 'not complete', 'upload_folder': 'app',
'allowed_extensions': ['jpg', 'gif', 'png', 'bmp']}
}
8 changes: 6 additions & 2 deletions app/extensions/file/local_uploader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from flask import current_app
from werkzeug.utils import secure_filename

Expand All @@ -20,7 +22,8 @@ def upload(self):
ret.append({
"key": single.name,
"id": exists.id,
"url": site_domain + '/assets/' + exists.path
"path": exists.path,
"url": site_domain + os.path.join(current_app.static_url_path, exists.path)
})
else:
absolute_path, relative_path, real_name = self._get_store_path(single.filename)
Expand All @@ -37,6 +40,7 @@ def upload(self):
ret.append({
"key": single.name,
"id": file.id,
"url": site_domain + '/assets/' + file.path
"path": file.path,
"url": site_domain + os.path.join(current_app.static_url_path, file.path)
})
return ret
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Flask-WTF==0.14.2
idna==2.6
itsdangerous==1.1.0
Jinja2==2.10
Lin-CMS==0.1.1b4
Lin-CMS==0.2.0b1
MarkupSafe==1.1.1
pipfile==0.0.2
PyJWT==1.7.1
Expand Down
2 changes: 1 addition & 1 deletion starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from app.app import create_app

app = create_app()
app = create_app(environment='development')


@app.route('/', methods=['GET'], strict_slashes=False)
Expand Down

0 comments on commit 0c6d155

Please sign in to comment.