python gen amis json options
Project description
pyamis
目的: 在python
中生成amis
的json
配置
解决问题:
- 手写json配置太累了,配置复制粘贴重用性不好,减少手写json拼写出错概率
- 可以在python中通过代码快速生成json配置
- 要能和python的dict混用
install
git clone https://github.com/1178615156/pyamis
pip install --editable .
示例
生成Form组件
# 首先import下
from pyamis.components import *
form = Form(
target='target',
mode="horizontal",
# 可以看到属性能够直接插入dict
controls=[
{
"type": "submit",
"label": "登录"
}
]
)
这样就生成了个Form配置了,然后转成json看看
import json
json.dumps(form)
转成json
{
"type": "form",
"mode": "horizontal",
"controls": [
{
"type": "submit",
"label": "\u767b\u5f55"
}
],
"target": "target"
}
和dict进一步结合示例
form_default_options = dict(
title='条件',
mode='horizontal',
horizontal={
"leftFixed": "sm"
},
submitOnInit=False,
autoFocus=False,
)
form = Form(**form_default_options, #可以直接插入dict
target='target')
# 直接设置属性也可以
form['controls'] = [
{
"type": "submit",
"label": "提交"
}
]
目前有的组件有:
快速启动示例
from flask import Flask, send_file
from pyamis.components import *
import json
app = Flask("pyamis-test")
# app-pages配置
def site():
return [
# 第一个page
AppPage(
label='page-1',
url='1',
# 第一个page有2个子页
children=[
# 子页1
AppPage(
label="page-1-1",
url='page-1-1',
schema_body=[
Form(controls=[
{
'type': 'text',
'name': "email",
'label': "email",
"required": True
},
]),
"hello world 1 - 1"
]
),
# 子页2
AppPage(
label="page-1-2",
url='page-1-2',
# schema_body=[...] 等价于
schema=Page(body=[
'hello page 1 - 2 '
]),
),
]
),
# 第二个page
AppPage(
label='page-2',
url='2',
#如果想用的组件没有的话,可以直接写json
schema_body=[
{
"type": "service",
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/page/initData",
"body": {
"type": "panel",
"title": "$title",
"body": "现在是:${date}"
}
}
],
)
]
# print下生成的json配置
print(json.dumps(site(),indent=2))
@app.route('/')
def root():
return send_file('test_index.html')
# 分页的json
@app.route("/pages/site.json")
def site_json():
return {
'data': {
'pages': [
dict(label='Home', url='/'),
dict(children=site())
]
}
}
if __name__ == '__main__':
app.run(port=8080, debug=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py-amis-0.0.1.tar.gz
(13.3 kB
view details)
Built Distribution
py_amis-0.0.1-py3-none-any.whl
(31.1 kB
view details)
File details
Details for the file py-amis-0.0.1.tar.gz
.
File metadata
- Download URL: py-amis-0.0.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4267d0f54e396cd2a37421d1227078c76c52530aac32a023735996365a04805f |
|
MD5 | 1f01a0d0a9503b1983e276dd9af63012 |
|
BLAKE2b-256 | b1aea2e702e4ef120ac0205f64af4fdc3c21ba25fbc3982237098c9ae8b493dc |
File details
Details for the file py_amis-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: py_amis-0.0.1-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39078fa3e2e0703b77b2bdbf287d29b40429a1ab71e937d23c7c9f9cfa8fcbbc |
|
MD5 | 6380df51e560f1dbf5ccaf61d3bd9c31 |
|
BLAKE2b-256 | 51c88a912938b4e64cc01bf32eb148f935c099232babd1d79bf1977536913b33 |