[IMP]Improve code for passing parameter.
bzr revid: kch@tinyerp.com-20110809064441-edw62zxu7c0r8uvv
This commit is contained in:
parent
3e3796f367
commit
805acc602d
|
@ -1225,13 +1225,13 @@ class Import(View):
|
|||
return fields
|
||||
|
||||
@openerpweb.httprequest
|
||||
def detect_data(self, req, session_id, model, id, csvfile, csvsep, csvdel, csvcode, csvskip):
|
||||
def detect_data(self, req, **params):
|
||||
import StringIO
|
||||
_fields = {}
|
||||
_fields_invert = {}
|
||||
error = None
|
||||
|
||||
fields = dict(req.session.model(model).fields_get(False, req.session.eval_context(req.context)))
|
||||
fields = dict(req.session.model(params.get('model')).fields_get(False, req.session.eval_context(req.context)))
|
||||
fields.update({'id': {'string': 'ID'}, '.id': {'string': 'Database ID'}})
|
||||
|
||||
def model_populate(fields, prefix_node='', prefix=None, prefix_value='', level=2):
|
||||
|
@ -1263,7 +1263,7 @@ class Import(View):
|
|||
model_populate(fields)
|
||||
|
||||
try:
|
||||
data = csv.reader(csvfile.file, quotechar=str(csvdel), delimiter=str(csvsep))
|
||||
data = csv.reader(params.get('csvfile').file, quotechar=str(params.get('csvdel')), delimiter=str(params.get('csvsep')))
|
||||
except:
|
||||
raise 'Error opening .CSV file', 'Input Error.'
|
||||
|
||||
|
@ -1278,7 +1278,7 @@ class Import(View):
|
|||
break
|
||||
for line in records:
|
||||
for word in line:
|
||||
word = str(word.decode(csvcode))
|
||||
word = str(word.decode(params.get('csvcode')))
|
||||
if word in _fields:
|
||||
fields.append((word, _fields[word]))
|
||||
elif word in _fields_invert.keys():
|
||||
|
@ -1290,30 +1290,30 @@ class Import(View):
|
|||
error = {'message':('Error processing the first line of the file. Field "%s" is unknown') % (word,)}
|
||||
|
||||
if error:
|
||||
csvfile.file.seek(0)
|
||||
error=dict(error, preview=csvfile.file.read(200))
|
||||
params.get('csvfile').file.seek(0)
|
||||
error=dict(error, preview=params.get('csvfile').file.read(200))
|
||||
return simplejson.dumps({'error':error})
|
||||
|
||||
return simplejson.dumps({'records':records[1:],'fields':fields})
|
||||
|
||||
@openerpweb.httprequest
|
||||
def import_data(self, req, session_id, model, id, csvfile, csvsep, csvdel, csvcode, csvskip, fields=[]):
|
||||
def import_data(self, req, **params):
|
||||
import StringIO
|
||||
|
||||
context = req.session.eval_context(req.context)
|
||||
modle_obj = req.session.model(model)
|
||||
modle_obj = req.session.model(params.get('model'))
|
||||
res = None
|
||||
content = csvfile.file.read()
|
||||
content = params.get('csvfile').file.read()
|
||||
input=StringIO.StringIO(content)
|
||||
limit = 0
|
||||
data = []
|
||||
|
||||
if not (csvdel and len(csvdel) == 1):
|
||||
if not (params.get('csvdel') and len(params.get('csvdel')) == 1):
|
||||
error={'message': "The CSV delimiter must be a single character"}
|
||||
return simplejson.dumps({'error':error})
|
||||
|
||||
try:
|
||||
for j, line in enumerate(csv.reader(input, quotechar=str(csvdel), delimiter=str(csvsep))):
|
||||
for j, line in enumerate(csv.reader(input, quotechar=str(params.get('csvdel')), delimiter=str(params.get('csvsep')))):
|
||||
# If the line contains no data, we should skip it.
|
||||
if not line:
|
||||
continue
|
||||
|
@ -1333,7 +1333,7 @@ class Import(View):
|
|||
|
||||
for line in data:
|
||||
try:
|
||||
datas.append(map(lambda x:x.decode(csvcode).encode('utf-8'), line))
|
||||
datas.append(map(lambda x:x.decode(params.get('csvcode')).encode('utf-8'), line))
|
||||
except:
|
||||
datas.append(map(lambda x:x.decode('latin').encode('utf-8'), line))
|
||||
|
||||
|
|
|
@ -333,12 +333,12 @@ openerp.base.Dialog = openerp.base.OldWidget.extend({
|
|||
},
|
||||
set_options: function(options) {
|
||||
options = options || {};
|
||||
options.width = this.get_width(options.width || this.options.width);
|
||||
options.min_width = this.get_width(options.min_width || this.options.min_width);
|
||||
options.max_width = this.get_width(options.max_width || this.options.max_width);
|
||||
options.height = this.get_height(options.height || this.options.height);
|
||||
options.min_height = this.get_height(options.min_height || this.options.min_height);
|
||||
options.max_height = this.get_height(options.max_height || this.options.max_width);
|
||||
options.width = this.get_width(options.width || this.dialog_options.width);
|
||||
options.min_width = this.get_width(options.min_width || this.dialog_options.min_width);
|
||||
options.max_width = this.get_width(options.max_width || this.dialog_options.max_width);
|
||||
options.height = this.get_height(options.height || this.dialog_options.height);
|
||||
options.min_height = this.get_height(options.min_height || this.dialog_options.min_height);
|
||||
options.max_height = this.get_height(options.max_height || this.dialog_options.max_width);
|
||||
|
||||
if (options.width !== 'auto') {
|
||||
if (options.width > options.max_width) options.width = options.max_width;
|
||||
|
@ -461,9 +461,9 @@ openerp.base.Database = openerp.base.Widget.extend({
|
|||
this.$element.closest(".openerp")
|
||||
.removeClass("login-mode")
|
||||
.addClass("database_block");
|
||||
|
||||
|
||||
var self = this;
|
||||
|
||||
|
||||
var fetch_db = this.rpc("/base/database/get_list", {}, function(result) {
|
||||
self.db_list = result.db_list;
|
||||
});
|
||||
|
@ -475,7 +475,7 @@ openerp.base.Database = openerp.base.Widget.extend({
|
|||
self.lang_list = result.lang_list;
|
||||
});
|
||||
$.when(fetch_db, fetch_langs).then(function () {self.do_create();});
|
||||
|
||||
|
||||
this.$element.find('#db-create').click(this.do_create);
|
||||
this.$element.find('#db-drop').click(this.do_drop);
|
||||
this.$element.find('#db-backup').click(this.do_backup);
|
||||
|
@ -594,11 +594,11 @@ openerp.base.Database = openerp.base.Widget.extend({
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
do_drop: function() {
|
||||
var self = this;
|
||||
self.$option_id.html(QWeb.render("DropDB", self));
|
||||
|
||||
|
||||
self.$option_id.find("form[name=drop_db_form]").validate({
|
||||
submitHandler: function (form) {
|
||||
var $form = $(form),
|
||||
|
@ -682,11 +682,11 @@ openerp.base.Database = openerp.base.Widget.extend({
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
do_restore: function() {
|
||||
var self = this;
|
||||
self.$option_id.html(QWeb.render("RestoreDB", self));
|
||||
|
||||
|
||||
self.$option_id.find("form[name=restore_db_form]").validate({
|
||||
submitHandler: function (form) {
|
||||
$.blockUI();
|
||||
|
@ -752,7 +752,7 @@ openerp.base.Database = openerp.base.Widget.extend({
|
|||
|
||||
openerp.base.Login = openerp.base.Widget.extend({
|
||||
remember_creditentials: true,
|
||||
|
||||
|
||||
init: function(parent, element_id) {
|
||||
this._super(parent, element_id);
|
||||
this.has_local_storage = typeof(localStorage) != 'undefined';
|
||||
|
@ -981,7 +981,7 @@ openerp.base.WebClient = openerp.base.Widget.extend({
|
|||
|
||||
this.menu = new openerp.base.Menu(this, "oe_menu", "oe_secondary_menu");
|
||||
this.menu.on_action.add(this.on_menu_action);
|
||||
|
||||
|
||||
},
|
||||
start: function() {
|
||||
this.session.start();
|
||||
|
|
|
@ -1282,7 +1282,6 @@
|
|||
<form name="import_data" id="import_data" action="" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="session_id" t-att-value="session.session_id"/>
|
||||
<input type="hidden" name="model" t-att-value="dataset.model"/>
|
||||
<input type="hidden" name="id" t-att-value="dataset.id"/>
|
||||
<table cellspacing="5" border="0" width="100%">
|
||||
<tr>
|
||||
<td>
|
||||
|
|
Loading…
Reference in New Issue