コード例 #1
0
ファイル: util.py プロジェクト: qroques/indico
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
コード例 #2
0
 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)
コード例 #3
0
 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)
コード例 #4
0
ファイル: offline.py プロジェクト: mkopcic/indico
 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)
コード例 #5
0
ファイル: offline.py プロジェクト: jas01/indico
 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)
コード例 #6
0
ファイル: util.py プロジェクト: indico/indico
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