Skip to content

Commit

Permalink
[FIX] Merge fix in saas1 for the problem that made the server crash w…
Browse files Browse the repository at this point in the history
…hen install a db

bzr revid: nicolas.vanhoren@openerp.com-20130610144915-0nj8vpk7n84ocj3f
bzr revid: nicolas.vanhoren@openerp.com-20130610150657-3xddn91gm0iq0ubp
bzr revid: nicolas.vanhoren@openerp.com-20130610154514-oee6s4f9g17bx63z
  • Loading branch information
nicolas-van committed Jun 10, 2013
2 parents 901ba0c + 02aa3f2 commit a94bbf8
Show file tree
Hide file tree
Showing 40 changed files with 255 additions and 269 deletions.
4 changes: 3 additions & 1 deletion addons/web/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
'name': 'Web',
'category': 'Hidden',
'version': '7.0.1.0',
'version': '1.0',
'description':
"""
OpenERP Web core module.
Expand All @@ -13,6 +13,7 @@
'auto_install': True,
'post_load': 'wsgi_postload',
'js' : [
"static/src/fixbind.js",
"static/lib/datejs/globalization/en-US.js",
"static/lib/datejs/core.js",
"static/lib/datejs/parser.js",
Expand Down Expand Up @@ -76,6 +77,7 @@
"static/test/class.js",
"static/test/registry.js",
"static/test/form.js",
"static/test/data.js",
"static/test/list-utils.js",
"static/test/formats.js",
"static/test/rpc.js",
Expand Down
32 changes: 19 additions & 13 deletions addons/web/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def fs2web(path):
"""convert FS path into web path"""
return '/'.join(path.split(os.path.sep))

def manifest_glob(extension, addons=None, db=None):
def manifest_glob(extension, addons=None, db=None, include_remotes=False):
if addons is None:
addons = module_boot(db=db)
else:
Expand All @@ -324,23 +324,29 @@ def manifest_glob(extension, addons=None, db=None):
addons_path = os.path.join(manifest['addons_path'], '')[:-1]
globlist = manifest.get(extension, [])
for pattern in globlist:
for path in glob.glob(os.path.normpath(os.path.join(addons_path, addon, pattern))):
r.append((path, fs2web(path[len(addons_path):])))
if pattern.startswith(('http://', 'https://', '//')):
if include_remotes:
r.append((None, pattern))
else:
for path in glob.glob(os.path.normpath(os.path.join(addons_path, addon, pattern))):
r.append((path, fs2web(path[len(addons_path):])))
return r

def manifest_list(extension, mods=None, db=None):
""" list ressources to load specifying either:
mods: a comma separated string listing modules
db: a database name (return all installed modules in that database)
"""
files = manifest_glob(extension, addons=mods, db=db, include_remotes=True)
if not req.debug:
path = '/web/webclient/' + extension
if mods is not None:
path += '?' + urllib.urlencode({'mods': mods})
elif db:
path += '?' + urllib.urlencode({'db': db})
return [path]
files = manifest_glob(extension, addons=mods, db=db)

remotes = [wp for fp, wp in files if fp is None]
return [path] + remotes
return [wp for _fp, wp in files]

def get_last_modified(files):
Expand Down Expand Up @@ -1204,19 +1210,19 @@ def image(self, model, id, field, **kw):
headers = [('Content-Type', 'image/png')]
etag = req.httprequest.headers.get('If-None-Match')
hashed_session = hashlib.md5(req.session_id).hexdigest()
retag = hashed_session
id = None if not id else simplejson.loads(id)
if type(id) is list:
id = id[0] # m2o
if etag:
if not id and hashed_session == etag:
return werkzeug.wrappers.Response(status=304)
else:
date = Model.read([id], [last_update], req.context)[0].get(last_update)
if hashlib.md5(date).hexdigest() == etag:
try:
if etag:
if not id and hashed_session == etag:
return werkzeug.wrappers.Response(status=304)
else:
date = Model.read([id], [last_update], req.context)[0].get(last_update)
if hashlib.md5(date).hexdigest() == etag:
return werkzeug.wrappers.Response(status=304)

retag = hashed_session
try:
if not id:
res = Model.default_get([field], req.context).get(field)
image_base64 = res
Expand Down
21 changes: 16 additions & 5 deletions addons/web/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def init(self, params):
# we use _ as seprator where RFC2616 uses '-'
self.lang = lang.replace('-', '_')

@contextlib.contextmanager
def registry_cr(self):
dbname = self.session._db or openerp.addons.web.controllers.main.db_monodb(self)
registry = openerp.modules.registry.RegistryManager.get(dbname.lower())
with registry.cursor() as cr:
yield (registry, cr)

def reject_nonliteral(dct):
if '__ref' in dct:
raise ValueError(
Expand Down Expand Up @@ -298,6 +305,8 @@ def dispatch(self, method):
#_logger.debug("%s --> %s.%s %r", self.httprequest.method, method.im_class.__name__, method.__name__, akw)
try:
r = method(**self.params)
except werkzeug.exceptions.HTTPException, e:
r = e
except Exception, e:
_logger.exception("An exception occured during an http request")
se = serialize_exception(e)
Expand All @@ -307,11 +316,13 @@ def dispatch(self, method):
'data': se
}
r = werkzeug.exceptions.InternalServerError(cgi.escape(simplejson.dumps(error)))
if self.debug or 1:
if isinstance(r, (werkzeug.wrappers.BaseResponse, werkzeug.exceptions.HTTPException)):
_logger.debug('<-- %s', r)
else:
_logger.debug("<-- size: %s", len(r))
else:
if not r:
r = werkzeug.wrappers.Response(status=204) # no content
if isinstance(r, (werkzeug.wrappers.BaseResponse, werkzeug.exceptions.HTTPException)):
_logger.debug('<-- %s', r)
else:
_logger.debug("<-- size: %s", len(r))
return r

def make_response(self, data, headers=None, cookies=None):
Expand Down
43 changes: 39 additions & 4 deletions addons/web/static/src/js/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,7 @@ instance.web.Menu = instance.web.Widget.extend({
self.reflow();
// launch the fetch of needaction counters, asynchronous
if (!_.isEmpty(menu_data.all_menu_ids)) {
this.rpc("/web/menu/load_needaction", {menu_ids: menu_data.all_menu_ids}).done(function(r) {
self.on_needaction_loaded(r);
});
this.do_load_needaction(menu_data.all_menu_ids);
}
});
var lazyreflow = _.debounce(this.reflow.bind(this), 200);
Expand All @@ -941,7 +939,7 @@ instance.web.Menu = instance.web.Widget.extend({
this.data = {data: data};
this.renderElement();
this.$secondary_menus.html(QWeb.render("Menu.secondary", { widget : this }));
this.$el.on('click', 'a[data-menu]', this.on_menu_click);
this.$el.on('click', 'a[data-menu]', this.on_top_menu_click);
// Hide second level submenus
this.$secondary_menus.find('.oe_menu_toggler').siblings('.oe_secondary_submenu').hide();
if (self.current_menu) {
Expand All @@ -950,6 +948,16 @@ instance.web.Menu = instance.web.Widget.extend({
this.trigger('menu_loaded', data);
this.has_been_loaded.resolve();
},
do_load_needaction: function (menu_ids) {
var self = this;
menu_ids = _.reject(menu_ids, _.isEmpty);
if (_.isEmpty(menu_ids)) {
return $.when();
}
return this.rpc("/web/menu/load_needaction", {'menu_ids': menu_ids}).done(function(r) {
self.on_needaction_loaded(r);
});
},
on_needaction_loaded: function(data) {
var self = this;
this.needaction_data = data;
Expand Down Expand Up @@ -1081,11 +1089,38 @@ instance.web.Menu = instance.web.Widget.extend({
}
this.open_menu(id);
},
do_reload_needaction: function () {
var self = this;
if (self.current_menu) {
self.do_load_needaction([self.current_menu]).then(function () {
self.trigger("need_action_reloaded");
});
}
},
/**
* Jquery event handler for menu click
*
* @param {Event} ev the jquery event
*/
on_top_menu_click: function(ev) {
var self = this;
var id = $(ev.currentTarget).data('menu');
var menu_ids = [id];
var menu = _.filter(this.data.data.children, function (menu) {return menu.id == id;})[0];
function add_menu_ids (menu) {
if (menu.children) {
_.each(menu.children, function (menu) {
menu_ids.push(menu.id);
add_menu_ids(menu);
});
}
};
add_menu_ids(menu);
self.do_load_needaction(menu_ids).then(function () {
self.trigger("need_action_reloaded");
});
this.on_menu_click(ev);
},
on_menu_click: function(ev) {
ev.preventDefault();
var needaction = $(ev.target).is('div.oe_menu_counter');
Expand Down
3 changes: 2 additions & 1 deletion addons/web/static/src/js/corelib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
}
qs = '?' + $.param(params);
}
return this.prefix + path + qs;
var prefix = _.any(['http://', 'https://', '//'], _.bind(_.str.startsWith, null, path)) ? '' : this.prefix;
return prefix + path + qs;
},
});

Expand Down
19 changes: 18 additions & 1 deletion addons/web/static/src/js/view_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
this.ViewManager = parent;
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
Expand Down Expand Up @@ -720,6 +721,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
return this.save().done(function(result) {
self.trigger("save", result);
self.to_view_mode();
}).then(function(result) {
self.ViewManager.ActionManager.__parentedParent.menu.do_reload_needaction();
});
},
on_button_cancel: function(event) {
Expand Down Expand Up @@ -2901,7 +2904,7 @@ instance.web.form.FieldRadio = instance.web.form.AbstractField.extend(instance.w
var domain = instance.web.pyeval.eval('domain', this.build_domain()) || [];
if (! _.isEqual(self.domain, domain)) {
self.domain = domain;
var ds = new instance.web.DataSet(self, self.field.relation);
var ds = new instance.web.DataSetStatic(self, self.field.relation, self.build_context());
ds.call('search', [self.domain])
.then(function (records) {
ds.name_get(records).then(function (records) {
Expand Down Expand Up @@ -3151,6 +3154,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
instance.web.form.CompletionFieldMixin.init.call(this);
this.set({'value': false});
this.display_value = {};
this.display_value_backup = {};
this.last_search = [];
this.floating = false;
this.current_display = null;
Expand Down Expand Up @@ -3234,6 +3238,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
);
pop.on('write_completed', self, function(){
self.display_value = {};
self.display_value_backup = {};
self.render_value();
self.focus();
});
Expand Down Expand Up @@ -3284,6 +3289,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
if (self.last_search.length > 0) {
if (self.last_search[0][0] != self.get("value")) {
self.display_value = {};
self.display_value_backup = {};
self.display_value["" + self.last_search[0][0]] = self.last_search[0][1];
self.reinit_value(self.last_search[0][0]);
} else {
Expand Down Expand Up @@ -3349,6 +3355,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
var item = ui.item;
if (item.id) {
self.display_value = {};
self.display_value_backup = {};
self.display_value["" + item.id] = item.name;
self.reinit_value(item.id);
} else if (item.action) {
Expand Down Expand Up @@ -3394,6 +3401,11 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
this.alive(dataset.name_get([self.get("value")])).done(function(data) {
self.display_value["" + self.get("value")] = data[0][1];
self.render_value(true);
}).fail( function (data, event) {
// avoid displaying crash errors as many2One should be name_get compliant
event.preventDefault();
self.display_value["" + self.get("value")] = self.display_value_backup["" + self.get("value")];
self.render_value(true);
});
}
},
Expand Down Expand Up @@ -3437,9 +3449,13 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
var self = this;
if (value_ instanceof Array) {
this.display_value = {};
this.display_value_backup = {}
if (! this.options.always_reload) {
this.display_value["" + value_[0]] = value_[1];
}
else {
this.display_value_backup["" + value_[0]] = value_[1];
}
value_ = value_[0];
}
value_ = value_ || false;
Expand All @@ -3450,6 +3466,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
},
add_id: function(id) {
this.display_value = {};
this.display_value_backup = {};
this.reinit_value(id);
},
is_false: function() {
Expand Down
9 changes: 7 additions & 2 deletions addons/web/static/src/js/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
return x;
}
});
this.ActionManager = parent;
this.views = {};
this.flags = flags || {};
this.registry = instance.web.views;
Expand Down Expand Up @@ -1253,6 +1254,7 @@ instance.web.View = instance.web.Widget.extend({
view_type: undefined,
init: function(parent, dataset, view_id, options) {
this._super(parent);
this.ViewManager = parent;
this.dataset = dataset;
this.view_id = view_id;
this.set_default_options(options);
Expand Down Expand Up @@ -1324,7 +1326,6 @@ instance.web.View = instance.web.Widget.extend({
}
};
var context = new instance.web.CompoundContext(dataset.get_context(), action_data.context || {});

var handler = function (action) {
if (action && action.constructor == Object) {
var ncontext = new instance.web.CompoundContext(context);
Expand Down Expand Up @@ -1361,7 +1362,11 @@ instance.web.View = instance.web.Widget.extend({
}
}
args.push(context);
return dataset.call_button(action_data.name, args).then(handler);
return dataset.call_button(action_data.name, args).then(handler).then(function () {
if (self.ViewManager.ActionManager) {
self.ViewManager.ActionManager.__parentedParent.menu.do_reload_needaction();
}
});
} else if (action_data.type=="action") {
return this.rpc('/web/action/load', {
action_id: action_data.name,
Expand Down
7 changes: 5 additions & 2 deletions addons/web_kanban/static/src/js/kanban.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,13 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
var remaining = groups.length - 1,
groups_array = [];
return $.when.apply(null, _.map(groups, function (group, index) {
var def = $.when([]);
var dataset = new instance.web.DataSetSearch(self, self.dataset.model,
new instance.web.CompoundContext(self.dataset.get_context(), group.model.context()), group.model.domain());
return dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit })
.then(function (records) {
if (group.attributes.length >= 1) {
def = dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit });
}
return def.then(function(records) {
self.nb_records += records.length;
self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
groups_array[index] = new instance.web_kanban.KanbanGroup(self, records, group, dataset);
Expand Down
Loading

0 comments on commit a94bbf8

Please sign in to comment.