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
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
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)
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)
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)
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)
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
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()
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))
def view(id): file = object_or_404(File.by_id(id)) authz.require(authz.project_read(file.project)) return jsonify(file)