CollectionObject

class docushare.CollectionObject(docushare, hdl, title, object_handles)

Bases: DocuShareBaseObject

Represents one Collection object in DocuShare.

Parameters
  • docushare (DocuShare) – The DocuShare site that this object belongs to.

  • hdl (Handle) – The DocuShare handle that represents this object. The type must be HandleType.Collection.

  • title (str) – Title of this collection.

  • object_handles (list) – Handles of the objects under this collection. list of Handle instances.’

Attributes Summary

docushare

The DocuShare site that this object belongs to.

handle

The DocuShare handle that represents this object.

object_handle_tree

Tree structure under this collection.

object_handles

Handles of the objects under this collection.

title

Title of this collection.

Methods Summary

download([destination_path, option, ...])

Downlaod the documents in this Collection.

Attributes Documentation

docushare

The DocuShare site that this object belongs to.

Type

DocuShare

handle

The DocuShare handle that represents this object.

Type

Handle

object_handle_tree

Tree structure under this collection.

The root node of the tree structure is this collection. Each node is an instance of CollectionHandleNode or DocumentHandleNode. In addition to the DocuShare handle information (e.g. Collection-xxxxx, Document-zzzzz), these classes include the parent/child relation information using anytree.node.nodemixin.NodeMixin. Therefore, you can traverse, visualize and search the tree structure using anytree API.

Examples

The example below shows the tree structure under the Collection-10000.

>>> from docushare import *
>>> from anytree import RenderTree
>>> ds = DocuShare(base_url='https://your.docushare.domain/docushare/')
>>> ds.login()
>>> collection = ds['Collection-10000']
>>> print(RenderTree(collection.object_handle_tree).by_attr('identifier'))
Collection-10000
├── Collection-11000
│   ├── Document-11001
│   └── Document-11002
├── Collection-12000
│   ├── Document-12001
│   └── Document-12002
├── Document-10001
├── Document-10002
└── Document-10003

In principle, each node in the tree contains only handle and parent/child information. To show more information like title in the tree visualization, you need to query properties like this:

>>> for pre, fill, handle in RenderTree(collection.object_handle_tree):
...     node_str = f'{pre}{handle}'
...     hdl_obj = ds[handle]
...     print(node_str.ljust(25), hdl_obj.title)
Collection-10000          (Title of Collection-10000)
├── Collection-11000      (Title of Collection-11000)
│   ├── Document-11001    (Title of Document-11001)
│   └── Document-11002    (Title of Document-11001)
├── Collection-12000      (Title of Collection-12000)
│   ├── Document-12001    (Title of Document-12001)
│   └── Document-12002    (Title of Document-12002)
├── Document-10001        (Title of Document-10001)
├── Document-10002        (Title of Document-10002)
└── Document-10003        (Title of Document-10003)

If you want to get all Document handles under Collection-10000 and its descendant Collections, you may want to use CollectionHandleNode.leaves():

>>> for doc_hdl in collection.object_handle_tree.leaves:
...     doc_obj = ds[doc_hdl]
...     print(f'{doc_hdl.identifier}    {doc_obj.title}')
Document-11001    (Title of Document-11001)
Document-11002    (Title of Document-11001)
Document-12001    (Title of Document-12001)
Document-12002    (Title of Document-12002)
Document-10001    (Title of Document-10001)
Document-10002    (Title of Document-10002)
Document-10003    (Title of Document-10003)
object_handles

Handles of the objects under this collection.

Type

list of Handle

title

Title of this collection.

Type

str

Methods Documentation

download(destination_path=None, option=CollectionDownloadOption.CHILD_ONLY, progress_report=True)

Downlaod the documents in this Collection.

Parameters
  • destination_path (path-like object or None) – This method downloads the documents in this Collection to this directory. If it is None, they will be downloaded to the current directory.

  • option (CollectionDownloadOption) – See CollectionDownloadOption for more details.

  • progress_report (bool) – Show progress bar using tqdm <https://tqdm.github.io/> if it is True.

Returns

list of downloaded files as pathlib.Path.

Return type

list