@@ -44,7 +44,7 @@ def __init__(self, database, document_id=None):
4444 if document_id and not document_id .startswith ('_design/' ):
4545 document_id = '_design/{0}' .format (document_id )
4646 super (DesignDocument , self ).__init__ (database , document_id )
47- self ._nested_object_names = frozenset (['views' , 'indexes' , 'lists' ])
47+ self ._nested_object_names = frozenset (['views' , 'indexes' , 'lists' , 'shows' ])
4848 for prop in self ._nested_object_names :
4949 self .setdefault (prop , dict ())
5050
@@ -98,6 +98,17 @@ def lists(self):
9898 """
9999 return self .get ('lists' )
100100
101+ @property
102+ def shows (self ):
103+ """
104+ Provides an accessor property to the shows dictionary in the
105+ locally cached DesignDocument.
106+
107+ :returns: Dictionary containing show names and functions
108+ as key/value
109+ """
110+ return self .get ('shows' )
111+
101112 @property
102113 def rewrites (self ):
103114 """
@@ -215,6 +226,21 @@ def add_list_function(self, list_name, list_func):
215226
216227 self .lists .__setitem__ (list_name , codify (list_func ))
217228
229+ def add_show_function (self , show_name , show_func ):
230+ """
231+ Appends a show function to the locally cached DesignDocument
232+ shows dictionary.
233+
234+ :param show_name: Name used to identify the show function.
235+ :param show_func: Javascript show function.
236+ """
237+ if self .get_show_function (show_name ) is not None :
238+ msg = ('A show function with name {0} already exists in this design doc'
239+ .format (show_name ))
240+ raise CloudantArgumentError (msg )
241+
242+ self .shows .__setitem__ (show_name , show_func )
243+
218244 def update_view (self , view_name , map_func , reduce_func = None , ** kwargs ):
219245 """
220246 Modifies/overwrites an existing MapReduce view definition in the
@@ -276,6 +302,21 @@ def update_list_function(self, list_name, list_func):
276302
277303 self .lists .__setitem__ (list_name , codify (list_func ))
278304
305+ def update_show_function (self , show_name , show_func ):
306+ """
307+ Modifies/overwrites an existing show function in the
308+ locally cached DesignDocument shows dictionary.
309+
310+ :param show_name: Name used to identify the show function.
311+ :param show_func: Javascript show function.
312+ """
313+ if self .get_show_function (show_name ) is None :
314+ msg = ('A show function with name {0} does not exist in this design doc'
315+ .format (show_name ))
316+ raise CloudantArgumentError (msg )
317+
318+ self .shows .__setitem__ (show_name , show_func )
319+
279320 def delete_view (self , view_name ):
280321 """
281322 Removes an existing MapReduce view definition from the locally cached
@@ -317,6 +358,18 @@ def delete_list_function(self, list_name):
317358 """
318359 self .lists .__delitem__ (list_name )
319360
361+ def delete_show_function (self , show_name ):
362+ """
363+ Removes an existing show function in the locally cached DesignDocument
364+ shows dictionary.
365+
366+ :param show_name: Name used to identify the list.
367+ """
368+ if self .get_show_function (show_name ) is None :
369+ return
370+
371+ self .shows .__delitem__ (show_name )
372+
320373 def fetch (self ):
321374 """
322375 Retrieves the remote design document content and populates the locally
@@ -346,7 +399,7 @@ def fetch(self):
346399 )
347400
348401 for prop in self ._nested_object_names :
349- # Ensure views, indexes, and lists dict exist in locally cached DesignDocument.
402+ # Ensure dict for each sub-object exists in locally cached DesignDocument.
350403 getattr (self , prop , self .setdefault (prop , dict ()))
351404
352405 # pylint: disable=too-many-branches
@@ -394,7 +447,7 @@ def save(self):
394447
395448 for prop in self ._nested_object_names :
396449 if not getattr (self , prop ):
397- # Ensure empty views, indexes, or lists dict is not saved remotely.
450+ # Ensure empty dict for each sub-object is not saved remotely.
398451 self .__delitem__ (prop )
399452
400453 super (DesignDocument , self ).save ()
@@ -462,6 +515,17 @@ def iterlists(self):
462515 for list_name , list_func in iteritems_ (self .lists ):
463516 yield list_name , list_func
464517
518+ def itershows (self ):
519+ """
520+ Provides a way to iterate over the locally cached DesignDocument
521+ shows dictionary.
522+
523+ :returns: Iterable containing show function name and associated
524+ show function
525+ """
526+ for show_name , show_func in iteritems_ (self .shows ):
527+ yield show_name , show_func
528+
465529 def list_views (self ):
466530 """
467531 Retrieves a list of available View objects in the locally cached
@@ -489,6 +553,15 @@ def list_list_functions(self):
489553 """
490554 return list (self .lists .keys ())
491555
556+ def list_show_functions (self ):
557+ """
558+ Retrieves a list of available show functions in the locally cached
559+ DesignDocument shows dictionary.
560+
561+ :returns: List of show function names
562+ """
563+ return list (self .shows .keys ())
564+
492565 def get_view (self , view_name ):
493566 """
494567 Retrieves a specific View from the locally cached DesignDocument by
@@ -518,10 +591,21 @@ def get_list_function(self, list_name):
518591
519592 :param str list_name: Name used to identify the list function.
520593
521- :returns: Index dictionary for the specified list function name
594+ :returns: String form of the specified list function
522595 """
523596 return self .lists .get (list_name )
524597
598+ def get_show_function (self , show_name ):
599+ """
600+ Retrieves a specific show function from the locally cached DesignDocument
601+ shows dictionary by name.
602+
603+ :param str show_name: Name used to identify the show function.
604+
605+ :returns: String form of the specified show function
606+ """
607+ return self .shows .get (show_name )
608+
525609 def info (self ):
526610 """
527611 Retrieves the design document view information data, returns dictionary
0 commit comments