Exemplo n.º 1
0
def save_file(file_attr, file_data, user, sub_folder):
    filename = ''
    try:
        filename = resource_uploader.save(file_data, folder=sub_folder,
                                          name=file_attr.name.data + '.')
        current_app.logger.info('Upload File: ' + filename)
        rc = Resource()
        rc.filename = filename
        rc.name = file_attr.name.data
        rc.link = file_attr.link.data
        rc.description = file_attr.description.data
        rc.user = user
        rc.level = file_attr.level.data if int(file_attr.level.data) in xrange(0, 3) else ResourceLevel.PRIVATE
        rc.usage = file_attr.usage.data if int(file_attr.usage.data) in xrange(0, 6) else ResourceUsage.OTHER_RES
        rc.upload_time = datetime.now()
        rc.type = get_type(rc.file_type)
        rc.save()
        return 'OK'
    except UploadNotAllowed:
        current_app.logger.error(traceback.format_exc())
        return 'your upload is not allowed'
    except IntegrityError:
        os.remove(resource_uploader.path(filename))
        db.session.rollback()
        current_app.logger.error(traceback.format_exc())
        return 'file name exist'
    except Exception:
        current_app.logger.error(traceback.format_exc())
        return 'filed to save your upload'
Exemplo n.º 2
0
def save_file(file_attr, file_data, user):
    filename = ''
    try:
        filename = resource.save(file_data, name=file_attr.name.data + '.')
        rc = Resource()
        rc.filename = filename
        rc.name = file_attr.name.data
        rc.description = file_attr.description.data
        rc.user = user
        rc.level = file_attr.level.data if int(file_attr.level.data) in xrange(0, 3) else ResourceLevel.PRIVATE
        rc.usage = file_attr.usage.data if int(file_attr.usage.data) in xrange(0, 5) else ResourceUsage.OTHER_RES
        rc.upload_time = datetime.now()
        rc.type = get_type(rc.file_type)
        rc.save()
        return 'OK'
    except UploadNotAllowed:
        return 'your upload is not allowed'
    except IntegrityError:
        os.remove(resource.path(filename))
        db.session.rollback()
        return 'file name exist'
    except Exception, e:
        return 'filed to save you upload'
Exemplo n.º 3
0
def save_file(file_attr, file_data, user):
    filename = ''
    try:
        filename = resource.save(file_data, name=file_attr.name.data + '.')
        rc = Resource()
        rc.filename = filename
        rc.name = file_attr.name.data
        rc.description = file_attr.description.data
        rc.user = user
        rc.level = file_attr.level.data if int(file_attr.level.data) in xrange(
            0, 3) else ResourceLevel.PRIVATE
        rc.usage = file_attr.usage.data if int(file_attr.usage.data) in xrange(
            0, 5) else ResourceUsage.OTHER_RES
        rc.upload_time = datetime.now()
        rc.type = get_type(rc.file_type)
        rc.save()
        return 'OK'
    except UploadNotAllowed:
        return 'your upload is not allowed'
    except IntegrityError:
        os.remove(resource.path(filename))
        db.session.rollback()
        return 'file name exist'
    except Exception, e:
        return 'filed to save you upload'