當前位置: 首頁>>代碼示例>>Python>>正文


Python Project.add_datafile方法代碼示例

本文整理匯總了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)
開發者ID:sweemeng,項目名稱:scrapedump,代碼行數:9,代碼來源:test_project.py

示例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 
開發者ID:sweemeng,項目名稱:scrapedump,代碼行數:19,代碼來源:test_project.py

示例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
開發者ID:sweemeng,項目名稱:scrapedump,代碼行數:64,代碼來源:action.py


注:本文中的project.model.Project.add_datafile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。