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 = ''
171
182
193class EntryQueryable :
204 """
215 This class is base class for the Entry and Query class that shares common functions
226 """
7+
238 def __init__ (self ):
249 self .entry_queryable_param = {}
10+ self .entry_include_array = []
11+ self .entry_include_dict = {}
2512
2613 def locale (self , locale : str ):
2714 """
@@ -53,7 +40,7 @@ def locale(self, locale: str):
5340 self .entry_queryable_param ['locale' ] = locale
5441 return self
5542
56- def only (self , field_uid ):
43+ def only (self , field_uid : str ):
5744 """
5845 Specifies an array of only keys in BASE object that would be included in the response.
5946 It refers to the top-level fields of the schema
@@ -62,57 +49,56 @@ def only(self, field_uid):
6249 self -- so you can chain this call.
6350 """
6451 if field_uid is not None :
65- self .entry_queryable_param ['only[BASE][]' ] = field_uid
66- return self
52+ if isinstance (field_uid , str ):
53+ self .entry_queryable_param ['only[BASE][]' ] = [field_uid ]
54+ else :
55+ raise KeyError ("Invalid field_uid provided" )
56+ return self
6757
68- def excepts (self , field_uid ):
58+ def excepts (self , field_uid : str ):
6959 """
7060 Specifies list of field_uid that would be excluded from the response.
7161 It refers to the top-level fields of the schema
7262 :param field_uid: to be excluded from the response.
7363 :return: self -- so you can chain this call.
7464 """
7565 if field_uid is not None :
76- self .entry_queryable_param ['except[BASE][]' ] = field_uid
77- return self
66+ if isinstance (field_uid , str ):
67+ self .entry_queryable_param ['except[BASE][]' ] = [field_uid ]
68+ else :
69+ raise KeyError ("Invalid field_uid provided" )
70+ return self
7871
79- def include_reference (self , include_reference_type : Include , reference_field_uid : str , field_uid = None ):
72+ def include_reference (self , field_uid ):
8073 """
8174 **Include Reference:**
8275 When you fetch an entry of a content type that has a reference field,
8376 by default, the content of the referred entry is not fetched.
8477 It only fetches the UID of the referred entry, along with the content of
8578 the specified entry.
8679
80+ Note: The maximum reference depth limit to which a multiple content type
81+ referencing Reference field works is three levels deep
82+
8783 Arguments:
88- reference_field_uid {str} -- Key who has reference to some other class object.
8984 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
85+ field_uid {str or list of str} -- [str/list of str] of field_uid on which include operation to perform
9386
9487 Returns:
9588 self -- So you can chain this call.
9689 """
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 }
90+ if field_uid is not None and isinstance (field_uid , str ):
91+ self .entry_queryable_param ["include[]" ] = [field_uid ]
92+ if field_uid is not None and isinstance (field_uid , list ) and len (field_uid ) > 0 :
93+ self .entry_queryable_param ["include[]" ] = field_uid
10594 return self
10695
10796 def include_content_type (self ):
10897 """
10998 This method also includes the ContentType in the entry
11099 :return: self: so you can chain this call.
111-
112100 -------------------------------
113-
114101 [Example: for Entry]
115-
116102 >>> import contentstack
117103 >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
118104 >>> content_type = stack.content_type('content_type_uid')
0 commit comments