本文整理汇总了Python中project.model.Project.set_load_worker方法的典型用法代码示例。如果您正苦于以下问题:Python Project.set_load_worker方法的具体用法?Python Project.set_load_worker怎么用?Python Project.set_load_worker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project.model.Project
的用法示例。
在下文中一共展示了Project.set_load_worker方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_data_upload
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import set_load_worker [as 别名]
def load_data_upload(project_id,entry_id):
# This should return json
# look at jquery-upload
print "getting upload"
uploads = request.files.getlist('files[]')
print "file length: %d" % len(uploads)
project = Project()
project.get(project_id)
# project add_datafile should return file_id
uploaded_all = []
# first what if it is a invalid file,
# second what if it failed
for uploaded in uploads:
print 'filename being uploaded %s' % uploaded.filename
try:
file_id = project.add_datafile(entry_id,uploaded)
except:
data = {
'filename':uploaded.filename,
'name':uploaded.filename.replace('.','_'),
'content-type':uploaded.content_type,
'msg':'Invalid File Type, only CSV/Json are supported',
'success':False
}
uploaded_all.append(data)
continue
try:
task_id = loader_task.delay(project_id,entry_id,file_id)
project.set_load_worker(entry_id,file_id,task_id.id)
except:
data = {
'name':uploaded.filename.replace('.','_'),
'filename':uploaded.filename,
'content-type':uploaded.content_type,
'msg':'Problem processing file',
'success':False,
}
uploaded_all.append(data)
continue
test_file = project.get_datafile(file_id)
get_url = '/download/%s/%s/' % (project_id,entry_id)
delete_url = '/delete/%s/%s/' % (project_id,entry_id)
data = {
'success':True,
'msg':'',
'file_id':file_id,
'length':test_file.length,
'name':test_file.name.replace('.','_'),
'filename':test_file.name,
'content-type':test_file.content_type,
'url':get_url,
'delete':delete_url
}
uploaded_all.append(data)
data = json.dumps(uploaded_all)
resp = Response(data,status=200,mimetype='application/json')
resp.headers['Link'] = 'http://localhost:5000'
return resp