cherryext/orun/extjs/cp.py

71 lines
2.1 KiB
Python
Raw Normal View History

2013-04-30 09:49:34 +04:00
import os
from orun.extjs import *
from orun.servers import cp
2018-08-08 10:08:17 +03:00
import cherrypy
2018-08-17 12:14:11 +03:00
THEME_MODEL = 'classic'
2018-08-08 10:08:17 +03:00
THEME = 'gray'
2018-08-22 21:34:00 +03:00
CHART_THEME_MODEL = 'classic/classic' if THEME_MODEL == 'classic' else 'modern/modern-' + THEME
2018-08-08 10:08:17 +03:00
2018-08-17 21:06:07 +03:00
BASE_URL = ''
2018-08-22 21:48:07 +03:00
ENABLE_CHARTS=False
CHART_HTML_CODE = '''<script type="text/javascript" src="{base_url}/ext_620/packages/charts/{theme_model}/charts.js"></script>
<link rel="stylesheet" type="text/css" href="{base_url}/ext_620/packages/charts/{chart_theme_model}/resources/charts-all.css">
'''.format(base_url=BASE_URL,
theme_model=THEME_MODEL,
chart_theme_model=CHART_THEME_MODEL) if ENABLE_CHARTS else ''
EXTJS_PACKAGES = '' + CHART_HTML_CODE
2018-08-08 10:08:17 +03:00
@cherrypy.expose
class ExtJS:
2018-08-08 10:08:17 +03:00
_cp_config = {
'tools.staticdir.on': True,
2018-08-17 12:14:11 +03:00
'tools.staticdir.dir': os.path.join(os.path.dirname(__file__), 'static','ext-6.2.0'),
}
2013-04-30 09:49:34 +04:00
class ExtApplication(cp.Application):
2018-08-08 10:08:17 +03:00
def __init__(self, title=''):
super(ExtApplication, self).__init__(title)
2018-08-17 12:14:11 +03:00
self.ext_620 = ExtJS()
2018-08-08 10:08:17 +03:00
2018-08-16 17:49:28 +03:00
@cherrypy.expose
2013-04-30 09:49:34 +04:00
def index(self, *args, **kwargs):
f = open(os.path.join(os.path.dirname(__file__), 'app.html')).read()
self.main()
2018-08-22 21:37:01 +03:00
return f.format(title=self.title,
base_url=BASE_URL,
theme=THEME,
theme_model=THEME_MODEL,
script=str(js.js_manager),
2018-08-22 21:48:07 +03:00
packages=EXTJS_PACKAGES)
2013-04-30 09:49:34 +04:00
2018-08-16 17:49:28 +03:00
@cherrypy.expose
2013-04-30 09:49:34 +04:00
def ajax_callback(self, *args, **kwargs):
fn = kwargs.pop('fn')
if fn:
2018-08-16 19:27:06 +03:00
fn = js.live_methods[int(fn)].func
2013-04-30 09:49:34 +04:00
fn(*args, **kwargs)
return str(js.js_manager)
2018-08-16 17:49:28 +03:00
@cherrypy.expose
@cp.cherrypy.tools.json_out()
def ajax_func_callback(self, *args, **kwargs):
fn = kwargs.pop('fn')
if fn:
2018-08-16 19:27:06 +03:00
fn = js.live_methods[int(fn)].func
2018-08-16 17:49:28 +03:00
res = fn(*args, **kwargs)
return {
'data': res
}
else:
return {
'data': None
}
2013-04-30 09:49:34 +04:00
if __name__ == '__main__':
app = ExtApplication('Orun (ExtJS Application)')
app.run()