Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 6149ebc

Browse files
committed
Added filter functions property accessor with documentation
1 parent 67326b6 commit 6149ebc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/cloudant/design_document.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ def validate_doc_update(self):
7474
"""
7575
return self.get('validate_doc_update')
7676

77+
@property
78+
def filters(self):
79+
"""
80+
Provides an accessor property to the filters dictionary in the locally cached
81+
DesignDocument. Filter functions enable you to add tests for filtering each
82+
of the objects included in the changes feed. If any of the function tests
83+
fail, the object is filtered from the feed. If the function returns a true
84+
result when applied to a change, the change remains in the feed.
85+
86+
Filter functions require two arguments: ``doc`` and ``req``. The ``doc`` argument
87+
represents the document being tested for filtering. The ``req`` argument contains
88+
additional information about the HTTP request.
89+
90+
Filter function example:
91+
92+
.. code-block:: python
93+
94+
# Add the filter function to ``filters`` and save the design document
95+
ddoc = DesignDocument(self.db, '_design/ddoc001')
96+
# Filter and remove documents that are not of ``type`` mail
97+
ddoc['filters'] = {
98+
'filter001': 'function(doc, req){if (doc.type != \'mail\'){return false;} '
99+
'return true;} '
100+
}
101+
ddoc.save()
102+
103+
To execute filter functions on a changes feed, see the database API
104+
:func:`~cloudant.database.CouchDatabase.changes`
105+
106+
For more details, see the `Filter functions documentation
107+
<https://docs.cloudant.com/design_documents.html#filter-functions>`_.
108+
109+
:returns: Dictionary containing filter function names and functions
110+
as key/value
111+
"""
112+
return self.get('filters')
113+
77114
@property
78115
def updates(self):
79116
"""

0 commit comments

Comments
 (0)