mwgencode 1.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gencode/__init__.py +140 -0
- gencode/dd_models.py +256 -0
- gencode/ext.py +19 -0
- gencode/gen_code.py +343 -0
- gencode/gencode/__init__.py +0 -0
- gencode/gencode/export_class2swgclass.py +206 -0
- gencode/gencode/gen_bo_models_code.py +719 -0
- gencode/gencode/gen_state_code.py +171 -0
- gencode/gencode/gen_swagger_code.py +94 -0
- gencode/gencode/gen_tests_code.py +113 -0
- gencode/gencode/sample/__init__.py +2 -0
- gencode/gencode/sample/babel.cfg +3 -0
- gencode/gencode/sample/config-sample.ini +9 -0
- gencode/gencode/sample/config.ini +14 -0
- gencode/gencode/sample/create_new_table_run.pys +19 -0
- gencode/gencode/sample/dockerignore.dock +57 -0
- gencode/gencode/sample/file_utils.pys +396 -0
- gencode/gencode/sample/gencode.xmi +33 -0
- gencode/gencode/sample/gitignore.git +14 -0
- gencode/gencode/sample/migrate_run.bat +5 -0
- gencode/gencode/sample/migrate_run.pys +9 -0
- gencode/gencode/sample/requirements.txt +17 -0
- gencode/gencode/sample/run.sh +27 -0
- gencode/gencode/sample/seeds/__init__.py +0 -0
- gencode/gencode/sample/seeds/models_rm.pys +187 -0
- gencode/gencode/sample/seeds/seed_dev_data.pys +21 -0
- gencode/gencode/sample/seeds/seed_init.pys +17 -0
- gencode/gencode/sample/seeds/seed_rm.pys +39 -0
- gencode/gencode/sample/seeds/seed_run.pys +13 -0
- gencode/gencode/sample/seeds/seed_utils.pys +23 -0
- gencode/gencode/sample/test__init__.pys +6 -0
- gencode/gencode/sample/test_run.pys +4 -0
- gencode/gencode/sample/utils.pys +92 -0
- gencode/gencode/template/Dockerfile.tmp +55 -0
- gencode/gencode/template/README.md +91 -0
- gencode/gencode/template/__init__.py +0 -0
- gencode/gencode/template/__init__.pys +99 -0
- gencode/gencode/template/config.pys +134 -0
- gencode/gencode/template/default.conf +21 -0
- gencode/gencode/template/docker-compose-dev.yaml +52 -0
- gencode/gencode/template/docker-compose.yaml +55 -0
- gencode/gencode/template/drone.tmp +45 -0
- gencode/gencode/template/flask_models.pys +107 -0
- gencode/gencode/template/flask_models_base.pys +159 -0
- gencode/gencode/template/gen_code_flask.yaml +21 -0
- gencode/gencode/template/gen_code_run.pys +28 -0
- gencode/gencode/template/k8s-tmp.yml +141 -0
- gencode/gencode/template/run.pys +52 -0
- gencode/gencode/template/sample.mdj +1193 -0
- gencode/gencode/template/setup.tmp +48 -0
- gencode/gencode/template/supervisord.conf +21 -0
- gencode/gencode/template/swagger_file.yaml +195 -0
- gencode/gencode/template/swg_class.tmp +41 -0
- gencode/gencode/template/swg_ctrl_code.pys +130 -0
- gencode/gencode/template/swg_package_mng.tmp +4423 -0
- gencode/gencode/template/test_test_base.tmp +34 -0
- gencode/gencode/template/tests/__init__.py +0 -0
- gencode/gencode/template/tests/__init__.pys +5 -0
- gencode/gencode/template/tests/init_test_data.pys +80 -0
- gencode/gencode/template/tests/run.pys +4 -0
- gencode/gencode/template/tests/test_base.pys +87 -0
- gencode/gencode/template/tests/test_classmng.pys +58 -0
- gencode/gencode/template/uwsgi.ini +20 -0
- gencode/gencode/template/uwsgi_run.pys +44 -0
- gencode/importmdj/__init__.py +0 -0
- gencode/importmdj/import_dd_classes.py +369 -0
- gencode/importmdj/import_swagger2_class.py +371 -0
- gencode/importmdj/import_uml_models.py +466 -0
- gencode/importxmi/__init__.py +1 -0
- gencode/importxmi/import_classes.py +342 -0
- gencode/importxmi/import_sequences.py +291 -0
- gencode/importxmi/import_states.py +150 -0
- gencode/importxmi/import_swagger.py +151 -0
- gencode/swg2_class_models.py +179 -0
- gencode/uml_class_models.py +295 -0
- gencode/upgrade.py +113 -0
- gencode/utils.py +225 -0
- manage.py +194 -0
- mwgencode-1.4.1.dist-info/METADATA +325 -0
- mwgencode-1.4.1.dist-info/RECORD +84 -0
- mwgencode-1.4.1.dist-info/WHEEL +5 -0
- mwgencode-1.4.1.dist-info/entry_points.txt +2 -0
- mwgencode-1.4.1.dist-info/licenses/LICENSE.txt +19 -0
- mwgencode-1.4.1.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from distutils.core import setup
|
|
2
|
+
from Cython.Build import cythonize
|
|
3
|
+
|
|
4
|
+
def get_package_datas(pathname):
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
dirs = []
|
|
7
|
+
def get_dir(pathname,dirs):
|
|
8
|
+
pth = Path(pathname)
|
|
9
|
+
paths = [x for x in pth.iterdir() if x .is_dir()]
|
|
10
|
+
for p in paths:
|
|
11
|
+
if p.name in ('.git', '.idea', '__pycache__'):
|
|
12
|
+
continue
|
|
13
|
+
dirs.append(p.parts)
|
|
14
|
+
get_dir(str(p),dirs)
|
|
15
|
+
get_dir(pathname,dirs)
|
|
16
|
+
# 不需要包含 app
|
|
17
|
+
return ['/'.join(d[1:])+'/*' for d in dirs]+[Path(pathname).parts[-1]+'/*']
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
# package_datas = get_package_datas('app/translations', skip_dirs={'LC_MESSAGES'})
|
|
21
|
+
# package_datas.extend(get_package_datas('app/static'))
|
|
22
|
+
setup(
|
|
23
|
+
# 指定package,可以copy package data,但会包含py源码,需在安装后删除py文件
|
|
24
|
+
# packages=['app'],
|
|
25
|
+
ext_modules=cythonize('app/*.py',language_level = 3,compiler_directives=dict(always_allow_keywords=True))+
|
|
26
|
+
cythonize('app/api/*.py',language_level = 3,compiler_directives=dict(always_allow_keywords=True))+
|
|
27
|
+
cythonize('app/api/v1_0/*.py',language_level = 3,compiler_directives=dict(always_allow_keywords=True)),
|
|
28
|
+
# package_data={'app': get_package_datas('app/static')},
|
|
29
|
+
# 有多个目录
|
|
30
|
+
# package_data={'app': package_datas},
|
|
31
|
+
data_files=[
|
|
32
|
+
# ('/usr/local/lib/python3.7/site-packages/app/translations/en/LC_MESSAGES',
|
|
33
|
+
# ['app/translations/en/LC_MESSAGES/messages.mo']),
|
|
34
|
+
# ('/usr/local/lib/python3.7/site-packages/app/translations/zh_Hans_CN/LC_MESSAGES',
|
|
35
|
+
# ['app/translations/zh_Hans_CN/LC_MESSAGES/messages.mo']),
|
|
36
|
+
# ('/usr/local/lib/python3.7/site-packages/app/translations/zh_Hant_TW/LC_MESSAGES',
|
|
37
|
+
# ['app/translations/zh_Hant_TW/LC_MESSAGES/messages.mo']),
|
|
38
|
+
# ('/usr/local/lib/python3.7/site-packages/app/translations/vi_VN/LC_MESSAGES',
|
|
39
|
+
# ['app/translations/vi_VN/LC_MESSAGES/messages.mo']),
|
|
40
|
+
# ('/usr/local/lib/python3.7/site-packages/app/translations/ja/LC_MESSAGES',
|
|
41
|
+
# ['app/translations/ja/LC_MESSAGES/messages.mo']),
|
|
42
|
+
('/usr/local/lib/python3.7/site-packages/swagger/v1_0',
|
|
43
|
+
['swagger/v1_0/{{swagger.name}}.yaml'])
|
|
44
|
+
]
|
|
45
|
+
)
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print (e)
|
|
48
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[supervisord]
|
|
2
|
+
nodaemon=true
|
|
3
|
+
|
|
4
|
+
[program:uwsgi]
|
|
5
|
+
command=uwsgi --ini /var/{{swagger.name}}/uwsgi.ini --die-on-term --plugin python
|
|
6
|
+
stdout_logfile=/dev/stdout
|
|
7
|
+
stdout_logfile_maxbytes=0
|
|
8
|
+
stderr_logfile=/dev/stderr
|
|
9
|
+
stderr_logfile_maxbytes=0
|
|
10
|
+
|
|
11
|
+
[program:nginx]
|
|
12
|
+
command= nginx -g 'daemon off;'
|
|
13
|
+
autostart=true
|
|
14
|
+
autorestart=true
|
|
15
|
+
priority=10
|
|
16
|
+
stdout_events_enabled=true
|
|
17
|
+
stderr_events_enabled=true
|
|
18
|
+
stdout_logfile=/dev/stdout
|
|
19
|
+
stdout_logfile_maxbytes=0
|
|
20
|
+
stderr_logfile=/dev/stderr
|
|
21
|
+
stderr_logfile_maxbytes=0
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
swagger: "2.0"
|
|
2
|
+
info:
|
|
3
|
+
description: "{{ (swg.desc or '').replace('\"','\'') }}"
|
|
4
|
+
|
|
5
|
+
version: v1.0
|
|
6
|
+
title: {{ swg.swgtitle }}
|
|
7
|
+
host: {{swg.swghost}}
|
|
8
|
+
basePath: /{{ swg.name }}/v1.0
|
|
9
|
+
{% if swg.tags %}
|
|
10
|
+
tags:
|
|
11
|
+
{% for tag in swg.tags %}
|
|
12
|
+
- name: {{ tag.name }}
|
|
13
|
+
description: "{{ (tag.doc or '').replace('\"','\'') }}"
|
|
14
|
+
{% endfor %}
|
|
15
|
+
{% endif %}
|
|
16
|
+
schemes:
|
|
17
|
+
- http
|
|
18
|
+
- https
|
|
19
|
+
|
|
20
|
+
{% if swg.auth=='jwt'%}
|
|
21
|
+
securityDefinitions:
|
|
22
|
+
api_JWT:
|
|
23
|
+
type: apiKey
|
|
24
|
+
name: jwt
|
|
25
|
+
in: query
|
|
26
|
+
x-apikeyInfoFunc: app.apikey_auth
|
|
27
|
+
api_Key:
|
|
28
|
+
type: apiKey
|
|
29
|
+
name: apikey
|
|
30
|
+
in: query
|
|
31
|
+
x-apikeyInfoFunc: app.apikey_auth
|
|
32
|
+
api_Cookie:
|
|
33
|
+
type: apiKey
|
|
34
|
+
name: Cookie
|
|
35
|
+
in: header
|
|
36
|
+
x-apikeyInfoFunc: app.apikey_auth
|
|
37
|
+
api_Authorization:
|
|
38
|
+
type: apiKey
|
|
39
|
+
name: Authorization
|
|
40
|
+
in: header
|
|
41
|
+
x-apikeyInfoFunc: app.apikey_auth
|
|
42
|
+
{% endif %}
|
|
43
|
+
paths:
|
|
44
|
+
{% for path in paths %}
|
|
45
|
+
/{{ path.name.replace('_{','/{').replace('}_','}/') }}:
|
|
46
|
+
{% for act in path.actions %}
|
|
47
|
+
{{ act.action }}:
|
|
48
|
+
tags:
|
|
49
|
+
- {{ path.tag.name }}
|
|
50
|
+
summary: "{{ (act.summary or '').replace('\"','\'') }}"
|
|
51
|
+
description: "{{ (act.doc or '').replace('\"','\'') }}"
|
|
52
|
+
operationId: app.api.{{ act.ver_str }}.{{ path.tag.name }}.{{ path.name.replace('/','_').replace('{','').replace('}','').replace('-','_') }}_{{ act.action }}
|
|
53
|
+
schemes:
|
|
54
|
+
- http
|
|
55
|
+
- https
|
|
56
|
+
consumes:
|
|
57
|
+
{% if swg.resp_xml %}
|
|
58
|
+
- application/xml
|
|
59
|
+
{% endif %}
|
|
60
|
+
{% if swg.resp_html %}
|
|
61
|
+
- text/html
|
|
62
|
+
{% endif %}
|
|
63
|
+
{% if act.has_formdata %}
|
|
64
|
+
- application/x-www-form-urlencoded
|
|
65
|
+
- multipart/form-data
|
|
66
|
+
{% endif %}
|
|
67
|
+
- application/json
|
|
68
|
+
produces:
|
|
69
|
+
- application/json
|
|
70
|
+
{% if swg.resp_xml %}
|
|
71
|
+
- application/xml
|
|
72
|
+
{% endif %}
|
|
73
|
+
{% if swg.resp_html %}
|
|
74
|
+
- text/html
|
|
75
|
+
{% endif %}
|
|
76
|
+
|
|
77
|
+
{% if act.params %}
|
|
78
|
+
parameters:
|
|
79
|
+
{% for param in act.params %}
|
|
80
|
+
- in: {{ param.in_ }}
|
|
81
|
+
name: {{ param.name }}
|
|
82
|
+
description: "{{ (param.desc or '').replace('\"','\'') }}"
|
|
83
|
+
required: {{ param.required }}
|
|
84
|
+
{% if param.is_array %}
|
|
85
|
+
{% if param.type_attr == "data" %}
|
|
86
|
+
type: array
|
|
87
|
+
items:
|
|
88
|
+
type: {{ param.type }}
|
|
89
|
+
{% if param.format %}
|
|
90
|
+
format: {{ param.format }}
|
|
91
|
+
{% endif %}
|
|
92
|
+
collectionFormat: multi
|
|
93
|
+
{% elif param.type_attr == "object" %}
|
|
94
|
+
schema:
|
|
95
|
+
type: array
|
|
96
|
+
items:
|
|
97
|
+
$ref: "#/definitions/{{ param.ref_name }}"
|
|
98
|
+
{% endif %}
|
|
99
|
+
{% else %}
|
|
100
|
+
{% if param.type_attr == "data" %}
|
|
101
|
+
type: {{ param.type }}
|
|
102
|
+
{% if param.format %}
|
|
103
|
+
format: {{ param.format }}
|
|
104
|
+
{% endif %}
|
|
105
|
+
{% elif param.type_attr == "object" %}
|
|
106
|
+
schema:
|
|
107
|
+
$ref: "#/definitions/{{ param.ref_name }}"
|
|
108
|
+
{% endif %}
|
|
109
|
+
{% endif %}
|
|
110
|
+
{% endfor %}
|
|
111
|
+
{% endif %}
|
|
112
|
+
responses:
|
|
113
|
+
{% for resp in act.resps %}
|
|
114
|
+
{{ resp.code }}:
|
|
115
|
+
description: "{{ (resp.desc or '').replace('\"','\'') }}"
|
|
116
|
+
{% if resp.type_attr != "none" %}
|
|
117
|
+
{% if resp.is_array %}
|
|
118
|
+
schema:
|
|
119
|
+
type: "array"
|
|
120
|
+
items:
|
|
121
|
+
{% if resp.type_attr=="object" %}
|
|
122
|
+
$ref: "#/definitions/{{ resp.ref_name }}"
|
|
123
|
+
{% elif resp.type_attr=="data" %}
|
|
124
|
+
type : {{ resp.type }}
|
|
125
|
+
{% endif %}
|
|
126
|
+
{% else %}
|
|
127
|
+
schema:
|
|
128
|
+
{% if resp.type_attr=="object" %}
|
|
129
|
+
$ref: "#/definitions/{{ resp.ref_name }}"
|
|
130
|
+
{% elif resp.type_attr=="data" %}
|
|
131
|
+
type: string
|
|
132
|
+
{% endif %}
|
|
133
|
+
{% endif %}
|
|
134
|
+
{% endif %}
|
|
135
|
+
{% endfor %}
|
|
136
|
+
# ks:key auth,js:jwt auth ,bs :basc auth ,os:oauth2 ,s:jw auth
|
|
137
|
+
{% if act.is_auth %}
|
|
138
|
+
security:
|
|
139
|
+
{% if act.auth_type=="ks" %}
|
|
140
|
+
- api_Key: []
|
|
141
|
+
{% endif %}
|
|
142
|
+
{% if act.auth_type=="js" %}
|
|
143
|
+
- api_JWT: []
|
|
144
|
+
{% endif %}
|
|
145
|
+
{% if act.auth_type=="s" %}
|
|
146
|
+
- api_JWT: []
|
|
147
|
+
- api_Key: []
|
|
148
|
+
- api_Cookie: []
|
|
149
|
+
- api_Authorization: []
|
|
150
|
+
{% endif %}
|
|
151
|
+
{% if act.auth_type=="bs" %}
|
|
152
|
+
- basic: []
|
|
153
|
+
{% endif %}
|
|
154
|
+
{% if act.auth_type=="os" %}
|
|
155
|
+
- oauth2: ['uid']
|
|
156
|
+
{% endif %}
|
|
157
|
+
{% endif %}
|
|
158
|
+
{% endfor %}
|
|
159
|
+
{% endfor %}
|
|
160
|
+
{% if swg.defines %}
|
|
161
|
+
definitions:
|
|
162
|
+
{% endif %}
|
|
163
|
+
{% for defin in swg.defines %}
|
|
164
|
+
{{ defin.name }}:
|
|
165
|
+
type: object
|
|
166
|
+
description: "{{ (defin.desc or '').replace('\"','\'') }}"
|
|
167
|
+
properties:
|
|
168
|
+
{% for attr in defin.attrs %}
|
|
169
|
+
{{ attr.name }}:
|
|
170
|
+
{% if attr.is_array %}
|
|
171
|
+
description: "{{ (attr.desc or '').replace('\"','\'') }}"
|
|
172
|
+
type: array
|
|
173
|
+
items:
|
|
174
|
+
{% if attr.type_attr=="object" %}
|
|
175
|
+
$ref: "#/definitions/{{ attr.ref_name }}"
|
|
176
|
+
{% elif attr.type_attr=="data" %}
|
|
177
|
+
type: {{ attr.type }}
|
|
178
|
+
{% if attr.format %}
|
|
179
|
+
format: {{ attr.format }}
|
|
180
|
+
{% endif %}
|
|
181
|
+
{% endif %}
|
|
182
|
+
{% else %}
|
|
183
|
+
{% if attr.type_attr=="object" %}
|
|
184
|
+
$ref: "#/definitions/{{ attr.ref_name }}"
|
|
185
|
+
{% elif attr.type_attr=="data" %}
|
|
186
|
+
description: "{{ (attr.desc or '').replace('\"','\'') }}"
|
|
187
|
+
type: {{ attr.type }}
|
|
188
|
+
{% if attr.format %}
|
|
189
|
+
format: {{ attr.format }}
|
|
190
|
+
{% endif %}
|
|
191
|
+
{% endif %}
|
|
192
|
+
{% endif %}
|
|
193
|
+
{% endfor %}
|
|
194
|
+
{% endfor %}
|
|
195
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[
|
|
2
|
+
{% for cls in classes %}
|
|
3
|
+
{
|
|
4
|
+
"_type": "UMLClass",
|
|
5
|
+
"_id": "cls_{{cls.id}}",
|
|
6
|
+
"_parent": {
|
|
7
|
+
"$ref": "{{swg_pkg_id}}"
|
|
8
|
+
},
|
|
9
|
+
"documentation":"{{cls.doc}}",
|
|
10
|
+
"name": "{{cls.name}}",
|
|
11
|
+
"visibility": "public",
|
|
12
|
+
"attributes": [
|
|
13
|
+
{% for pro in cls.propertys %}
|
|
14
|
+
{
|
|
15
|
+
"_type": "UMLAttribute",
|
|
16
|
+
"_id": "pro_{{pro.id}}",
|
|
17
|
+
"_parent": {
|
|
18
|
+
"$ref": "cls_{{cls.id}}"
|
|
19
|
+
},
|
|
20
|
+
"name": "{{pro.name}}",
|
|
21
|
+
"documentation":"{{pro.doc}}",
|
|
22
|
+
"visibility": "public",
|
|
23
|
+
"isStatic": false,
|
|
24
|
+
"isLeaf": false,
|
|
25
|
+
"type": "{{pro.type.lower()}}",
|
|
26
|
+
"isReadOnly": false,
|
|
27
|
+
"isOrdered": false,
|
|
28
|
+
"isUnique": false,
|
|
29
|
+
"isDerived": false,
|
|
30
|
+
"aggregation": "none",
|
|
31
|
+
"isID": false
|
|
32
|
+
}{% if pro.id!=cls.propertys[-1].id %},{% endif %}
|
|
33
|
+
{% endfor %}
|
|
34
|
+
],
|
|
35
|
+
"isAbstract": false,
|
|
36
|
+
"isFinalSpecialization": false,
|
|
37
|
+
"isLeaf": false,
|
|
38
|
+
"isActive": false
|
|
39
|
+
}{% if cls.id != classes[-1].id %},{% endif %}
|
|
40
|
+
{% endfor %}
|
|
41
|
+
]
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
from app import auth, db, p
|
|
2
|
+
from app.models import *
|
|
3
|
+
from flask import current_app
|
|
4
|
+
from flask_babel import gettext as _
|
|
5
|
+
from app.utils import set_timezone,todatetime
|
|
6
|
+
|
|
7
|
+
{% for path in paths %}
|
|
8
|
+
{% for act in path.actions %}
|
|
9
|
+
{% if act.default_resp.umlcls_type=='UMLClass' or act.is_auth %}
|
|
10
|
+
@auth.valid_login
|
|
11
|
+
{% if not act.is_lk %}
|
|
12
|
+
@p.check("{{act.default_resp.ref_name}}",["{{right_type[act.action]}}"])
|
|
13
|
+
{% endif %}
|
|
14
|
+
{% endif %}
|
|
15
|
+
|
|
16
|
+
def {{path.name.replace('{', '').replace('}', '').replace('-', '_').replace('/','_') + '_' + act.action}}({{get_params(act.params)}}):
|
|
17
|
+
"""
|
|
18
|
+
{{act.summary}}
|
|
19
|
+
{{act.doc}}
|
|
20
|
+
{% for param in act.params %}
|
|
21
|
+
:param {{param.name}}:{{param.desc}}
|
|
22
|
+
:type {{param.name}}: {{param.type}}
|
|
23
|
+
|
|
24
|
+
:rtype:{% if act.default_resp %}{{act.default_resp.ref_name.capitalize()}}{% endif %}
|
|
25
|
+
{% endfor %}
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
{% if act.default_resp.umlcls_type=='UMLClass' %}
|
|
29
|
+
{% if act.action == 'post' %}
|
|
30
|
+
try:
|
|
31
|
+
data = {{act.default_resp.ref_name.capitalize()}}(**{k: v for k, v in body.items() if k in {{act.default_resp.ref_name.capitalize()}}.__table__.columns.keys()})
|
|
32
|
+
# data = {{act.default_resp.ref_name.capitalize()}}(**todatetime({k: v for k, v in body.items() if k in {{act.default_resp.ref_name.capitalize()}}.__table__.columns.keys()},
|
|
33
|
+
# [datetime fields]))
|
|
34
|
+
db.session.add(data)
|
|
35
|
+
db.session.commit()
|
|
36
|
+
except Exception as e:
|
|
37
|
+
db.session.rollback()
|
|
38
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
39
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
40
|
+
return set_timezone(data.to_json()), 201, {"content-type": "application/json;charset=utf8"}
|
|
41
|
+
{% endif %}
|
|
42
|
+
|
|
43
|
+
{% if act.action == 'put' %}
|
|
44
|
+
try:
|
|
45
|
+
body = todatetime({k: v for k, v in body.items() if k in {{act.default_resp.ref_name.capitalize()}}.__table__.columns.keys()},[])
|
|
46
|
+
{{act.default_resp.ref_name.capitalize()}}.query.filter({{act.default_resp.ref_name.capitalize()}}.id == id).update(body)
|
|
47
|
+
except Exception as e:
|
|
48
|
+
db.session.rollback()
|
|
49
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
50
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
51
|
+
data = {{act.default_resp.ref_name.capitalize()}}.query.filter_by(id=id).first_or_404()
|
|
52
|
+
return set_timezone(data.to_json()), 201, {"content-type": "application/json;charset=utf8"}
|
|
53
|
+
{% endif %}
|
|
54
|
+
{% if act.action == 'delete' %}
|
|
55
|
+
try:
|
|
56
|
+
db.session.query({{act.default_resp.ref_name.capitalize()}}).filter({{act.default_resp.ref_name.capitalize()}}.id == id).delete()
|
|
57
|
+
except Exception as e:
|
|
58
|
+
db.session.rollback()
|
|
59
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
60
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
61
|
+
return "", 204
|
|
62
|
+
{% endif %}
|
|
63
|
+
|
|
64
|
+
{% if act.action == 'get' and not act.default_resp.is_array %}
|
|
65
|
+
data = {{act.default_resp.ref_name.capitalize()}}.query.filter_by(id=id).first_or_404()
|
|
66
|
+
return set_timezone(data.to_json()), 200, {"content-type": "application/json;charset=utf8"}
|
|
67
|
+
{% endif %}
|
|
68
|
+
|
|
69
|
+
{% if act.action == 'get' and act.default_resp.is_array %}
|
|
70
|
+
{% if act.has_page %}
|
|
71
|
+
datap = {{act.default_resp.ref_name.capitalize()}}.query
|
|
72
|
+
header = {"content-type": "application/json;charset=utf8"}
|
|
73
|
+
# todo add custom filter,sample:
|
|
74
|
+
#if name:
|
|
75
|
+
# datap = datap.filter({{act.default_resp.ref_name.capitalize()}}.name.like('%'+name+'%'))
|
|
76
|
+
if page is None and per_page is None:
|
|
77
|
+
datas = datap.all()
|
|
78
|
+
else:
|
|
79
|
+
datap = datap.order_by({{act.default_resp.ref_name.capitalize()}}.id).paginate(page=page, per_page=per_page)
|
|
80
|
+
datas = datap.items
|
|
81
|
+
header.update({"x-page":datap.page,"x-total":datap.total})
|
|
82
|
+
return [set_timezone(data.to_json()) for data in datas] ,200 ,header
|
|
83
|
+
{% else %}
|
|
84
|
+
datap = {{act.default_resp.ref_name.capitalize()}}.query
|
|
85
|
+
# todo add filter ,sample:
|
|
86
|
+
#if name:
|
|
87
|
+
# datap = datap.filter({{act.default_resp.ref_name.capitalize()}}.name.like('%'+name+'%'))
|
|
88
|
+
datas = datap.all()
|
|
89
|
+
return [set_timezone(data.to_json()) for data in datas],200,{"content-type": "application/json;charset=utf8"}
|
|
90
|
+
{% endif %}
|
|
91
|
+
{% endif %}
|
|
92
|
+
|
|
93
|
+
{% else %}
|
|
94
|
+
{% if act.action == 'post' %}
|
|
95
|
+
try:
|
|
96
|
+
data = {}
|
|
97
|
+
return data, 201, {"content-type": "application/json;charset=utf8"}
|
|
98
|
+
except Exception as e:
|
|
99
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
100
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
101
|
+
{% elif act.action == 'put' %}
|
|
102
|
+
try:
|
|
103
|
+
data = {}
|
|
104
|
+
return data, 201, {"content-type": "application/json;charset=utf8"}
|
|
105
|
+
except Exception as e:
|
|
106
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
107
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
108
|
+
{% elif act.action == 'delete' %}
|
|
109
|
+
try:
|
|
110
|
+
data = {}
|
|
111
|
+
return "", 204
|
|
112
|
+
except Exception as e:
|
|
113
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
114
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
115
|
+
{% elif act.action == 'get' %}
|
|
116
|
+
try:
|
|
117
|
+
data = {}
|
|
118
|
+
return data, 200, {"content-type": "application/json;charset=utf8"}
|
|
119
|
+
except Exception as e:
|
|
120
|
+
current_app.logger.error(str(e),exc_info=True)
|
|
121
|
+
return {"error": _(str(e))}, 422, {"content-type": "application/json;charset=utf8"}
|
|
122
|
+
{% else %}
|
|
123
|
+
pass
|
|
124
|
+
{% endif %}
|
|
125
|
+
{% endif %}
|
|
126
|
+
{% endfor %}
|
|
127
|
+
{% endfor %}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|