[FIX] Fix not working code, and some cleaning proposed by AL

bzr revid: vta@openerp.com-20121226181833-kih09glellxisl9p
This commit is contained in:
vta vta@openerp.com 2012-12-26 19:18:33 +01:00
parent 78f36a2fce
commit 39e5509e6c
4 changed files with 19 additions and 36 deletions

View File

@ -656,9 +656,6 @@ class WebClient(openerpweb.Controller):
def translations(self, req, mods, lang): def translations(self, req, mods, lang):
res_lang = req.session.model('res.lang') res_lang = req.session.model('res.lang')
ids = res_lang.search([("code", "=", lang)]) ids = res_lang.search([("code", "=", lang)])
if not ids:
ids = res_lang.search([("iso_code", "=", lang)])
lang = res_lang.search_read([('id', "in", ids)], ["code"])[0]['code']
lang_params = None lang_params = None
if ids: if ids:
lang_params = res_lang.read(ids[0], ["direction", "date_format", "time_format", lang_params = res_lang.read(ids[0], ["direction", "date_format", "time_format",
@ -800,9 +797,9 @@ class Session(openerpweb.Controller):
return { return {
"session_id": req.session_id, "session_id": req.session_id,
"uid": req.session._uid, "uid": req.session._uid,
"context": req.session.get_context() if req.session._uid else {}, "user_context": req.session.get_context() if req.session._uid else {},
"db": req.session._db, "db": req.session._db,
"login": req.session._login, "username": req.session._login,
} }
@openerpweb.jsonrequest @openerpweb.jsonrequest

View File

@ -22,7 +22,7 @@ class Service(object):
def __init__(self, session, service_name): def __init__(self, session, service_name):
self.session = session self.session = session
self.service_name = service_name self.service_name = service_name
def __getattr__(self, method): def __getattr__(self, method):
def proxy_method(*args): def proxy_method(*args):
result = self.session.send(self.service_name, method, *args) result = self.session.send(self.service_name, method, *args)
@ -60,7 +60,7 @@ class OpenERPSession(object):
in a web session. in a web session.
.. attribute:: context .. attribute:: context
The session context, a ``dict``. Can be reloaded by calling The session context, a ``dict``. Can be reloaded by calling
:meth:`openerpweb.openerpweb.OpenERPSession.get_context` :meth:`openerpweb.openerpweb.OpenERPSession.get_context`
@ -80,7 +80,7 @@ class OpenERPSession(object):
self._suicide = False self._suicide = False
self.context = {} self.context = {}
self.jsonp_requests = {} # FIXME use a LRU self.jsonp_requests = {} # FIXME use a LRU
def send(self, service_name, method, *args): def send(self, service_name, method, *args):
code_string = "warning -- %s\n\n%s" code_string = "warning -- %s\n\n%s"
try: try:
@ -112,7 +112,7 @@ class OpenERPSession(object):
def authenticate(self, db, login, password, env=None): def authenticate(self, db, login, password, env=None):
uid = self.proxy('common').authenticate(db, login, password, env) uid = self.proxy('common').authenticate(db, login, password, env)
self.bind(db, uid, login, password) self.bind(db, uid, login, password)
if uid: self.get_context() if uid: self.get_context()
return uid return uid

View File

@ -1,16 +1,16 @@
/* /*
* Copyright (c) 2012, OpenERP S.A. * Copyright (c) 2012, OpenERP S.A.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -243,7 +243,7 @@ instance.web.ParentedMixin = {
/** /**
* Backbone's events. Do not ever use it directly, use EventDispatcherMixin instead. * Backbone's events. Do not ever use it directly, use EventDispatcherMixin instead.
* *
* This class just handle the dispatching of events, it is not meant to be extended, * This class just handle the dispatching of events, it is not meant to be extended,
* nor used directly. All integration with parenting and automatic unregistration of * nor used directly. All integration with parenting and automatic unregistration of
* events is done in EventDispatcherMixin. * events is done in EventDispatcherMixin.
@ -303,7 +303,7 @@ var Events = instance.web.Class.extend({
}); });
return lst; return lst;
}, },
trigger : function(events) { trigger : function(events) {
var event, node, calls, tail, args, all, rest; var event, node, calls, tail, args, all, rest;
if (!(calls = this._callbacks)) if (!(calls = this._callbacks))
@ -1043,7 +1043,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
id: payload.id, id: payload.id,
sid: this.httpsessionid, sid: this.httpsessionid,
}; };
var set_sid = function (response, textStatus, jqXHR) { var set_sid = function (response, textStatus, jqXHR) {
// If response give us the http session id, we store it for next requests... // If response give us the http session id, we store it for next requests...
if (response.httpsessionid) { if (response.httpsessionid) {
@ -1054,7 +1054,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
url.url = this.url(url.url, null); url.url = this.url(url.url, null);
var ajax = _.extend({ var ajax = _.extend({
type: "GET", type: "GET",
dataType: 'jsonp', dataType: 'jsonp',
jsonp: 'jsonp', jsonp: 'jsonp',
cache: false, cache: false,
data: data data: data

View File

@ -49,7 +49,6 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
_(this.module_list).each(function (mod) { _(this.module_list).each(function (mod) {
self.module_loaded[mod] = true; self.module_loaded[mod] = true;
}); });
this.context = {};
this.active_id = null; this.active_id = null;
return this.session_init(); return this.session_init();
}, },
@ -67,7 +66,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
return deferred.then(function() { return self.load_modules(); }); return deferred.then(function() { return self.load_modules(); });
} }
return $.when( return $.when(
deferred, deferred,
self.rpc('/web/webclient/bootstrap_translations', {mods: instance._modules}).then(function(trans) { self.rpc('/web/webclient/bootstrap_translations', {mods: instance._modules}).then(function(trans) {
instance.web._t.database.set_bundle(trans); instance.web._t.database.set_bundle(trans);
}) })
@ -86,13 +85,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
// If immediately follows a login (triggered by trying to restore // If immediately follows a login (triggered by trying to restore
// an invalid session or no session at all), refresh session data // an invalid session or no session at all), refresh session data
// (should not change, but just in case...) // (should not change, but just in case...)
_.extend(self, { _.extend(self,result);
session_id: result.session_id,
db: result.db,
username: result.login,
uid: result.uid,
user_context: result.context
});
}); });
}, },
session_is_valid: function() { session_is_valid: function() {
@ -109,14 +102,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
if (!result.uid) { if (!result.uid) {
return $.Deferred().reject(); return $.Deferred().reject();
} }
_.extend(self, result);
_.extend(self, {
session_id: result.session_id,
db: result.db,
username: result.login,
uid: result.uid,
user_context: result.context
});
if (!_volatile) { if (!_volatile) {
self.set_cookie('session_id', self.session_id); self.set_cookie('session_id', self.session_id);
} }