def make_files_preview_compatible(files): """Processes a list of RecordFiles to a list of FileObjects. This is needed to make the objects compatible with invenio-previewer. """ file_objects = [] for file in files: file_objects.append( FileObject(obj=files[file].object_version, data={}).dumps()) return file_objects
def previewer_record_file_factory(pid, record, filename): """Get file from a record. :param pid: Not used. It keeps the function signature. :param record: Record which contains the files. :param filename: Name of the file to be returned. :returns: Previewer compatible File object or ``None`` if not found. """ try: if not (hasattr(record, 'files') and record.files): return None except MissingModelError: return None try: rf = record.files.get(filename) if rf is not None: return FileObject(obj=rf.file, data=rf.metadata or {}) except KeyError: return None
def to_previewer_files(record): """Get previewer-compatible files list.""" return [ FileObject(obj=f.object_version, data=f.metadata or {}) for f in record.files.values() ]