1- import enum
2-
3-
4- class Include (enum .Enum ):
5- """
6- Include is enum that Provides Options to perform operation to query the result.
7-
8- Available Options for QueryOperation are below.
9- DEFAULT, ONLY, EXCEPT
10-
11- Arguments:
12- enum {Include} -- Type of IncludeReference
13- """
14- EXCEPT = 'except'
15- ONLY = 'only'
16- DEFAULT = ''
1+ """
2+ EntryQueryable class contains common functions
3+ that is used as parents class for the query and entry classes
4+ """
175
186
197class EntryQueryable :
208 """
219 This class is base class for the Entry and Query class that shares common functions
2210 """
11+
2312 def __init__ (self ):
2413 self .entry_queryable_param = {}
2514
@@ -53,7 +42,7 @@ def locale(self, locale: str):
5342 self .entry_queryable_param ['locale' ] = locale
5443 return self
5544
56- def only (self , field_uid ):
45+ def only (self , field_uid : str ):
5746 """
5847 Specifies an array of only keys in BASE object that would be included in the response.
5948 It refers to the top-level fields of the schema
@@ -62,57 +51,61 @@ def only(self, field_uid):
6251 self -- so you can chain this call.
6352 """
6453 if field_uid is not None :
65- self .entry_queryable_param ['only[BASE][]' ] = field_uid
66- return self
54+ if isinstance (field_uid , str ):
55+ self .entry_queryable_param ['only[BASE][]' ] = field_uid
56+ else :
57+ raise KeyError ("Invalid field_uid provided" )
58+ return self
6759
68- def excepts (self , field_uid ):
60+ def excepts (self , field_uid : str ):
6961 """
7062 Specifies list of field_uid that would be excluded from the response.
7163 It refers to the top-level fields of the schema
7264 :param field_uid: to be excluded from the response.
7365 :return: self -- so you can chain this call.
7466 """
7567 if field_uid is not None :
76- self .entry_queryable_param ['except[BASE][]' ] = field_uid
77- return self
68+ if isinstance (field_uid , str ):
69+ self .entry_queryable_param ['except[BASE][]' ] = field_uid
70+ else :
71+ raise KeyError ("Invalid field_uid provided" )
72+ return self
7873
79- def include_reference (self , include_reference_type : Include , reference_field_uid : str , field_uid = None ):
74+ def include_reference (self , field_uid ):
8075 """
8176 **Include Reference:**
8277 When you fetch an entry of a content type that has a reference field,
8378 by default, the content of the referred entry is not fetched.
8479 It only fetches the UID of the referred entry, along with the content of
8580 the specified entry.
8681
82+ Note: The maximum reference depth limit to which a multiple content type
83+ referencing Reference field works is three levels deep
84+
8785 Arguments:
88- reference_field_uid {str} -- Key who has reference to some other class object.
8986 Array of the only reference keys to be included in response
90- include_type {Include} -- Provides three options, none, only and except
91- i.e accepts list of field_uid
92- field_uid {list} -- list of field_uid on which include operation to perform
87+ field_uid {str or list of str} -- [str/list of str] of field_uid on
88+ which include operation to perform
9389
9490 Returns:
9591 self -- So you can chain this call.
92+
93+ >>> import contentstack
94+ >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
95+ >>> entry = stack.content_type('content_type')
96+ >>> entry("entry_uid").include_reference(["categories", "brand"])
97+ >>> result = entry.fetch()
9698 """
97- container = {}
98- if reference_field_uid is None :
99- raise KeyError ("reference_field_uid can't be None" )
100- if include_reference_type .name == 'DEFAULT' :
101- self .entry_queryable_param ["include[]" ] = reference_field_uid
102- else :
103- container [reference_field_uid ] = field_uid
104- self .entry_queryable_param ["include[]" ] = {include_reference_type .value : container }
99+ if field_uid is not None and isinstance (field_uid , (str , list )):
100+ self .entry_queryable_param ["include[]" ] = field_uid
105101 return self
106102
107103 def include_content_type (self ):
108104 """
109105 This method also includes the ContentType in the entry
110106 :return: self: so you can chain this call.
111-
112107 -------------------------------
113-
114108 [Example: for Entry]
115-
116109 >>> import contentstack
117110 >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
118111 >>> content_type = stack.content_type('content_type_uid')
0 commit comments