本文整理汇总了Python中project.model.Project.get_datafile方法的典型用法代码示例。如果您正苦于以下问题:Python Project.get_datafile方法的具体用法?Python Project.get_datafile怎么用?Python Project.get_datafile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project.model.Project
的用法示例。
在下文中一共展示了Project.get_datafile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_export
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import get_datafile [as 别名]
def download_export(project_id,entry_id,export_type):
project = Project()
project.get(project_id)
metadata = project.get_exported_file(entry_id,export_type)
file_ = project.get_datafile(str(metadata['file_id']))
response = make_response(file_.read())
response.headers['Content-Description'] = 'Uploaded File'
response.headers['Content-Type'] = 'application/%s' % file_.content_type
response.headers['Content-Length'] = file_.length
response.headers['Content-Disposition'] = 'attachment; filename=%s' % file_.filename
return response
示例2: get_data_upload
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import get_datafile [as 别名]
def get_data_upload(project_id,entry_id,file_id):
# this will allow download of the file.
project = Project()
project.get(project_id)
metadata = project.get_datafile_metadata(entry_id,file_id)
response = make_response(project.get_datafile(file_id).read())
response.headers['Content-Description'] = 'Uploaded File'
response.headers['Content-Type'] = 'application/%s' % metadata['filename'].split('.')[-1]
response.headers['Content-Length'] = metadata['size']
response.headers['Content-Disposition'] = 'attachment; filename=%s' % metadata['filename']
return response
示例3: export_worker
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import get_datafile [as 别名]
def export_worker(msg):
project = Project()
project.get(msg['project_id'])
completed = project.export_completed(msg['entry_id'],msg['format'])
file_id = ''
if completed:
print 'task completed, making sure file need to regenerated'
metadata = project.get_exported_file(msg['entry_id'],msg['format'])
if metadata['file_id']:
f = project.get_datafile(metadata['file_id'])
uploaded_date = f.upload_date
last_updated = project.get_entry_updated()
print uploaded_date
print last_updated
if last_updated > uploaded_date:
print 'file need regen'
task = export_single.delay(msg['project_id'],msg['entry_id'],msg['format'])
print task
project.set_exporter_task(msg['entry_id'],msg['format'],task.id)
completed = project.export_completed(msg['entry_id'],msg['format'])
else:
task = export_single.delay(msg['project_id'],msg['entry_id'],msg['format'])
project.set_exporter_task(msg['entry_id'],msg['format'],task.id)
completed = project.export_completed(msg['entry_id'],msg['format'])
while not completed:
completed = project.export_completed(msg['entry_id'],msg['format'])
yield {'completed':False,'file_id':file_id,'format':msg['format'],
'project_id':msg['project_id'],'entry_id':msg['entry_id']}
time.sleep(1)
project.get(msg['project_id'])
metadata = project.get_exported_file(msg['entry_id'],msg['format'])
print metadata['file_id']
f = project.get_datafile(metadata['file_id'])
file_id = metadata['file_id']
yield {'completed':True,'file_id':file_id,'format':msg['format'],
'project_id':msg['project_id'],'entry_id':msg['entry_id']}
示例4: test_project_file_download
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import get_datafile [as 别名]
def test_project_file_download():
content = "a,b,c\n1,2,3\n4,5,6"
project = Project()
project.find('test project download')
data = project.project.input_file
entry_id = project.find_entry('test entries')
files = data[entry_id]
valid_flag = False
for file_id in files:
test_file = project.get_datafile(file_id)
test_data = test_file.read()
if test_data == content:
valid_flag = True
assert valid_flag
示例5: load_data_upload
# 需要导入模块: from project.model import Project [as 别名]
# 或者: from project.model.Project import get_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