Merge lp:~openerp-dev/openerp-web/7.0-monodb-again-fme into lp:openerp-web/7.0

Proposed by Christophe Simonis (OpenERP)
Status: Rejected
Rejected by: Xavier (Open ERP)
Proposed branch: lp:~openerp-dev/openerp-web/7.0-monodb-again-fme
Merge into: lp:openerp-web/7.0
Diff against target: 112 lines (+14/-35)
2 files modified
addons/web/controllers/main.py (+13/-28)
addons/web/static/src/js/chrome.js (+1/-7)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/7.0-monodb-again-fme
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Needs Information
Review via email: mp+159115@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Why?

review: Needs Information

Unmerged revisions

3853. By Fabien Meghazi (OpenERP)

[IMP] Hard code instance._selected_db in template

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'addons/web/controllers/main.py'
--- addons/web/controllers/main.py 2013-04-05 13:47:47 +0000
+++ addons/web/controllers/main.py 2013-04-16 09:52:29 +0000
@@ -93,14 +93,8 @@
93 dbs = [i for i in dbs if re.match(r, i)]93 dbs = [i for i in dbs if re.match(r, i)]
94 return dbs94 return dbs
9595
96def db_monodb_redirect(req):96def db_monodb(req):
97 db = False97 db = False
98 redirect = False
99
100 # 1 try the db in the url
101 db_url = req.params.get('db')
102 if db_url:
103 return (db_url, False)
10498
105 try:99 try:
106 dbs = db_list(req)100 dbs = db_list(req)
@@ -108,25 +102,18 @@
108 # ignore access denied102 # ignore access denied
109 dbs = []103 dbs = []
110104
111 # 2 use the database from the cookie if it's listable and still listed105 # 1 try the db in the url
112 cookie_db = req.httprequest.cookies.get('last_used_database')106 db = req.params.get('db')
113 if cookie_db in dbs:107
114 db = cookie_db108 # 2 try the db in the cookie
115109 if not db:
116 # 3 use the first db110 db = req.httprequest.cookies.get('last_used_database')
117 if dbs and not db:111
112 # 3 use the first db, ensure db is listed
113 if dbs and db not in dbs:
118 db = dbs[0]114 db = dbs[0]
119115
120 # redirect to the chosen db if multiple are available116 return db
121 if db and len(dbs) > 1:
122 query = dict(urlparse.parse_qsl(req.httprequest.query_string, keep_blank_values=True))
123 query.update({ 'db': db })
124 redirect = req.httprequest.path + '?' + urllib.urlencode(query)
125 return (db, redirect)
126
127def db_monodb(req):
128 # if only one db exists, return it else return False
129 return db_monodb_redirect(req)[0]
130117
131def redirect_with_hash(req, url, code=303):118def redirect_with_hash(req, url, code=303):
132 if req.httprequest.user_agent.browser == 'msie':119 if req.httprequest.user_agent.browser == 'msie':
@@ -551,6 +538,7 @@
551 <script type="text/javascript">538 <script type="text/javascript">
552 $(function() {539 $(function() {
553 var s = new openerp.init(%(modules)s);540 var s = new openerp.init(%(modules)s);
541 s._selected_db = %(db)s;
554 %(init)s542 %(init)s
555 });543 });
556 </script>544 </script>
@@ -569,14 +557,11 @@
569557
570 @openerpweb.httprequest558 @openerpweb.httprequest
571 def index(self, req, s_action=None, db=None, **kw):559 def index(self, req, s_action=None, db=None, **kw):
572 db, redir = db_monodb_redirect(req)
573 if redir:
574 return redirect_with_hash(req, redir)
575
576 js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, 'js', db=db))560 js = "\n ".join('<script type="text/javascript" src="%s"></script>' % i for i in manifest_list(req, 'js', db=db))
577 css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, 'css', db=db))561 css = "\n ".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list(req, 'css', db=db))
578562
579 r = html_template % {563 r = html_template % {
564 'db': simplejson.dumps(db_monodb(req)),
580 'js': js,565 'js': js,
581 'css': css,566 'css': css,
582 'modules': simplejson.dumps(module_boot(req, db=db)),567 'modules': simplejson.dumps(module_boot(req, db=db)),
583568
=== modified file 'addons/web/static/src/js/chrome.js'
--- addons/web/static/src/js/chrome.js 2013-03-19 15:43:45 +0000
+++ addons/web/static/src/js/chrome.js 2013-04-16 09:52:29 +0000
@@ -603,7 +603,7 @@
603 this._super(parent);603 this._super(parent);
604 this.has_local_storage = typeof(localStorage) != 'undefined';604 this.has_local_storage = typeof(localStorage) != 'undefined';
605 this.db_list = null;605 this.db_list = null;
606 this.selected_db = null;606 this.selected_db = instance._selected_db;
607 this.selected_login = null;607 this.selected_login = null;
608 this.params = action.params || {};608 this.params = action.params || {};
609 if (_.isEmpty(this.params)) {609 if (_.isEmpty(this.params)) {
@@ -614,9 +614,6 @@
614 } else if ($.deparam.querystring().db) {614 } else if ($.deparam.querystring().db) {
615 this.params.db = $.deparam.querystring().db;615 this.params.db = $.deparam.querystring().db;
616 }616 }
617 if (this.params.db) {
618 this.selected_db = this.params.db;
619 }
620617
621 if (this.params.login_successful) {618 if (this.params.login_successful) {
622 this.on('login_successful', this, this.params.login_successful);619 this.on('login_successful', this, this.params.login_successful);
@@ -674,9 +671,6 @@
674 on_db_loaded: function (result) {671 on_db_loaded: function (result) {
675 var self = this;672 var self = this;
676 this.db_list = result;673 this.db_list = result;
677 if (!this.selected_db) {
678 this.selected_db = result[0];
679 }
680 this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db}));674 this.$("[name=db]").replaceWith(QWeb.render('Login.dblist', { db_list: this.db_list, selected_db: this.selected_db}));
681 if(this.db_list.length === 0) {675 if(this.db_list.length === 0) {
682 this.do_action("database_manager");676 this.do_action("database_manager");