[IMP] Database selector and manager

bzr revid: fme@openerp.com-20131219143648-5jvlcet3yjsw6vq6
This commit is contained in:
Fabien Meghazi 2013-12-19 15:36:48 +01:00
parent 6754d72a93
commit da780aa478
3 changed files with 131 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import csv
import functools
import glob
import itertools
import jinja2
import logging
import operator
import datetime
@ -40,6 +41,12 @@ from openerp.http import request, serialize_exception as _serialize_exception
_logger = logging.getLogger(__name__)
env = jinja2.Environment(
loader=jinja2.PackageLoader('openerp.addons.web', "views"),
autoescape=True
)
env.filters["json"] = simplejson.dumps
#----------------------------------------------------------
# OpenERP Web helpers
#----------------------------------------------------------
@ -108,8 +115,19 @@ def serialize_exception(f):
return werkzeug.exceptions.InternalServerError(simplejson.dumps(error))
return wrap
def redirect_with_hash(url, code=303):
if request.httprequest.user_agent.browser in ('msie', 'safari'):
def redirect_with_hash(path, keep_query=None, exclude_query=[], code=303):
url = path
if keep_query:
query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True))
for key in exclude_query:
query.pop(key, None)
if hasattr(keep_query, '__iter__'):
for key in query.keys():
if key not in keep_query:
query.pop(key)
url = path + '?' + urllib.urlencode(query)
if request.httprequest.user_agent.browser in ('msie', 'safari'):
# Most IE and Safari versions decided not to preserve location.hash upon
# redirect. And even if IE10 pretends to support it, it still fails
# inexplicably in case of multiple redirects (and we do have some).
@ -514,6 +532,7 @@ def content_disposition(filename):
# OpenERP Web web Controllers
#----------------------------------------------------------
# TODO: obsoleted by webclient_bootstrap() but need to change edi and pos addons
html_template = """<!DOCTYPE html>
<html style="height: 100%%">
<head>
@ -540,13 +559,21 @@ html_template = """<!DOCTYPE html>
</html>
"""
def webclient_bootstrap(**options):
for res in ['js', 'css']:
if res not in options:
options[res] = manifest_list(res, db=options.get('db'), debug=options.get('debug', request.debug))
if 'modules' not in options:
options['modules'] = module_boot(db=options.get('db'))
return env.get_template("webclient_bootstrap.html").render(options)
class Home(http.Controller):
@http.route('/', type='http', auth="none")
def index(self, s_action=None, db=None, debug=False, **kw):
query = dict(urlparse.parse_qsl(request.httprequest.query_string, keep_blank_values=True))
redirect = '/web' + '?' + urllib.urlencode(query)
return redirect_with_hash(redirect)
return redirect_with_hash('web', keep_query=True)
@http.route('/web', type='http', auth="none")
def web_client(self, s_action=None, db=None, debug=False, **kw):
@ -563,7 +590,7 @@ class Home(http.Controller):
# if no db can be found til here, send to the database selector
# the database selector will redirect to database manager if needed
if db is None:
return request.redirect('/database/selector', 303) # TODO: check status code semantic and forward debug
return redirect_with_hash('/web/database/selector', keep_query=['debug'])
# always switch the session to the computed db
if db != request.session.db:
@ -753,6 +780,22 @@ class Proxy(http.Controller):
class Database(http.Controller):
@http.route('/web/database/selector', type='http', auth="none")
def selector(self, debug=False):
dbs = http.db_list(True)
if not dbs:
return redirect_with_hash('/web/database/manager', keep_query=['debug'])
return env.get_template("database_selector.html").render({
'databases': dbs
})
@http.route('/web/database/manager', type='http', auth="none")
def manager(self, debug=False):
options = {
'action': 'database_manager'
}
return webclient_bootstrap(client_options=options)
@http.route('/web/database/get_list', type='json', auth="none")
def get_list(self):
# TODO change js to avoid calling this method if in monodb mode

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>OpenERP</title>
<link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/web/static/src/css/full.css">
<link rel="stylesheet" href="/web/static/lib/fontawesome/css/font-awesome.css">
<link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="/web/static/src/css/base.css">
<body>
<div class="openerp openerp_webclient_container">
<table class="oe_webclient">
<tr>
<td>
<div class="oe_login">
<div class="oe_login_bottom"> </div>
<div class="oe_login_pane" style="top: 60%">
<div class="oe_login_logo"><img src="/web/static/src/img/logo2.png" alt="OpenERP"></div>
<form action="/web" method="get">
<ul>
<li>Select database</li>
<li>
<select name="db">
<option></option>
{% for db in databases %}
<option value="{{ db }}">{{ db }}</option>
{% endfor %}
</select>
</li>
<li class="pull-right" style="margin-top: 20px">
<button name="submit">Continue</button>
</li>
</ul>
</form>
<div class="oe_login_footer">
<a class="oe_login_manage_db" href="#" data-modes="default">Manage Databases</a> |
<a href="http://www.openerp.com" target="_blank">Powered by <span>OpenERP</span></a>
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html style="height: 100%%">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>OpenERP</title>
<link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="/web/static/src/css/full.css" />
{% for css_file in css %}
<link rel="stylesheet" href="{{ css_file }}">
{% endfor %}
{% for js_file in js %}
<script type="text/javascript" src="{{ js_file }}"></script>
{% endfor %}
<script type="text/javascript">
$(function() {
var s = new openerp.init({{ modules | json | safe }});
{% if init %}
{{ init }}
{% else %}
var wc = new s.web.WebClient({% if client_options %}{{ client_options | json | safe }}{% endif %});
wc.appendTo($(document.body));
{% endif %}
});
</script>
</head>
<body>
<!--[if lte IE 8]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>CFInstall.check({mode: "overlay"});</script>
<![endif]-->
</body>
</html>