CollectionObject
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
ofHandle
instances.’
Attributes Summary
The DocuShare site that this object belongs to.
The DocuShare handle that represents this object.
Tree structure under this collection.
Handles of the objects under this collection.
Title of this collection.
Methods Summary
download
([destination_path, option, ...])Downlaod the documents in this Collection.
Attributes Documentation
The DocuShare site that this object belongs to.
- Type
The DocuShare handle that represents this object.
- Type
Tree structure under this collection.
The root node of the tree structure is this collection. Each node is an instance of
CollectionHandleNode
orDocumentHandleNode
. In addition to the DocuShare handle information (e.g. Collection-xxxxx, Document-zzzzz), these classes include the parent/child relation information usinganytree.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)
Title of this collection.
- Type
Methods Documentation
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 aspathlib.Path
.- Return type