From 6959e394d70191e9e350b4a6cfc4ca60aa965010 Mon Sep 17 00:00:00 2001 From: han0 Date: Mon, 9 Aug 2021 15:15:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(func):=20=E6=96=B0=E5=A2=9E=20get=5Freques?= =?UTF-8?q?t=5Fjson=20=E5=AF=B9=E9=A9=BC=E5=B3=B0=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=BD=AC=E6=8D=A2=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 21 ++++++++++++++++ nc_http/core/func.py | 35 ++++++++++++++++++++++++++- nc_http/core/verification/__init__.py | 2 +- requirements.txt | 10 +++++++- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ae70441 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + +- repo: https://github.com/pre-commit/mirrors-pylint + rev: v2.7.4 + hooks: + - id: pylint + exclude: ^nc_http/trash + args: + - --disable=C0103,C0114,C0115,C0116,E0401,R0201,R0903,R1722,W0105,W0108,W0401,W0613,W0621 +# - --enable=unused-import + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: check-json + - id: check-merge-conflict + - id: check-yaml + - id: no-commit-to-branch + args: [--branch, staging] + - id: check-added-large-files + args: [ --maxkb=512 ] \ No newline at end of file diff --git a/nc_http/core/func.py b/nc_http/core/func.py index 7e0e410..e878e77 100644 --- a/nc_http/core/func.py +++ b/nc_http/core/func.py @@ -23,9 +23,40 @@ def strip_value(data): return data -def get_request_json(): +def camelize(uncamelized_str): + """ + 小写下划线转驼峰 + :param uncamelized_str: + :return: + """ + if not uncamelized_str: + return uncamelized_str + result = ''.join(i.capitalize() for i in uncamelized_str.split('_')) + result = ''.join((result[0].lower(), result[1:])) + return result + + +def uncamelize(camelized_str): + """ + 驼峰转小写下划线 + :param camelized_str: + :return: + """ + if not camelized_str: + return camelized_str + lst = [] + for index, char in enumerate(camelized_str): + if char.isupper() and index != 0: + lst.append("_") + lst.append(char) + + return ''.join(lst).lower() + + +def get_request_json(is_uncamelize=False): """ 获取 json 传递参数 + :param is_uncamelize: 是否进行驼峰->小写下划线转换 :return: """ if 'request_data' not in g: @@ -37,6 +68,8 @@ def get_request_json(): data = json.loads(json_data) else: data = request.get_json(force=True, silent=True) or {} + if is_uncamelize: + data = {uncamelize(k): v for k, v in data.items()} g.request_data = strip_value(data) diff --git a/nc_http/core/verification/__init__.py b/nc_http/core/verification/__init__.py index 1fd698f..5d610cd 100644 --- a/nc_http/core/verification/__init__.py +++ b/nc_http/core/verification/__init__.py @@ -1,3 +1,3 @@ """ 用户验证码相关 -""" \ No newline at end of file +""" diff --git a/requirements.txt b/requirements.txt index 88a0e36..9853b8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,12 @@ xlrd>=1.2.0 captcha>=0.3 six>=1.15.0 requests>=2.25.0 -locust>=1.5.3 \ No newline at end of file +locust>=1.5.3 + +docxtpl>=0.11.5 +python-docx>=0.8.11 + +python-dateutil +sqlalchemy + +pre-commit \ No newline at end of file