本文整理汇总了Python中project.model.Project.add_datafile方法的典型用法代码示例。如果您正苦于以下问题:Python Project.add_datafile方法的具体用法?Python Project.add_datafile怎么用?Python Project.add_datafile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project.model.Project
的用法示例。
在下文中一共展示了Project.add_datafile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_test_load_data
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import add_datafile [as 别名]
def setup_test_load_data():
project = Project()
project.create('test load data',' list entries')
content = "a,b,c\n1,2,3\n4,5,6"
f = MockFile('test_data.csv',content)
entry_id = project.add_entry('test entries','test entries','test_entries','testdata')
project.add_datafile(entry_id,f)
示例2: test_project_file_upload
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import add_datafile [as 别名]
def test_project_file_upload():
content = "a,b,c\n1,2,3\n4,5,6"
test_data = cStringIO.StringIO(content)
f = MockFile('test_data.csv',content)
project = Project()
project.find('test project upload')
entry_id = project.find_entry('test entries')
project.add_datafile(entry_id,f)
input_file = project.project.input_file
exist_flag = False
for entry in input_file:
for file_id in input_file[entry]:
if input_file[entry][file_id]['filename'] == 'test_data.csv':
exist_flag = True
assert exist_flag
示例3: load_data_upload
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import add_datafile [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