Skip to content

Commit

Permalink
fix(form): Correct form test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed Aug 7, 2024
1 parent 20e0722 commit b9d2f72
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 252 deletions.
220 changes: 16 additions & 204 deletions examples/length_converter/converter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import schedula as sh\n",
"from converter import converter, metric, imperial\n",
"from form import form"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -36,28 +36,11 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4589302544\" class=\"sh-box\" src=\"http://localhost:57268/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(SiteMap([(Metric, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Click on the graph to see the model.\n",
"metric.register().plot(view=False, engine='neato', body={'style': 'filled'}).site()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -70,28 +53,11 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4636200400\" class=\"sh-box\" src=\"http://localhost:57270/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(SiteMap([(Imperial, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Click on the graph to see the model.\n",
"imperial.register().plot(view=False, engine='neato', body={'style': 'filled'}).site()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -104,29 +70,12 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4636509968\" class=\"sh-box\" src=\"http://localhost:57274/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(SiteMap([(LengthConverter, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dsp = converter.register()\n",
"# Click on the graph to see the model.\n",
"dsp.plot(view=False, engine='neato', body={'style': 'filled'}).site()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -139,29 +88,12 @@
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4636925072\" class=\"sh-box\" src=\"http://localhost:57278/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(SiteMap([(LengthConverterForm, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"form = form.register()\n",
"# Click on the graph to see the model.\n",
"form.plot(view=False, graph_attr={'rankdir': 'LR'}).site()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -176,49 +108,21 @@
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Solution([('cm', 2.5), ('mm', 25.0), ('km', 2.5e-05)])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sol = dsp.dispatch(inputs={'cm': 2.5}, outputs=['km'])\n",
"sol"
]
],
"outputs": []
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4696731856\" class=\"sh-box\" src=\"http://localhost:57571/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(SiteMap([(LengthConverter, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Click on the graph to see the model.\n",
"sol.plot(view=False, body={'style': 'filled'}).site()"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -231,103 +135,11 @@
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style> .sh-box { width: 100%; height: 500px } </style>\n",
"<iframe id=\"4637592912\" class=\"sh-box\" src=\"http://localhost:57318/\" allowfullscreen>\n",
"</iframe>\n"
],
"text/plain": [
"Site(FormMap([(LengthConverterForm, FormMap())]), host='localhost', port=57318, depth=-1, index=True, root_path=None)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET / HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/props/js/index.js HTTP/1.1\" 404 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/js/main.d0ca5de4.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/css/main.13e13505.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/props/js/index.js HTTP/1.1\" 404 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:47] \"GET /static/schedula/css/main.13e13505.css HTTP/1.1\" 304 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /locales/en_US/messages HTTP/1.1\" 404 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /locales/en/messages HTTP/1.1\" 404 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/forms/index-ui.json HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/forms/index-schema.json HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3793.313eeae4.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6562.c35d9b86.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8568.40698121.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3508.517796c7.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5899.94aff875.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/474.c952ad64.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2556.190d88d8.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1940.a41328ce.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7364.4924a21c.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2931.0adcab7f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/9894.c6e247c9.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7049.216ec413.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8620.8ca4d683.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5870.6625ca31.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1692.5ec0ad01.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7505.521439e5.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4692.4e2c6b7c.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7124.7e1f21cf.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6558.dbc62c6d.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3581.4022e93c.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/9862.c9a0d52e.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3070.44089e71.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6834.399ca706.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4424.32264c0f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8715.5d8dc348.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8294.1eee2cd8.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1748.ea52717d.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4303.c3a825e2.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7928.d01f28f2.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/835.48267712.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2065.0d5474a7.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4842.2a7e5fdf.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8152.6127376f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5387.37f8f61e.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/css/5387.911e2e10.chunk.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1745.833f0cff.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/3281.35755d96.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2506.f185d23a.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/1745.dba1d253.chunk.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/132.a4de6573.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9558.d129bc13.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1279.be357b2b.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2894.f1c4622f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1678.c61f118f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/7828.85a7d563.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/4673.ce2e8e85.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1082.a90979a4.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/6569.6299f80c.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/5398.d984bdf8.chunk.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/5398.edabcec0.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1362.0594020f.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/5349.33d4a824.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/1362.a0725ba9.chunk.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9559.52882117.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2846.dd67d512.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2179.62b3c7e9.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9486.74b2ad72.chunk.js HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/2696.fbac7eeb.chunk.css HTTP/1.1\" 200 -\n",
"127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2696.2bee98cb.chunk.js HTTP/1.1\" 200 -\n"
]
}
],
"source": [
"# Click RUN to see the output.\n",
"form.form(directory='.', view=False) "
]
],
"outputs": []
}
],
"metadata": {
Expand Down
45 changes: 1 addition & 44 deletions examples/length_converter/static/schedula/forms/index-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
}
},
"ui:onlyChildren": true,
"ui:layout": {
"component": "App",
"props": {
Expand All @@ -27,42 +28,6 @@
"global": {
"tabEnableClose": false
},
"borders": [
{
"type": "border",
"location": "left",
"enableDrop": false,
"size": 1200,
"selected": 0,
"children": [
{
"type": "tab",
"enableClose": false,
"enableDrag": false,
"enableFloat": true,
"name": "Debug",
"component": 3
}
]
},
{
"type": "border",
"location": "right",
"enableDrop": false,
"size": 400,
"selected": 0,
"children": [
{
"type": "tab",
"enableClose": false,
"enableDrag": false,
"enableFloat": false,
"name": "Errors",
"component": 2
}
]
}
],
"layout": {
"type": "row",
"children": [
Expand Down Expand Up @@ -222,14 +187,6 @@
]
}
]
},
{
"component": "Errors",
"force_render": true
},
{
"component": "Debug",
"force_render": true
}
]
}
Expand Down
8 changes: 6 additions & 2 deletions schedula/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def web(self, depth=-1, node_data=NONE, node_function=NONE, directory=None,

def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None,
sites=None, run=True, view=True, get_context=NONE, get_data=NONE,
subsite_idle_timeout=600, basic_app_config=None,
subsite_idle_timeout=600, basic_app_config=None, debug=False,
stripe_event_handler=lambda event: None):
"""
Creates a dispatcher Form Flask app.
Expand Down Expand Up @@ -171,6 +171,10 @@ def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None,
Flask app config object.
:type basic_app_config: object, optional
:param debug:
Enable debug chart backend server?
:type debug: bool, optional
:param stripe_event_handler:
Stripe event handler function.
:type stripe_event_handler: function, optional
Expand Down Expand Up @@ -201,7 +205,7 @@ def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None,
if v is not NONE:
setattr(formmap, f'_{k}', v)
if sites is not None or run or view:
site = formmap.site(view=view)
site = formmap.site(view=view, debug=debug)
site = run and not view and site.run() or site
if sites is None:
return site
Expand Down
Loading

0 comments on commit b9d2f72

Please sign in to comment.