此应用程序在本地完美运行,但当我在服务器上尝试它时,我得到一个timeoutexception。我正在尝试导入的文件是utf-8并包含冰岛字符(á,ú,í,æ,é,ð,ö)
继承人的代码: def get(self):
site = "order"
scripts = """
<script>
$('#csv').ajaxForm({
beforeSend: function() {
$('#update').html("Loading...");
},
complete: function(data) {
$('#update').html(data.responseText);
}
});
</script>
"""
content = """
<div class="row" style="margin-top: 10px;">
<div class="large-12 columns" id="update">
<form id="csv" enctype="multipart/form-data" method="post" action="import">
<select name="db">
<option value="users">Users</option>
<option value="machines">Machines</option>
<option value="company">Company</option>
<option value="process">Order</option>
<option value="status">Status</option>
<option value="part">Part</option>
<option value="machineType">Machine Type</option>
<select>
<input name="file" type="file">
<input type="submit" value="submit" class="button">
</form>
</div>
</div>
"""
template_values = {
'site': site,
'scripts': scripts,
'content': content,
}
template = JINJA_ENVIRONMENT.get_template('main.html')
self.response.write(template.render(template_values))
def post(self):
out = """
<div style='background: green; border: 1px solid green; border-top-left-radius: 3px; border-top-right-radius: 3px; padding: 5px;'>
{{import}} rows important <a style="float:right; color:white;">Back</a>
</div>
<div style='border: 1px solid gray; padding: 5px;'>
"""
file = self.request.get('file')
reader = file.decode('utf-8').split('\n')
database = self.request.get('db')
out += import_excel.bulkImport(reader, database)
self.response.write(out)
@staticmethod
def bulkImport(reader, database):
rows = 0
out = ""
if database == "users":
for row in reader:
rows += 1
tiles = row.split(';')
x = users(idno = tiles[0],
company = tiles[1],
firstname = tiles[2],
lastname = tiles[3],
phone = tiles[4],
fax = tiles[5],
email = tiles[6],
comments = tiles[7])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + ", " + tiles[4] + ", " + tiles[5] + ", " + tiles[6] + ", " + tiles[7] + "]</br>"
elif database == "machines":
for row in reader:
rows += 1
tiles = row.split(';')
x = machines(ID = tiles[0],
brand = tiles[1],
type = tiles[2],
year = tiles[3],
SN = tiles[4],
owner = tiles[5],
comments = tiles[6])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + ", " + tiles[4] + ", " + tiles[5] + ", " + tiles[6] + "]</br>"
elif database == "companies":
for row in reader:
rows += 1
tiles = row.split(';')
x = company(ID = tiles[0],
name = tiles[1],
street = tiles[2],
zip = tiles[3],
city = tiles[4],
country = tiles[5],
phone = tiles[6],
fax = tiles[7],
email = tiles[8],
comments = tiles[9])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + ", " + tiles[4] + ", " + tiles[5] + ", " + tiles[6] + ", " + tiles[7] + ", " + tiles[8] + ", " + tiles[9] + "]</br>"
elif database == "process":
for row in reader:
rows += 1
tiles = row.split(';')
x = process(ID = tiles[0],
company = tiles[1],
contact = tiles[2],
machine = tiles[3],
status = tiles[4],
comments = tiles[5])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + ", " + tiles[4] + ", " + tiles[5] + "]</br>"
elif database == "part":
for row in reader:
rows += 1
tiles = row.split(';')
x = part(ID = tiles[0],
no = tiles[1],
name = tiles[2],
price = int(tiles[3]),
company = tiles[4],
comments = tiles[5])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + ", " + tiles[4] + ", " + tiles[5] + "]</br>"
elif database == "machineType":
for row in reader:
rows += 1
tiles = row.replace('&comma', ',').split(';')
x = machineType(Description = tiles[0],
ID = tiles[1],
Brand = tiles[2],
Type = tiles[3])
x.put()
out += "Row imported [" + tiles[0] + ", " + tiles[1] + ", " + tiles[2] + ", " + tiles[3] + "]</br>"
out += "</div>"
out = out.replace("{{import}}", str(rows))
return out