diff --git a/addons/base/controllers/main.py b/addons/base/controllers/main.py index 923df69ca2d..f5384697d17 100644 --- a/addons/base/controllers/main.py +++ b/addons/base/controllers/main.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import base64 import glob, os import pprint from xml.etree import ElementTree @@ -361,24 +362,6 @@ class DataSet(openerpweb.Controller): @openerpweb.jsonrequest def read(self, request, model, ids, fields=False): return self.do_search_read(request, model, ids, fields) - def search_read(self, request, model, ids, fields=False): - """ Performs a read() - - :param request: a JSON-RPC request object - :type request: openerpweb.JsonRequest - :param str model: the name of the model to search on - :param ids: the ids of the records - :type ids: [?] - :param fields: a list of the fields to return in the result records - :type fields: [str] - :returns: a list of result records - :rtype: list - """ - Model = request.session.model(model) - - reads = Model.read(ids, fields or False, request.context) - reads.sort(key=lambda obj: ids.index(obj['id'])) - return reads @openerpweb.jsonrequest def get(self, request, model, ids, fields=False): @@ -403,7 +386,7 @@ class DataSet(openerpweb.Controller): :rtype: list """ Model = request.session.model(model) - records = Model.read(ids, fields) + records = Model.read(ids, fields, request.context) record_map = dict((record['id'], record) for record in records) @@ -572,6 +555,48 @@ class FormView(View): fields_view = self.fields_view_get(req, model, view_id, 'form', toolbar=toolbar) return {'fields_view': fields_view} + @openerpweb.httprequest + def image(self, request, session_id, model, id, field, **kw): + cherrypy.response.headers['Content-Type'] = 'image/png' + Model = request.session.model(model) + try: + if not id: + res = Model.default_get([field], request.context).get(field, '') + else: + res = Model.read([id], [field], request.context)[0].get(field, '') + return base64.decodestring(res) + except: + return self.placeholder() + def placeholder(self): + return open(os.path.join(openerpweb.path_addons, 'base', 'static', 'src', 'img', 'placeholder.png'), 'rb').read() + + @openerpweb.httprequest + def upload(self, request, session_id, callback, ufile=None): + cherrypy.response.timeout = 500 + headers = {} + for key, val in cherrypy.request.headers.iteritems(): + headers[key.lower()] = val + size = int(headers.get('content-length', 0)) + # TODO: might be usefull to have a configuration flag for max-lenght file uploads + try: + out = """""" + data = ufile.file.read() + args = [size, ufile.filename, ufile.headers.getheader('Content-Type'), base64.encodestring(data)] + except Exception as e: + args = [False, e.message] + return out % (simplejson.dumps(callback), simplejson.dumps(args)) + class ListView(View): _cp_path = "/base/listview" diff --git a/addons/base/static/lib/json/json2.js b/addons/base/static/lib/json/json2.js new file mode 100755 index 00000000000..b4c02d3f08b --- /dev/null +++ b/addons/base/static/lib/json/json2.js @@ -0,0 +1,480 @@ +/* + http://www.JSON.org/json2.js + 2011-02-23 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. + + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array of strings. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the value + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array of strings, then it will be + used to select the members to be serialized. It filters the results + such that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + var a; + if (typeof value === 'string') { + a = +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + var d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. +*/ + +/*jslint evil: true, strict: false, regexp: false */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +var JSON; +if (!JSON) { + JSON = {}; +} + +(function () { + "use strict"; + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return isFinite(this.valueOf()) ? + this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z' : null; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : gap ? + '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === 'string') { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : gap ? + '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : + '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/ + .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') + .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}()); diff --git a/addons/base/static/lib/qweb/qweb2.js b/addons/base/static/lib/qweb/qweb2.js index b37a38e9c38..e113ddc7c80 100644 --- a/addons/base/static/lib/qweb/qweb2.js +++ b/addons/base/static/lib/qweb/qweb2.js @@ -1,4 +1,5 @@ // TODO: trim support +// TODO: line number -> https://bugzilla.mozilla.org/show_bug.cgi?id=618650 var QWeb2 = { expressions_cache: {}, reserved_words: 'true,false,NaN,null,undefined,debugger,in,instanceof,new,function,return,this,typeof,eval,Math,RegExp,Array,Object'.split(','), @@ -295,8 +296,7 @@ QWeb2.Engine = (function() { compile : function(node) { var e = new QWeb2.Element(this, node); var template = node.getAttribute(this.prefix + '-name'); - return "(function(dict) {\n" + - " /* 'this' refers to Qweb2.Engine instance */\n" + + return " /* 'this' refers to Qweb2.Engine instance */\n" + " var context = { engine : this, template : " + (this.tools.js_escape(template)) + " };\n" + " dict = dict || {};\n" + " dict['__template__'] = '" + template + "';\n" + @@ -306,8 +306,7 @@ QWeb2.Engine = (function() { " /* END OF TEMPLATE */ } catch(error) {\n" + " context.engine.tools.exception('Runtime Error: ' + error, context);\n" + " }\n" + - " return r.join('');\n" + - "});"; + " return r.join('');"; }, render : function(template, dict) { if (this.debug && window['console'] !== undefined) { @@ -332,12 +331,16 @@ QWeb2.Engine = (function() { } var code = this.compile(this.templates[template]), tcompiled; try { - // tcompiled = new Function(code); TODO: Check if could use this in order to avoid eval - tcompiled = eval(code); + tcompiled = new Function(['dict'], code); } catch (error) { - console.log(code); + if (this.debug && window.console) { + console.log(code); + } this.tools.exception("Error evaluating template: " + error, { template: name }); } + if (!tcompiled) { + this.tools.exception("Error evaluating template: (IE?)" + error, { template: name }); + } this.compiled_templates[template] = tcompiled; return this.render(template, dict); } else { diff --git a/addons/base/static/src/base.html b/addons/base/static/src/base.html index 39909413397..314422d826b 100644 --- a/addons/base/static/src/base.html +++ b/addons/base/static/src/base.html @@ -20,6 +20,7 @@ + @@ -35,6 +36,9 @@ + - - - - - - - - -
- - -
-
    -
-
-
- - -
-
-

Choose dashboard layout

- -
-
\ No newline at end of file diff --git a/addons/base_dashboard/static/src/js/dashboard.js b/addons/base_dashboard/static/src/js/dashboard.js index 34d09f80e62..8f09f622050 100644 --- a/addons/base_dashboard/static/src/js/dashboard.js +++ b/addons/base_dashboard/static/src/js/dashboard.js @@ -10,39 +10,70 @@ openerp.base.form.Board = openerp.base.form.Widget.extend({ }, start: function() { this._super.apply(this, arguments); - this.$element.html(QWeb.render(this.template)); - }, - - render: function() { - var self = this; - jQuery('body').append( - jQuery('
', {'id': 'dashboard_template'}).load('/base_dashboard/static/src/dashboard_template.html',self.on_loaded).hide() - ) - }, - - on_loaded: function() { + + this.$element.html(QWeb.render(this.template)); + var $dashboard = this.$element.find('#dashboard'); var children = this.node.children; - var board = jQuery('#dashboard').dashboard({ - layoutClass:'layout' - }); - board.init(); - for(var ch = 0; ch < children.length; ch++) { - var ch_widgets = children[ch].children; - for(var chld = 0; chld < ch_widgets.length; chld++) { - var widget_type = ch_widgets[chld].tag; - var child_index = widget_type == 'action' ? chld : ch; - var widget = new (openerp.base.form.widgets.get_object(widget_type)) (this.view, ch_widgets[chld], board, child_index); - widget.start(); + + for(var ch=0; ch < children.length; ch++) { + var node = children[ch]; + + var widget; + if(node.tag.indexOf('child') >= 0) { + widget = new (openerp.base.form.widgets.get_object('child')) (this.view, node, $dashboard); + } else { + //Vpaned + widget = new (openerp.base.form.widgets.get_object(node.tag)) (this.view, node, $dashboard); } + + widget.start(); + } - } + + jQuery('.column').css('width', 100/children.length+'%'); + }, }); + +openerp.base.form.Dashbar = openerp.base.form.Widget.extend({ + init: function(view, node, dashboard) { + this._super(view, node, dashboard); + this.dashboard = dashboard; + this.template = 'Portlet' + }, + start: function() { + var $dashboard = this.dashboard; + var children = this.node.children; + $dashboard.append(QWeb.render(this.template, {widget: this, 'children': children})) + + for(var chld=0; chld < children.length;chld++) { + var child = children[chld]; + var widget = new (openerp.base.form.widgets.get_object(child.tag)) (this.view, child); + widget.start() + } + $( ".column" ).sortable({ + connectWith: ".column", + scroll: false + }); + + $( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) + .find( ".portlet-header" ) + .addClass( "ui-widget-header ui-corner-all" ) + .end() + .find( ".portlet-content" ); + + $( ".portlet-header .ui-icon" ).click(function() { + $( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" ); + $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle(); + }); + + $( ".column" ).disableSelection(); + } +}) + openerp.base.form.Action = openerp.base.form.Widget.extend({ - init: function(view, node, board, child_index) { - this._super(view, node, board, child_index); - this.board = board; - this.child_index = child_index; + init: function(view, node) { + this._super(view, node); }, start: function() { this._super.apply(this, arguments); @@ -54,26 +85,17 @@ openerp.base.form.Action = openerp.base.form.Widget.extend({ on_load_action: function(result) { var action = result.action; - - action.search_view = false; - action.no_sidebar = true; - action.search_view_id = false; - + action.flags = { + search_view : false, + sidebar : false, + views_switcher : false, + action_buttons : false + } var node_attrs = this.node.attrs; - var get_column = ['first', 'second', 'third']; - var board_element = this.board.element.find('[id=column-'+get_column[this.child_index]+']'); - - this.board.addWidget({ - 'id': node_attrs.name, - 'title': node_attrs.string, - }, board_element); - - var content_id = node_attrs.name+'-widgetcontent'; - this.board.getWidget(node_attrs.name).element.find('.widgetcontent').attr('id',content_id) - - action_manager = new openerp.base.ActionManager(this.session, content_id); + var content_id = 'portlet-content-'+node_attrs.name; + var action_manager = new openerp.base.ActionManager(this.session, content_id); action_manager.start(); - this.board.getWidget(node_attrs.name).url = action_manager.do_action(action); + action_manager.do_action(action); } }) @@ -99,6 +121,7 @@ openerp.base.form.Vpaned = openerp.base.form.Widget.extend({ }) openerp.base.form.widgets.add('hpaned', 'openerp.base.form.Board'); +openerp.base.form.widgets.add('child', 'openerp.base.form.Dashbar'); openerp.base.form.widgets.add('vpaned', 'openerp.base.form.Vpaned'); openerp.base.form.widgets.add('action', 'openerp.base.form.Action'); -} \ No newline at end of file +} diff --git a/addons/base_dashboard/static/src/xml/base_dashboard.xml b/addons/base_dashboard/static/src/xml/base_dashboard.xml index efe0a92c4dc..5d5b957e2ba 100644 --- a/addons/base_dashboard/static/src/xml/base_dashboard.xml +++ b/addons/base_dashboard/static/src/xml/base_dashboard.xml @@ -1,12 +1,17 @@ \ No newline at end of file diff --git a/addons/base_gantt/__openerp__.py b/addons/base_gantt/__openerp__.py index 55cec2c0863..c23f352a4f7 100644 --- a/addons/base_gantt/__openerp__.py +++ b/addons/base_gantt/__openerp__.py @@ -3,8 +3,8 @@ "version": "2.0", "depends": ['base'], "js": [ - 'static/lib/dhtmlxGantt/codebase/dhtmlxcommon.js', - 'static/lib/dhtmlxGantt/codebase/dhtmlxgantt.js', + 'static/lib/dhtmlxGantt/sources/dhtmlxcommon.js', + 'static/lib/dhtmlxGantt/sources/dhtmlxgantt.js', 'static/src/js/gantt.js' ], "css": ['static/lib/dhtmlxGantt/codebase/dhtmlxgantt.css'], diff --git a/addons/base_gantt/controllers/main.py b/addons/base_gantt/controllers/main.py index 7edb4d28763..0e6754ecb05 100644 --- a/addons/base_gantt/controllers/main.py +++ b/addons/base_gantt/controllers/main.py @@ -1,184 +1,11 @@ -import glob, os -from xml.etree import ElementTree -import math -import simplejson import openerpweb -import time -import datetime -from base.controllers.main import Xml2Json - +from base.controllers.main import View -COLOR_PALETTE = ['#f57900', '#cc0000', '#d400a8', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', - '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', - '#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', - '#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900', ] - -_colorline = ['#%02x%02x%02x' % (25 + ((r + 10) % 11) * 23, 5 + ((g + 1) % 11) * 20, 25 + ((b + 4) % 11) * 23) for r in range(11) for g in range(11) for b in range(11) ] - -def choice_colors(n): - if n > len(COLOR_PALETTE): - return _colorline[0:-1:len(_colorline) / (n + 1)] - elif n: - return COLOR_PALETTE[:n] - return [] - -class GanttView(openerpweb.Controller): +class GanttView(View): _cp_path = "/base_gantt/ganttview" - - date_start = None - date_delay = None - date_stop = None - color_field = None - - day_length = 8 - fields = {} - events = [] - calendar_fields = {} - ids = [] - model = '' - domain = [] - context = {} - event_res = [] - colors = {} - color_values = [] - + @openerpweb.jsonrequest def load(self, req, model, view_id): - m = req.session.model(model) - r = m.fields_view_get(view_id, 'gantt') - r["arch"] = Xml2Json.convert_to_structure(r["arch"]) - return {'fields_view':r} - - @openerpweb.jsonrequest - def get_events(self, req, **kw): + fields_view = self.fields_view_get(req, model, view_id, 'gantt') + return {'fields_view':fields_view} - self.model = kw['model'] - self.fields = kw['fields'] - self.day_length = kw['day_length'] - self.calendar_fields = kw['calendar_fields'] - self.color_field = kw.get('color_field') or self.color_field or None - self.fields[self.color_field] = "" - self.colors = kw.get('colors') or {} - self.text = self.calendar_fields['text']['name'] - - self.date_start = self.calendar_fields['date_start']['name'] - self.fields[self.date_start] = "" - - if self.calendar_fields.get('date_stop'): - self.date_stop = self.calendar_fields['date_stop']['name'] - self.fields[self.date_stop] = "" - if self.calendar_fields.get('date_delay'): - self.date_delay = self.calendar_fields['date_delay']['name'] - self.fields[self.date_delay] = "" - if self.calendar_fields.get('parent'): - self.parent = self.calendar_fields['parent']['name'] - self.fields[self.parent] = "" - - model = req.session.model(self.model) - event_ids = model.search([]) - - return self.create_event(event_ids, model) - - def create_event(self, event_ids, model): - - self.events = model.read(event_ids, self.fields.keys()) - result = [] - for evt in self.events: - - event_res = {} - key = evt[self.color_field] - name = key - value = key - if isinstance(key, list): # M2O, XMLRPC returns List instead of Tuple - name = key[0] - value = key[-1] - evt[self.color_field] = key = key[-1] - if isinstance(key, tuple): # M2O - value, name = key - - self.colors[key] = (name, value, None) - - st_date = evt.get(self.date_start) - if st_date: - self.set_format(st_date) - if self.date_delay: - duration = evt.get(self.date_delay) - else: - en_date = evt.get(self.date_stop) - - duration = (time.mktime(time.strptime(en_date, self.format))-\ - time.mktime(time.strptime(st_date, self.format)))/ (60 * 60) - - if duration > self.day_length : - d = math.floor(duration / 24) - h = duration % 24 - duration = d * self.day_length + h - - event_res = {} - event_res['start_date'] = st_date - event_res['duration'] = duration - event_res['text'] = evt.get(self.text) - event_res['id'] = evt['id'] - event_res['parent'] = evt.get(self.parent) - result.append(event_res) - - colors = choice_colors(len(self.colors)) - for i, (key, value) in enumerate(self.colors.items()): - self.colors[key] = [value[0], value[1], colors[i]] - - return {'result': result,'sidebar': self.colors} - - def set_format(self, st_date): - if len(st_date) == 10 : - self.format = "%Y-%m-%d" - else : - self.format = "%Y-%m-%d %H:%M:%S" - return - - def check_format(self, date): - if self.format == "%Y-%m-%d %H:%M:%S": - date = date + " 00:00:00" - return date - - @openerpweb.jsonrequest - def on_event_resize(self, req, **kw): - if self.date_delay: - key = self.date_delay - value = kw['duration'] - else: - key = self.date_stop - value = self.check_format(kw['end_date']) - try: - model = req.session.model(self.model) - res = model.write(kw['id'], {key : value}) - except Exception, e: - print "eeeeeeeeeeeeeeeeeeeeeeeeeee",e - return True - - @openerpweb.jsonrequest - def on_event_drag(self, req, **kw): - start_date = self.check_format(kw['start_date']) - if self.date_delay: - key = self.date_delay - value = kw['duration'] - else: - key = self.date_stop - value = self.check_format(kw['end_date']) - try: - model = req.session.model(self.model) - res = model.write(kw['id'], {self.date_start : start_date, key : value}) - except Exception, e: - print "eeeeeeeeeeeeeeeeeeeeeeeeeee",e - return True - - @openerpweb.jsonrequest - def reload_gantt(self, req, **kw): - - model = req.session.model(kw['model']) - if (kw['domain']): - domain = (kw['color_field'],'in', kw['domain']) - event_ids = model.search([domain]) - else: - event_ids = model.search([]) - return self.create_event(event_ids, model) - \ No newline at end of file diff --git a/addons/base_gantt/static/lib/dhtmlxGantt/sources/dhtmlxgantt.js b/addons/base_gantt/static/lib/dhtmlxGantt/sources/dhtmlxgantt.js index 52b9b562e96..75b33fefc45 100644 --- a/addons/base_gantt/static/lib/dhtmlxGantt/sources/dhtmlxgantt.js +++ b/addons/base_gantt/static/lib/dhtmlxGantt/sources/dhtmlxgantt.js @@ -173,8 +173,9 @@ GanttProjectInfo.prototype.getTaskByIdInTree = function(parentTask, id) * @type: public * @topic: 0 */ -function GanttTaskInfo(id, name, est, duration, percentCompleted, predecessorTaskId) +function GanttTaskInfo(id, name, est, duration, percentCompleted, predecessorTaskId, color) { + this.color = color || "white"; this.Id = id; this.Name = name; this.EST = est; @@ -348,7 +349,7 @@ GanttProject.prototype.create = function() * @type: public * @topic: 0 */ -function GanttChart() +function GanttChart(day_length) { this.Error = new GanttError(); this.dhtmlXMLSenderObject = new dhtmlXMLSenderObject(this); @@ -356,7 +357,7 @@ function GanttChart() //settings this.heightTaskItem = 12; this.dayInPixels = 24; - this.hoursInDay = 8; + this.hoursInDay = day_length; this._showTreePanel = true; this._showTooltip = true; this.isShowDescTask = false; @@ -4869,11 +4870,13 @@ GanttTask.prototype.createTaskItem = function() cellTblTask.height = this.Chart.heightTaskItem + "px"; cellTblTask.width = this.TaskInfo.PercentCompleted + "%"; cellTblTask.style.lineHeight = "1px"; + cellTblTask.style.backgroundColor = self.TaskInfo.color; + var imgPr = document.createElement("img"); imgPr.style.width = (this.TaskInfo.PercentCompleted * this.TaskInfo.Duration * this.Chart.hourInPixelsWork) / 100 + "px"; imgPr.style.height = this.Chart.heightTaskItem + "px"; cellTblTask.appendChild(imgPr); - imgPr.src = this.Chart.imgs + "progress_filled.png"; + //imgPr.src = this.Chart.imgs + "progress_filled.png"; } if (this.TaskInfo.PercentCompleted != 100) @@ -4943,9 +4946,9 @@ GanttTask.prototype.createTaskItem = function() } var taskClick = function() { - self.Chart.callEvent("onTaskClick", [self]); + self.Chart.callEvent("onTaskDblClick", [self]); }; - this.addEvent(divMove, 'click', taskClick, false); + this.addEvent(divMove, 'dblclick', taskClick, false); if (this.Chart.isEditable) { diff --git a/addons/base_gantt/static/src/js/gantt.js b/addons/base_gantt/static/src/js/gantt.js index f8391f2744b..398ec2df9dd 100644 --- a/addons/base_gantt/static/src/js/gantt.js +++ b/addons/base_gantt/static/src/js/gantt.js @@ -7,7 +7,8 @@ QWeb.add_template('/base_gantt/static/src/xml/base_gantt.xml'); openerp.base.views.add('gantt', 'openerp.base_gantt.GanttView'); openerp.base_gantt.GanttView = openerp.base.Controller.extend({ - init: function(view_manager, session, element_id, dataset, view_id) { +init: function(view_manager, session, element_id, dataset, view_id) { + this._super(session, element_id); this.view_manager = view_manager; this.dataset = dataset; @@ -16,207 +17,326 @@ openerp.base_gantt.GanttView = openerp.base.Controller.extend({ this.fields_views = {}; this.widgets = {}; this.widgets_counter = 0; - this.fields = {}; - this.datarecord = {}; + this.fields = this.dataset.fields ? this.dataset.fields: {}; + this.ids = this.dataset.ids; + this.name = ""; + this.date_start = ""; + this.date_delay = ""; + this.date_stop = ""; + this.color_field = ""; + this.day_lenth = 8; + this.colors = []; + this.color_values = []; this.calendar_fields = {}; + this.info_fields = []; + this.domain = this.dataset._domain ? this.dataset._domain: []; + this.context = {}; }, - do_show: function () { - // TODO: re-trigger search - this.$element.show(); - }, - do_hide: function () { - this.$element.hide(); - }, + start: function() { - this.rpc("/base_gantt/ganttview/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); + this.rpc("/base_gantt/ganttview/load", + {"model": this.model, "view_id": this.view_id}, this.on_loaded); }, + on_loaded: function(data) { - this.fields_view = data.fields_view; + var self = this; + this.fields_view = data.fields_view; + this.name = this.fields_view.name || this.fields_view.arch.attrs.string; this.view_id = this.fields_view.view_id; this.date_start = this.fields_view.arch.attrs.date_start; this.date_delay = this.fields_view.arch.attrs.date_delay; this.date_stop = this.fields_view.arch.attrs.date_stop; - this.color_field = this.fields_view.arch.attrs.color; + this.color_field = this.fields_view.arch.attrs.color; this.day_length = this.fields_view.arch.attrs.day_length || 8; this.colors = this.fields_view.arch.attrs.colors; - this.fields = this.fields_view.fields; this.text = this.fields_view.arch.children[0].children[0].attrs.name; this.parent = this.fields_view.arch.children[0].attrs.link; - this.calendar_fields['parent'] = {'name': this.parent}; - this.calendar_fields['date_start'] = {'name': this.date_start}; - this.calendar_fields['text'] = {'name': this.text}; - if(this.date_delay) - this.calendar_fields['date_delay'] = {'name': this.date_delay}; - if(this.date_stop) - this.calendar_fields['date_stop'] = {'name': this.date_stop}; + this.format = "yyyy-MM-dd"; + + self.create_gantt(); + self.get_events(); - this.calendar_fields['day_length'] = this.day_length; - this.rpc('/base_gantt/ganttview/get_events', - {'model': this.model, - 'fields': this.fields, - 'color_field': this.color_field, - 'day_length': this.day_length, - 'calendar_fields': this.calendar_fields, - 'colors': this.colors, - 'info_fields': this.info_fields - }, - function(res) { - self.create_gantt(); - self.load_event(res); - }) this.$element.html(QWeb.render("GanttView", {"view": this, "fields_view": this.fields_view})); }, - convert_date_format: function(date) { - date=date+""; - if(typeof (date)!="string"||date.length===0){ - return null; - } - var iso=date.split("-"); - if(iso.length===0){ - return null; - } - var day = iso[2]; - var iso_hours = day.split(' '); - if (iso_hours.length > 1) { - day = iso_hours[0]; - var iso_date_hours = iso_hours[1].split(':') - var new_date = new Date(iso[0], iso[1] - 1, day); - new_date.setHours(iso_date_hours[0]); - new_date.setMinutes(iso_date_hours[1]); - new_date.setSeconds(iso_date_hours[2]); - } - else { - var new_date = new Date(iso[0], iso[1] - 1, day); - } - new_date.setFullYear(iso[0]); - new_date.setMonth(iso[1]-1); - new_date.setDate(day); - return new_date; - }, - create_gantt: function() { - ganttChartControl = new GanttChart(); + + ganttChartControl = new GanttChart(this.day_length); ganttChartControl.setImagePath("/base_gantt/static/lib/dhtmlxGantt/codebase/imgs/"); ganttChartControl.setEditable(true); ganttChartControl.showTreePanel(true); ganttChartControl.showContextMenu(true); ganttChartControl.showDescTask(true,'d,s-f'); ganttChartControl.showDescProject(true,'n,d'); - }, - load_event: function(res) { - var self = this - var result = res.result; - var sidebar = res.sidebar; - var project_id = new Array(); - var project = new Array(); - var j = -1; - var self = this; - for (i in result) { - - var parent_id = result[i]['parent'][0]; - var parent_name = result[i]['parent'][1]; - - if (jQuery.inArray(parent_id, project_id) == -1){ - if (parent_id == undefined){ - parent_name = ""; - } - j = j + 1; - project[j] = new GanttProjectInfo(parent_id, parent_name, new Date(2011, 1, 1)); - project_id[j] = parent_id; - } - - var id = result[i]['id']; - var text = result[i]['text']; - var start_date = this.convert_date_format(result[i]['start_date']); - var duration = result[i]['duration']; - - var task = new GanttTaskInfo(id, text, start_date, duration, 100, ""); - - k = project_id.indexOf(parent_id); - project[k].addTask(task); - } - for (i in project_id){ - ganttChartControl.addProject(project[i]); - } - ganttChartControl.create("GanttDiv"); - ganttChartControl.attachEvent("onTaskEndResize", function(task) {self.on_task_end_resize(task);}) - ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_task_end_drag(task);}) - - //Create Sidebar - if (jQuery('#cal-sidebar-option').length == 0){ - jQuery('#gantt-sidebar').append( - jQuery('',{'width':'100%','cellspacing': 0, 'cellpadding': 0, 'id':'cal-sidebar-option'}) - ) - for(s in sidebar) { - jQuery('#cal-sidebar-option').append( - jQuery('').append( - jQuery('
').append( - jQuery('
') - .append( - jQuery('', - { - 'type': 'checkbox', - 'id':sidebar[s][0], - 'value':sidebar[s][0] - }).bind('click',function(){ - self.reload_gantt(self.color_field,self.model) - }), - sidebar[s][1] - ) - .css('background-color',sidebar[s][sidebar[s].length-1]) - ) - ) - ) + }, + + get_events: function() { + + var self = this; + this.dataset.read_ids(this.dataset.ids, {}, function(result) { + self.load_event(result); + }); + + }, + + load_event: function(events) { + + var self = this; + + var result = events; + var project = {}; + var project_smalldate = {}; + var proj_id = []; + var proj_id_text = []; + + COLOR_PALETTE = ['#ccccff', '#cc99ff', '#75507b', '#3465a4', '#73d216', '#c17d11', '#edd400', + '#fcaf3e', '#ef2929', '#ff00c9', '#ad7fa8', '#729fcf', '#8ae234', '#e9b96e', '#fce94f', + '#ff8e00', '#ff0000', '#b0008c', '#9000ff', '#0078ff', '#00ff00', '#e6ff00', '#ffff00', + '#905000', '#9b0000', '#840067', '#510090', '#0000c9', '#009b00', '#9abe00', '#ffc900'] + + //Smallest date of child is parent start date + for (i in result){ + var res = result[i]; + + if (res[this.date_start] != false){ + + var parent_id = res[this.parent][0] || res[this.parent]; + var parent_name = res[this.parent][1]; + var start_date = this.convert_str_date(res[this.date_start]); + + if (project_smalldate[parent_id] == undefined){ + project_smalldate[parent_id] = start_date; + proj_id.push(parent_id); + + if (parent_name != undefined){ + proj_id_text.push(res[this.parent]); + } + } + else{ + if (start_date < project_smalldate[parent_id]){ + project_smalldate[parent_id] = start_date; + } + } + } } + + //get parent text + if (parent_name == undefined){ + + var ajax = { + url: '/base/dataset/call', + async: false + }; + + this.rpc(ajax, { + model: this.dataset.model, + method: "name_get", + ids: proj_id, + args: "" + }, function(response) { + proj_id_text = response.result; + + }); + } + + //create parents + for (i in proj_id){ + + var id = proj_id_text[i][0]; + var text = proj_id_text[i][1]; + + project[id] = new GanttProjectInfo(id, text, project_smalldate[id]); + } + + //create childs + var k = 0; + var color_box = {}; + for (i in result) { + + var res = result[i]; + if (res[this.date_start] != false){ + + var parent_id = res[this.parent][0] || res[this.parent]; + var id = res['id']; + var text = res[this.text]; + + var start_date = this.convert_str_date(res[this.date_start]); + + var color = res[this.color_field][0] || res[this.color_field]; + if (color_box[color] == undefined){ + color_box[color] = COLOR_PALETTE[k]; + k = k + 1; + } + + if (this.date_stop != undefined){ + if (res[this.date_stop] != false){ + var stop_date = this.convert_str_date(res[this.date_stop]); + var duration= self.hours_between(start_date, stop_date); + } + else{ + var duration = 0; + } + } + else{ + var duration = res[this.date_delay]; + } + if (duration == false) + duration = 0 + task = new GanttTaskInfo(id, text, start_date, duration, 100, "", color_box[color]); + project[parent_id].addTask(task); + + } + } + + //Add parent + for (i in proj_id){ + ganttChartControl.addProject(project[proj_id[i]]); + } + + ganttChartControl.create("GanttDiv"); + ganttChartControl.attachEvent("onTaskStartDrag", function(task) {self.on_drag_start(task);}); + ganttChartControl.attachEvent("onTaskEndResize", function(task) {self.on_resize_drag_end(task, "resize");}); + ganttChartControl.attachEvent("onTaskEndDrag", function(task) {self.on_resize_drag_end(task, "drag");}); + ganttChartControl.attachEvent("onTaskDblClick", function(task) {self.open_popup(task);}); + }, - reload_gantt: function(color_field, model) { - var domain = []; + + hours_between: function(date1, date2) { + + var ONE_DAY = 1000 * 60 * 60 * 24; + var date1_ms = date1.getTime(); + var date2_ms = date2.getTime(); + var difference_ms = Math.abs(date1_ms - date2_ms); + + d = Math.round(difference_ms / ONE_DAY); + h = Math.round((difference_ms % ONE_DAY)/(1000 * 60 * 60)); + + return (d * this.day_length) + h; + + }, + + open_popup : function(task) { + var event_id = task.getId(); + if (event_id) { + event_id = parseInt(event_id, 10); + var dataset_event_index = jQuery.inArray(event_id, this.ids); + } else { + var dataset_event_index = null; + } + this.dataset.index = dataset_event_index; + var element_id = _.uniqueId("act_window_dialog"); + var dialog = jQuery('
', + {'id': element_id + }).dialog({ + title: 'Gantt Chart', + modal: true, + minWidth: 800, + position: 'top' + }); + var event_form = new openerp.base.FormView(this.view_manager, this.session, element_id, this.dataset, false); + event_form.start(); + }, + + on_drag_start : function(task){ + st_date = task.getEST(); + if(st_date.getHours()){ + self.hh = st_date.getHours(); + self.mm = st_date.getMinutes(); + } + }, + + on_resize_drag_end : function(task, evt){ + + var event_id = task.getId(); + var data = {}; + + if (evt == "drag"){ + full_date = task.getEST().set({hour: self.hh, minute : self.mm, second:0}); + data[this.date_start] = this.convert_date_str(full_date); + } + if (this.date_stop != undefined){ + tm = (task.getDuration() % this.day_length); + stp = task.getFinishDate().add(tm).hour(); + data[this.date_stop] = this.convert_date_str(stp); + }else{ + data[this.date_delay] = task.getDuration(); + } + this.dataset.write(event_id, data, function(result) {}); + + }, + + do_show: function () { + this.$element.show(); + }, + + do_hide: function () { + this.$element.hide(); + }, + + convert_str_date: function (str){ + if (str.length == 19){ + this.format = "yyyy-MM-dd HH:mm:ss"; + return openerp.base.parse_datetime(str); + } else if (str.length == 10){ + this.format = "yyyy-MM-dd"; + return openerp.base.parse_date(str); + } else if (str.length == 8){ + this.format = "HH:mm:ss"; + return openerp.base.parse_time(str); + } + throw "Unrecognized date/time format"; + }, + + convert_date_str: function(full_date) { + if (this.format == "yyyy-MM-dd HH:mm:ss"){ + return openerp.base.format_datetime(full_date); + } else if (this.format == "yyyy-MM-dd"){ + return openerp.base.format_date(full_date); + } else if (this.format == "HH:mm:ss"){ + return openerp.base.format_time(full_date); + } + throw "Unrecognized date/time format"; + }, + + reload_gantt: function(domain) { var self = this; - jQuery('input[type=checkbox]:checked','#cal-sidebar-option').each(function() { - domain.push(parseInt(jQuery(this).attr('id'))) + var ajax = { + url: '/base/dataset/search_read', + async: false + }; + this.rpc(ajax, { + model: this.dataset.model, + domain: self.dataset.domain, + context :self.dataset.context + }, function(response) { + ganttChartControl.clearAll(); + jQuery("#GanttDiv").children().remove(); + self.load_event(response); + }); + }, + + do_search: function (domains, contexts, groupbys) { + + var self = this; + + return this.rpc('/base/session/eval_domain_and_context', { + domains: domains, + contexts: contexts, + group_by_seq: groupbys + }, function (results) { + self.dataset.context = results.context; + self.dataset.domain = results.domain; + return self.reload_gantt(self.dataset.domain); }); - this.rpc('/base_gantt/ganttview/reload_gantt',{ - 'domain':domain, - 'color_field':color_field, - 'model': model - },function(res) { - ganttChartControl.clearAll(); - jQuery("#GanttDiv").children().remove(); - self.load_event(res); - }); - }, - reverse_convert_date_format: function(date) { - return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate(); - }, - - on_task_end_resize : function(task) { - this.rpc('/base_gantt/ganttview/on_event_resize', - {'id' : task.getId(), - 'end_date' : this.reverse_convert_date_format(task.getFinishDate()), - 'duration' : task.getDuration() - }, - function(result) { - }) - }, - on_task_end_drag : function(task) { - this.rpc('/base_gantt/ganttview/on_event_drag', - {'id' : task.getId(), - 'start_date' : this.reverse_convert_date_format(task.getEST()), - 'end_date' : this.reverse_convert_date_format(task.getFinishDate()), - 'duration' : task.getDuration() - }, - function(result) { - }) } }); @@ -224,5 +344,4 @@ openerp.base_gantt.GanttView = openerp.base.Controller.extend({ // here you may tweak globals object, if any, and play with on_* or do_* callbacks on them }; - // vim:et fdc=0 fdl=0: diff --git a/addons/base_gantt/static/src/xml/base_gantt.xml b/addons/base_gantt/static/src/xml/base_gantt.xml index 72c14ceb16c..c85abf0cad8 100644 --- a/addons/base_gantt/static/src/xml/base_gantt.xml +++ b/addons/base_gantt/static/src/xml/base_gantt.xml @@ -3,12 +3,9 @@

- -
+
-
-
diff --git a/openerpweb/openerpweb.py b/openerpweb/openerpweb.py index 19836497ef1..81a323f2b97 100644 --- a/openerpweb/openerpweb.py +++ b/openerpweb/openerpweb.py @@ -422,6 +422,8 @@ class HttpRequest(object): self.applicationsession = applicationsession self.httpsession_id = "cookieid" self.httpsession = cherrypy.session + self.context = kw.get('context', {}) + self.session = self.httpsession.setdefault(kw.get('session_id', None), OpenERPSession()) self.result = "" print "GET/POST --> %s.%s %s %r" % (controller.__class__.__name__, f.__name__, request, kw) r = f(controller, self, **kw)