#TODO: ok now we've got the report, and so what?
return False
-
class Import(View):
_cp_path = "/base/import"
fields.update({'id':{'string':'ID'},'.id':{'string':'Database ID'}})
model_populate(fields)
all_fields = fields.keys()
+
try:
data = csv.reader(params.get('csvfile').file, quotechar=str(params.get('csvdel')), delimiter=str(params.get('csvsep')))
except:
fields = []
word=''
limit = 4
+ count = 0
try:
for i, row in enumerate(data):
records.append(row)
if i == limit:
break
- for line in records:
+ for j, line in enumerate(records):
+ if j == 1:
+ break
for word in line:
word = str(word.decode(params.get('csvcode')))
if word in _fields:
elif word in _fields_invert.keys():
fields.append((_fields_invert[word], word))
else:
+ count = count + 1
fields.append((word, word))
# error = {'message':("You cannot import the field '%s', because we cannot auto-detect it" % (word,))}
+
+ if len(line) == count:
+ error = {'message':"File has not any column header."}
except:
error = {'message':('Error processing the first line of the file. Field "%s" is unknown') % (word,)}
error=dict(error, preview=params.get('csvfile').file.read(200))
return simplejson.dumps({'error':error})
- return simplejson.dumps({'records':records[1:],'fields':fields,'all_fields':all_fields})
+ return simplejson.dumps({'records':records[1:],'header':fields,'all_fields':all_fields})
@openerpweb.httprequest
def import_data(self, req, **params):
d+= ('%s: %s' % (str(key),str(val)))
msg = 'Error trying to import this record:%s. ErrorMessage:%s %s' % (d,res[2],res[3])
error = {'message':str(msg), 'title':'ImportationError'}
-
return simplejson.dumps({'error':error})
},
import_results:function(res){
$('#result, #success').empty();
- $(".ui-button-text:contains('Import File')").parent().attr("disabled",false);
+
var results = $.parseJSON(res);
var result_node = $("#result");
if (results['records']){
- records = {'header':results['fields'],'sel':results['all_fields'],'row':results['records']};
+ records = {'header':results['header'],'sel':results['all_fields'],'row':results['records']};
result_node.append(QWeb.render('ImportView-result',{'records':records}));
}else if(results['error']){
result_node.append(QWeb.render('ImportView-result',{'error': results['error']}));
var success_node = $("#success");
success_node.append(QWeb.render('ImportView-result',{'success': results['success']}));
}
- $('td #header').each(function(){
- var head = $(this).text();
- if (jQuery.inArray(head,results['all_fields']) <= -1){
- $(".ui-button-text:contains('Import File')").parent().attr("disabled",true);
+ var mm = [];
+ $("td #sel_field").click(function(){
+ mm = [];
+ $("td #sel_field option:selected").each(function(){
+ mm.push($(this).index());
+ });
+ });
+ $("td #sel_field").change(function(){
+ $(this).css('background-color','');
+ var kk = this.selectedIndex;
+ if ($.inArray(kk,mm) > -1){
+ $(this).css('background-color','#FF6666');
+ }else{
+ $(this).css('background-color','');
}
});
},
stop: function() {
$(this.$dialog).remove();
this._super();
- },
+ }
});
};
\ No newline at end of file
<tr>
<t t-foreach="records.header" t-as="header">
<td>
- <select name="fld" id="fld">
+ <select name="sel_field" id="sel_field">
<option selected="selected" value=""></option>
<t t-foreach="records.sel" t-as="selection">
<option t-att="{'selected': header[0] === selection ? 'selected' : null}"
</table>
</t>
</t>
-</templates>
+</templates>
\ No newline at end of file