Commit 263e4714 authored by Jérome Perrin's avatar Jérome Perrin

erp5_sql_browser: various fixes

* support Decimal returned by database
* hide "presets" until it is implemented
* display autocomplete above of handsontable
parent f3642b2f
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>import datetime\n <value> <string>#from decimal import Decimal\n
import datetime\n
import json\n import json\n
from DateTime import DateTime\n from DateTime import DateTime\n
\n \n
...@@ -64,7 +65,7 @@ except Exception, e:\n ...@@ -64,7 +65,7 @@ except Exception, e:\n
response.setStatus(500)\n response.setStatus(500)\n
try:\n try:\n
response.write(str(e[1]))\n response.write(str(e[1]))\n
except Exception, _:\n except Exception:\n
response.write(str(e))\n response.write(str(e))\n
return\n return\n
\n \n
...@@ -75,51 +76,15 @@ for line in data[1:]:\n ...@@ -75,51 +76,15 @@ for line in data[1:]:\n
for v in line:\n for v in line:\n
if isinstance(v, DateTime):\n if isinstance(v, DateTime):\n
v = v.ISO()\n v = v.ISO()\n
if isinstance(v, datetime.datetime):\n elif isinstance(v, datetime.datetime):\n
v = v.isoformat()\n v = v.isoformat()\n
elif "Decimal" in repr(v): # XXX decimal is not allowed in restricted environment\n
v = float(v)\n
new_line.append(v)\n new_line.append(v)\n
new_data.append(new_line)\n new_data.append(new_line)\n
\n \n
response.setHeader(\'Content-Type\', \'application/json\')\n response.setHeader(\'Content-Type\', \'application/json\')\n
return json.dumps(new_data, indent=2)\n return json.dumps(new_data, indent=2)\n
\n
\n
\n
\n
\n
\n
import datetime\n
import json\n
from DateTime import DateTime\n
\n
response = container.REQUEST.RESPONSE\n
\n
try:\n
results = context.manage_test(query)\n
data = [ results.names() ]\n
data.extend(results.dictionaries())\n
except Exception, e:\n
response.setStatus(500)\n
try:\n
response.write(str(e[1]))\n
except Exception, _:\n
response.write(str(e))\n
return\n
\n
# handle non JSON serializable data\n
new_data = [data[0]]\n
for line in data[1:]:\n
new_line = {}\n
for k, v in line.items():\n
if isinstance(v, DateTime):\n
v = v.ISO()\n
if isinstance(v, datetime.datetime):\n
v = v.isoformat()\n
line[k] = v#new_line.append(v)\n
new_data.append(line)\n
\n
response.setHeader(\'Content-Type\', \'application/json\')\n
return json.dumps(new_data, indent=2)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts34503950.54</string> </value> <value> <string>ts34602970.42</string> </value>
</item> </item>
<item> <item>
<key> <string>__name__</string> </key> <key> <string>__name__</string> </key>
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
\n \n
<style>\n <style>\n
.CodeMirror {height: 80px;}\n .CodeMirror {height: 80px;}\n
.CodeMirror-hints {z-index: 100;} /* above handsontable header */\n
body {font-family: Verdana;}\n body {font-family: Verdana;}\n
.c3-line {stroke-width: 3px;}\n .c3-line {stroke-width: 3px;}\n
.c3 circle {stroke: white;}\n .c3 circle {stroke: white;}\n
...@@ -168,15 +169,16 @@ ...@@ -168,15 +169,16 @@
});\n });\n
});\n });\n
</script>\n </script>\n
\n <!--\n
Presets: <select id="presets"><option selected="selected" value=""></option></select>\n Presets: <select id="presets"><option selected="selected" value=""></option></select>\n
<button name="Save">Save Preset</button>\n <button name="Save">Save Preset</button>\n
<br/>\n <br/>\n
<textarea name="query" id="query"></textarea>\n -->\n
<textarea name="query" id="query"></textarea>\n
<button name="Query">Run Query</button>\n <button name="Query">Run Query</button>\n
\n \n
\n \n
<div id="table_container" style="margin: 10px; height: 300px; overflow: hidden"></div>\n <div id="table_container" style="margin: 10px; height: 300px; overflow: hidden; z-index: -1;"></div>\n
<div id="output" style="margin: 10px;"></div>\n <div id="output" style="margin: 10px;"></div>\n
\n \n
<!-- TODO: debug saved configuration -->\n <!-- TODO: debug saved configuration -->\n
...@@ -197,7 +199,7 @@ ...@@ -197,7 +199,7 @@
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>6813</int> </value> <value> <int>6903</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment