Example #1
0
def do_upload():
    if check_passwd(request.get_cookie("mdp")) == False:
        return template('authentification', get_url=app.get_url)
    try:

        upload = request.files.get('upload')
        name, ext = os.path.splitext(upload.filename)
        if ext not in ('.xlsx'):
            return {
                'get_url': app.get_url,
                'success': 'false',
                'data_fail':
                "File extension not allowed. You must import xlsx only",
                'data': ''
            }

        # we add a random name to the file:
        r = random.randint(1, 1000)
        file_path = str(r) + "{file}".format(path="", file=upload.filename)
        upload.save(file_path)
        val = import_xlsx.importation(file_path)
        if val['success'] == True:
            print("import ok")
            return {
                'get_url': app.get_url,
                'success': 'true',
                'data': json.dumps(val['data']),
                'data_fail': ''
            }
        else:
            return {
                'get_url': app.get_url,
                'success': 'false',
                'data_fail': val['data'],
                'data': ''
            }
    except Exception, err:
        return {
            'get_url': app.get_url,
            'success': 'false',
            'data_fail': traceback.format_exc(),
            'data': ''
        }
Example #2
0
def do_upload():
    if check_passwd(request.get_cookie("mdp"))==False:
        return template('authentification', get_url=app.get_url)
    try:
    
        upload = request.files.get('upload')
        name, ext = os.path.splitext(upload.filename)
        if ext not in ('.xlsx'):
            return { 'get_url':  app.get_url, 'success':'false', 'data_fail':"File extension not allowed. You must import xlsx only", 'data':''}
        
        #we add a random name to the file:
        r = random.randint(1,1000)
        file_path = str(r)+"{file}".format(path="", file=upload.filename)
        upload.save(file_path)
        val=import_xlsx.importation(file_path)
        if val['success']==True:
            print("import ok")
            return { 'get_url':  app.get_url, 'success':'true', 'data':json.dumps(val['data']), 'data_fail':''}
        else:
            return { 'get_url':  app.get_url, 'success':'false', 'data_fail':val['data'], 'data':''}
    except Exception, err:
        return { 'get_url':  app.get_url, 'success':'false', 'data_fail':traceback.format_exc(), 'data':''}