示例#1
0
 def decode(self, node, cstruct):
     if isinstance(cstruct, File):
         return cstruct
     if isinstance(cstruct, (int, basestring)):
         return File.by_id(cstruct)
     if isinstance(cstruct, dict):
         if cstruct.get('id'):
             return File.by_id(cstruct.get('id'))
     return None
示例#2
0
 def decode(self, node, cstruct):
     if isinstance(cstruct, File):
         return cstruct
     if isinstance(cstruct, (int, basestring)):
         return File.by_id(cstruct)
     if isinstance(cstruct, dict):
         if cstruct.get('id'):
             return File.by_id(cstruct.get('id'))
     return None
示例#3
0
文件: files_api.py 项目: jacqui/grano
def serve(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    sio = StringIO()
    sio.write(file.data)
    sio.seek(0)
    res = send_file(sio, mimetype=file.mime_type)
    res.headers['Content-Disposition'] = 'filename=%s' % file.file_name
    return res
示例#4
0
def serve(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    sio = StringIO()
    sio.write(file.data)
    sio.seek(0)
    res = send_file(sio, mimetype=file.mime_type)
    res.headers['Content-Disposition'] = 'filename=%s' % file.file_name
    return res
示例#5
0
文件: files_api.py 项目: jacqui/grano
def index():
    query = File.all()
    query = query.join(Project)
    query = query.outerjoin(Permission)
    query = query.filter(or_(Project.private == False,
        and_(Permission.reader == True, Permission.account==request.account)))

    if request.args.get('project'):
        query = query.filter(Project.slug == request.args.get('project'))

    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
示例#6
0
def generate(id, file_name, config_name):
    filepath = logic.get_file_location(file_name, id, config_name)
    if not os.path.exists(filepath):
        file = object_or_404(File.by_id(id))
        if config_name not in IMAGE_CONFIG:
            abort(404)
        try:
            logic.validate_file(file)
        except ValueError:
            return abort(400, "File is not a supported image format")
        config = IMAGE_CONFIG.get(config_name)
        new_file = logic.transform(file, (config['width'], config['height']))
        logic.store_file(new_file, filepath)

    return send_file(filepath)
示例#7
0
def index():
    query = File.all()
    query = query.join(Project)
    query = query.outerjoin(Permission)
    query = query.filter(
        or_(
            Project.private == False,
            and_(Permission.reader == True,
                 Permission.account == request.account)))

    if request.args.get('project'):
        query = query.filter(Project.slug == request.args.get('project'))

    query = query.distinct()
    pager = Pager(query)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
示例#8
0
def run_importer(pipeline_id):
    """ Perform a raw data import with a given mode. """

    pipeline = Pipeline.by_id(pipeline_id)
    pipelines.start(pipeline)

    mode = pipeline.config.get('mode')
    file_id = pipeline.config.get('file')
    file_ = File.by_id(file_id)
    if file_ is None:
        pipeline.log_error(pipeline, 'File object deleted: %s' % file_id)
    elif mode == 'aliases':
        import_aliases(pipeline, file_.fh)
    else:
        import_objects(pipeline, file_.fh)

    pipelines.finish(pipeline)
示例#9
0
文件: imports.py 项目: 01-/grano
def run_importer(pipeline_id):
    """ Perform a raw data import with a given mode. """

    pipeline = Pipeline.by_id(pipeline_id)
    pipelines.start(pipeline)

    mode = pipeline.config.get('mode')
    file_id = pipeline.config.get('file')
    file_ = File.by_id(file_id)
    if file_ is None:
        pipeline.log_error(pipeline, 'File object deleted: %s' % file_id)
    elif mode == 'aliases':
        import_aliases(pipeline, file_.fh)
    else:
        import_objects(pipeline, file_.fh)

    pipelines.finish(pipeline)
示例#10
0
def save(data, file_data, file=None):
    """ Save or update a file. """
    if file_data is None:
        raise BadRequest("No file given!")
    
    data.update({
        'file_name': file_data.filename,
        'mime_type': file_data.mimetype
        })
    sane = validate(data, file)
    
    if file is None:
        file = File()
        file.project = sane.get('project')
        file.author = sane.get('author')
        db.session.add(file)

    file.file_name = sane.get('file_name')
    file.mime_type = sane.get('mime_type')
    file.data = file_data.read()

    db.session.flush()
    return file
示例#11
0
文件: files.py 项目: 01-/grano
def save(data, file_data, file=None):
    """ Save or update a file. """
    if file_data is None:
        raise BadRequest("No file given!")

    data.update({
        'file_name': file_data.filename,
        'mime_type': file_data.mimetype
        })
    sane = validate(data, file)

    if file is None:
        file = File()
        file.project = sane.get('project')
        file.author = sane.get('author')
        db.session.add(file)

    file.file_name = sane.get('file_name')
    file.mime_type = sane.get('mime_type')
    file.data = file_data.read()

    db.session.flush()
    return file
示例#12
0
def delete(id):
    file_ = object_or_404(File.by_id(id))
    authz.require(authz.project_edit(file_.project))
    entities.delete(file_)
    db.session.commit()
    raise Gone()
示例#13
0
def table(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    limit = get_limit(10)
    validate_cache(keys={'id': file.id, 'limit': limit})
    return jsonify(files.as_table(file, limit))
示例#14
0
文件: files_api.py 项目: jacqui/grano
def view(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    return jsonify(file)
示例#15
0
def view(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    return jsonify(file)
示例#16
0
文件: files_api.py 项目: jacqui/grano
def table(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    limit = get_limit(10)
    validate_cache(keys={'id': file.id, 'limit': limit})
    return jsonify(files.as_table(file, limit))
示例#17
0
文件: files_api.py 项目: jacqui/grano
def delete(id):
    file_ = object_or_404(File.by_id(id))
    authz.require(authz.project_edit(file_.project))
    entities.delete(file_)
    db.session.commit()
    raise Gone()