[IMP] Use qweb template for login and webclient bootstrap

The database manager should be rewritten server side

bzr revid: fme@openerp.com-20140109151140-8x3ia8zpdpw1lics
This commit is contained in:
Fabien Meghazi 2014-01-09 16:11:40 +01:00
parent b42fc403cb
commit 0058291979
4 changed files with 127 additions and 51 deletions

View File

@ -12,7 +12,10 @@ This module provides the core of the OpenERP Web Client.
'depends': ['base'],
'auto_install': True,
'post_load': 'wsgi_postload',
'js' : [
'data': [
'views/webclient_templates.xml',
],
'js': [
"static/lib/es5-shim/es5-shim.min.js",
"static/lib/datejs/globalization/en-US.js",
"static/lib/datejs/core.js",

View File

@ -532,7 +532,8 @@ def content_disposition(filename):
# OpenERP Web web Controllers
#----------------------------------------------------------
# TODO: obsoleted by webclient_bootstrap() but need to change edi and pos addons before removing this
# TODO: to remove once the database manager has been migrated server side
# and `edi` + `pos` addons has been adapted to use render_bootstrap_template()
html_template = """<!DOCTYPE html>
<html style="height: 100%%">
<head>
@ -559,38 +560,45 @@ html_template = """<!DOCTYPE html>
</html>
"""
def webclient_bootstrap(**options):
# `options` can contain `client_options` dict. See chrome.js for more information about client_options.
def render_bootstrap_template(db, template, values=None, **kw):
if values is None:
values = {}
values.update(kw)
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 res not in values:
values[res] = manifest_list(res, db=db, debug=values.get('debug', request.debug))
if 'modules' not in options:
options['modules'] = module_boot(db=options.get('db'))
if 'modules' not in values:
values['modules'] = module_boot(db=db)
values['modules'] = simplejson.dumps(values['modules'])
return env.get_template("webclient_bootstrap.html").render(options)
registry = openerp.modules.registry.RegistryManager.get(db)
with registry.cursor() as cr:
view_obj = registry["ir.ui.view"]
return view_obj.render(cr, openerp.SUPERUSER_ID, template, values)
class Home(http.Controller):
@http.route('/', type='http', auth="none")
def index(self, s_action=None, db=None, debug=False, **kw):
return redirect_with_hash('web', keep_query=True)
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):
debug = debug is not False # we just check presence of `debug` query param
# if db not provided, use the session one
if db is None:
if not db:
db = request.session.db
# if no database provided and no database in session, use monodb
if db is None:
if not db:
db = http.db_monodb(request.httprequest)
# 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:
if not db:
return redirect_with_hash('/web/database/selector', keep_query=['debug'])
# always switch the session to the computed db
@ -598,8 +606,22 @@ class Home(http.Controller):
request.session.logout()
request.session.db = db
html = webclient_bootstrap(db=db, debug=debug)
return request.make_response(html, {'Cache-Control': 'no-cache', 'Content-Type': 'text/html; charset=utf-8'})
if request.session.uid:
html = render_bootstrap_template(db, "web.webclient_bootstrap")
return request.make_response(html, {'Cache-Control': 'no-cache', 'Content-Type': 'text/html; charset=utf-8'})
else:
return redirect_with_hash('/web/login', keep_query=True)
@http.route('/web/login', type='http', auth="none")
def web_login(self, **kw):
assert request.session.db is not None
values = request.params.copy()
if request.httprequest.method == 'POST':
uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
if uid is not False:
return set_cookie_and_redirect('/web')
values['authentication_failed'] = True
return render_bootstrap_template(request.session.db, 'web.login', values)
@http.route('/login', type='http', auth="none")
def login(self, db, login, key):
@ -787,10 +809,19 @@ class Database(http.Controller):
@http.route('/web/database/manager', type='http', auth="none")
def manager(self, debug=False):
debug = debug is not False # we just check presence of `debug` query param
options = {
'action': 'database_manager'
js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', debug=debug))
css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', debug=debug))
r = html_template % {
'js': js,
'css': css,
'modules': simplejson.dumps(module_boot()),
'init': """
var wc = new s.web.WebClient(null, { action: 'database_manager' });
wc.appendTo($(document.body));
"""
}
return webclient_bootstrap(client_options=options)
return r
@http.route('/web/database/get_list', type='json', auth="none")
def get_list(self):

View File

@ -1,33 +0,0 @@
<!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 %}null, {{ 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>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="web.layout" name="Web layout">&lt;!DOCTYPE html&gt;
<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" />
<t t-foreach="css" t-as="css_file">
<link rel="stylesheet" t-att-href="css_file"/>
</t>
<t t-foreach="js" t-as="js_file">
<script type="text/javascript" t-att-src="js_file"></script>
</t>
<t t-raw="head or ''"/>
</head>
<body>
<t t-raw="0"/>
</body>
</html>
</template>
<template id="web.webclient_bootstrap" name="Webclient Bootstrap">
<t t-call="web.layout">
<t t-set="head">
<script type="text/javascript">
$(function() {
var s = new openerp.init(<t t-raw="modules"/>);
<t t-if="init">
<t t-raw="init"/>
</t>
<t t-if="not init">
var wc = new s.web.WebClient();
wc.appendTo($(document.body));
</t>
});
</script>
</t>
</t>
</template>
<template id="web.login" name="Login">
<t t-call="web.layout">
<div class="row">
<div class="col-md-4"> </div>
<div class="col-md-4">
<img src="/web/static/src/img/logo2.png"/>
<form role="form" action="/web/login" method="post">
<div class="form-group">
<label for="login">Login</label>
<input type="text" name="login" t-att-value="login" id="login" class="form-control" placeholder="Enter login" required="required" autofocus="autofocus"/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Password" required="required"/>
</div>
<button type="submit" class="btn btn-default">Log in</button>
<p class="alert alert-danger" t-if="authentication_failed">
Wrong login/password
</p>
</form>
</div>
<div class="col-md-4"> </div>
</div>
</t>
</template>
</data>
</openerp>