def get_attached_folders(linked_object, include_empty=True, include_hidden=True, preload_event=False): """ Return a list of all the folders linked to an object. :param linked_object: The object whose attachments are to be returned :param include_empty: Whether to return empty folders as well. :param include_hidden: Include folders that the user can't see :param preload_event: in the process, preload all objects tied to the corresponding event and keep them in cache """ from indico.modules.attachments.models.folders import AttachmentFolder folders = AttachmentFolder.get_for_linked_object( linked_object, preload_event=preload_event) if not include_hidden: folders = [f for f in folders if f.can_view(session.user)] if not include_empty: folders = [f for f in folders if f.attachments] return folders
def _addMaterialFrom(self, target, categoryPath): for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True): for attachment in folder.attachments: if attachment.type == AttachmentType.file: dst_path = posixpath.join(self._mainPath, "files", categoryPath, "{}-{}".format(attachment.id, attachment.file.filename)) with attachment.file.get_local_path() as file_path: self._addFileFromSrc(dst_path, file_path)
def _addMaterialFrom(self, target, categoryPath): for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True): for attachment in folder.attachments: if attachment.type == AttachmentType.file: dst_path = posixpath.join(self._mainPath, "files", categoryPath, "{}-{}".format(attachment.id, attachment.file.filename)) with attachment.file.get_local_path() as file_path: self._addFileFromSrc(dst_path, file_path)
def _add_material(self, target, type_): for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True): for attachment in folder.attachments: if not attachment.can_access(None): continue if attachment.type == AttachmentType.file: dst_path = posixpath.join(self._content_dir, "material", type_, f"{attachment.id}-{attachment.file.filename}") with attachment.file.get_local_path() as file_path: self._copy_file(dst_path, file_path)
def _add_material(self, target, type_): for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True): for attachment in folder.attachments: if not attachment.can_access(None): continue if attachment.type == AttachmentType.file: dst_path = posixpath.join(self._content_dir, "material", type_, "{}-{}".format(attachment.id, attachment.file.filename)) with attachment.file.get_local_path() as file_path: self._copy_file(dst_path, file_path)
def get_attached_folders(linked_object, include_empty=True, include_hidden=True, preload_event=False): """ Return a list of all the folders linked to an object. :param linked_object: The object whose attachments are to be returned :param include_empty: Whether to return empty folders as well. :param include_hidden: Include folders that the user can't see :param preload_event: in the process, preload all objects tied to the corresponding event and keep them in cache """ from indico.modules.attachments.models.folders import AttachmentFolder folders = AttachmentFolder.get_for_linked_object(linked_object, preload_event=preload_event) if not include_hidden: folders = [f for f in folders if f.can_view(session.user)] if not include_empty: folders = [f for f in folders if f.attachments] return folders