Contentstack 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- contentstack/__init__.py +29 -0
- contentstack/asset.py +784 -0
- contentstack/config.py +162 -0
- contentstack/content_type.py +233 -0
- contentstack/entry.py +1162 -0
- contentstack/errors.py +162 -0
- contentstack/http_connection.py +195 -0
- contentstack/query.py +1632 -0
- contentstack/stack.py +760 -0
- contentstack/utils.py +34 -0
- contentstack-0.1.0.dist-info/LICENSE +21 -0
- contentstack-0.1.0.dist-info/METADATA +150 -0
- contentstack-0.1.0.dist-info/RECORD +15 -0
- contentstack-0.1.0.dist-info/WHEEL +5 -0
- contentstack-0.1.0.dist-info/top_level.txt +1 -0
contentstack/query.py
ADDED
|
@@ -0,0 +1,1632 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
Created by Shailesh Mishra on 22/06/19.
|
|
5
|
+
Copyright 2019 Contentstack. All rights reserved.
|
|
6
|
+
|
|
7
|
+
contentstack.query
|
|
8
|
+
~~~~~~~~~~~~~~~~~~
|
|
9
|
+
|
|
10
|
+
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#queries
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Query(object):
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
Contentstack provides certain queries that you can use to fetch filtered results.
|
|
19
|
+
You can use queries for Entries and Assets API requests.
|
|
20
|
+
|
|
21
|
+
[API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#queries]
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, content_type_uid):
|
|
26
|
+
|
|
27
|
+
self.__config = None
|
|
28
|
+
self.__query_url = None
|
|
29
|
+
self.__stack_instance = None
|
|
30
|
+
self.__http_request = None
|
|
31
|
+
|
|
32
|
+
self.__uid_include = []
|
|
33
|
+
self.__uid_except = []
|
|
34
|
+
self.__uid_only = []
|
|
35
|
+
|
|
36
|
+
self.__headers = {}
|
|
37
|
+
self.__query_params = {}
|
|
38
|
+
self.__query_value = {}
|
|
39
|
+
self.__only_json = {}
|
|
40
|
+
self.__query_dict = {}
|
|
41
|
+
self.__except_Json = {}
|
|
42
|
+
self.__main_json = {}
|
|
43
|
+
|
|
44
|
+
if content_type_uid is None or len(content_type_uid.strip()) == 0:
|
|
45
|
+
raise ValueError('Kindly provide content_type_uid as URI Parameters')
|
|
46
|
+
if isinstance(content_type_uid, str):
|
|
47
|
+
self.__content_type_id = content_type_uid
|
|
48
|
+
|
|
49
|
+
def _instance(self, stack_instance):
|
|
50
|
+
|
|
51
|
+
# _instance is protected and it is not accessible out side of package.
|
|
52
|
+
self.__stack_instance = stack_instance
|
|
53
|
+
self.__config = self.__stack_instance.config
|
|
54
|
+
endpoint = self.__config.endpoint
|
|
55
|
+
self.__query_url = '{}/content_types/{}/entries'.format(endpoint, self.__content_type_id)
|
|
56
|
+
self.__http_request = self.__stack_instance.get_http_instance
|
|
57
|
+
|
|
58
|
+
return self
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def content_type(self):
|
|
62
|
+
|
|
63
|
+
"""It returns the content type of the entry.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
str -- It returns the content type of the entry.
|
|
67
|
+
|
|
68
|
+
==============================
|
|
69
|
+
|
|
70
|
+
[Example]:
|
|
71
|
+
|
|
72
|
+
>>> from contentstack import Stack
|
|
73
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
74
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
75
|
+
>>> query = content_type.query()
|
|
76
|
+
>>> content_type = query.content_type
|
|
77
|
+
|
|
78
|
+
==============================
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
return self.__content_type_id
|
|
83
|
+
|
|
84
|
+
@content_type.setter
|
|
85
|
+
def content_type(self, content_type_id):
|
|
86
|
+
|
|
87
|
+
"""The unique ID of the content type of which you wish to retrieve the details.
|
|
88
|
+
The uid is generated based on the title of the content type and it is unique across a stack
|
|
89
|
+
|
|
90
|
+
Arguments:
|
|
91
|
+
content_type_id {str} -- unique ID of the content type of which you wish to retrieve information
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
ValueError: If content_type_id is None
|
|
95
|
+
ValueError: If content_type_id is not str type
|
|
96
|
+
|
|
97
|
+
==============================
|
|
98
|
+
|
|
99
|
+
[Example]:
|
|
100
|
+
>>> from contentstack import Stack
|
|
101
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
102
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
103
|
+
>>> query = content_type.query()
|
|
104
|
+
>>> query.content_type = 'content_type_id'
|
|
105
|
+
|
|
106
|
+
==============================
|
|
107
|
+
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
if content_type_id is None or len(content_type_id.strip()) == 0:
|
|
111
|
+
raise ValueError('Kindly provide valid content_type_id')
|
|
112
|
+
if isinstance(content_type_id, str):
|
|
113
|
+
self.__content_type_id = content_type_id
|
|
114
|
+
else:
|
|
115
|
+
raise ValueError('content_type_id should be str')
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def headers(self):
|
|
119
|
+
|
|
120
|
+
"""Additional header dict for Query.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
dict -- additional header dict for Query
|
|
124
|
+
|
|
125
|
+
==============================
|
|
126
|
+
|
|
127
|
+
[Example]:
|
|
128
|
+
>>> from contentstack import Stack
|
|
129
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
130
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
131
|
+
>>> query = content_type.query()
|
|
132
|
+
>>> query = query.headers
|
|
133
|
+
|
|
134
|
+
==============================
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
return self.__headers
|
|
139
|
+
|
|
140
|
+
def remove_header(self, key):
|
|
141
|
+
|
|
142
|
+
"""It removes header from the Query headers by key.
|
|
143
|
+
|
|
144
|
+
Arguments:
|
|
145
|
+
key {str} -- key of header param
|
|
146
|
+
|
|
147
|
+
Raises:
|
|
148
|
+
ValueError: If key is None or empty
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
Query -- Query, so you can chain this call.
|
|
152
|
+
|
|
153
|
+
==============================
|
|
154
|
+
|
|
155
|
+
[Example]:
|
|
156
|
+
|
|
157
|
+
>>> from contentstack import Stack
|
|
158
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
159
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
160
|
+
>>> query = content_type.query()
|
|
161
|
+
>>> query = query.remove_header('key')
|
|
162
|
+
>>> result = query.find()
|
|
163
|
+
|
|
164
|
+
==============================
|
|
165
|
+
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
if key is None or len(key.strip()) == 0:
|
|
169
|
+
raise ValueError('Kindly provide valid header key')
|
|
170
|
+
if isinstance(key, str) and key in self.__headers:
|
|
171
|
+
self.__headers.pop(key, None)
|
|
172
|
+
|
|
173
|
+
return self
|
|
174
|
+
|
|
175
|
+
def add_header(self, key, value):
|
|
176
|
+
|
|
177
|
+
"""It adds header in the Query headers by key and value.
|
|
178
|
+
|
|
179
|
+
Arguments:
|
|
180
|
+
key {str} -- header's key
|
|
181
|
+
value {object} -- value of the respective key
|
|
182
|
+
|
|
183
|
+
Raises:
|
|
184
|
+
ValueError: If key or value will be None
|
|
185
|
+
ValueError: If type of key should be str
|
|
186
|
+
|
|
187
|
+
Returns:
|
|
188
|
+
Query -- Query, so you can chain this call.
|
|
189
|
+
|
|
190
|
+
==============================
|
|
191
|
+
|
|
192
|
+
[Example]:
|
|
193
|
+
|
|
194
|
+
>>> from contentstack import Stack
|
|
195
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
196
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
197
|
+
>>> query = content_type.query()
|
|
198
|
+
>>> query = query.add_header('key', value)
|
|
199
|
+
>>> result = query.find()
|
|
200
|
+
|
|
201
|
+
==============================
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
if key and value is None:
|
|
205
|
+
raise ValueError('Kindly provide valid header key and value')
|
|
206
|
+
if isinstance(key, str):
|
|
207
|
+
self.__headers[key] = value
|
|
208
|
+
else:
|
|
209
|
+
raise ValueError('Kindly provide a valid arguments')
|
|
210
|
+
|
|
211
|
+
return self
|
|
212
|
+
|
|
213
|
+
def locale(self, locale):
|
|
214
|
+
|
|
215
|
+
"""Enter the language code of which the entries needs to be included.
|
|
216
|
+
Only the entries published in this locale will be displayed.
|
|
217
|
+
|
|
218
|
+
Arguments:
|
|
219
|
+
locale {str} -- locale is langauge code
|
|
220
|
+
|
|
221
|
+
Raises:
|
|
222
|
+
ValueError: If locale is None
|
|
223
|
+
ValueError: If locale is not type of str
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
Query -- Query, so you can chain this call.
|
|
227
|
+
|
|
228
|
+
==============================
|
|
229
|
+
|
|
230
|
+
[Example]:
|
|
231
|
+
|
|
232
|
+
>>> from contentstack import Stack
|
|
233
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
234
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
235
|
+
>>> query = content_type.query()
|
|
236
|
+
>>> query = query.locale('en-us')
|
|
237
|
+
>>> result = query.find()
|
|
238
|
+
|
|
239
|
+
==============================
|
|
240
|
+
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
if locale is None:
|
|
244
|
+
raise ValueError('Kindly provide a valid locale-code')
|
|
245
|
+
if isinstance(locale, str):
|
|
246
|
+
self.__query_params['locale'] = locale
|
|
247
|
+
else:
|
|
248
|
+
raise ValueError('locale-code should be str')
|
|
249
|
+
|
|
250
|
+
return self
|
|
251
|
+
|
|
252
|
+
def where(self, key, value):
|
|
253
|
+
|
|
254
|
+
"""Add a constraint to fetch all entries that contains given value against specified key
|
|
255
|
+
|
|
256
|
+
Arguments:
|
|
257
|
+
key {str} -- The key to be constrained.
|
|
258
|
+
value {object} -- field value which get included from the response.
|
|
259
|
+
|
|
260
|
+
Raises:
|
|
261
|
+
ValueError: If key or value is None
|
|
262
|
+
ValueError: If key type is not str
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
Query -- Query, so you can chain this call
|
|
266
|
+
|
|
267
|
+
==============================
|
|
268
|
+
|
|
269
|
+
[Example]:
|
|
270
|
+
|
|
271
|
+
>>> from contentstack import Stack
|
|
272
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
273
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
274
|
+
>>> query = content_type.query()
|
|
275
|
+
>>> query = query.where("uid", "bltsomething123")
|
|
276
|
+
>>> result = query.find()
|
|
277
|
+
|
|
278
|
+
==============================
|
|
279
|
+
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
if None in (key, value):
|
|
283
|
+
raise ValueError('Kindly provide a valid key and value')
|
|
284
|
+
if isinstance(key, str):
|
|
285
|
+
self.__query_dict[key] = value
|
|
286
|
+
else:
|
|
287
|
+
raise ValueError('key and value should be str')
|
|
288
|
+
|
|
289
|
+
return self
|
|
290
|
+
|
|
291
|
+
def add_query(self, key, value):
|
|
292
|
+
|
|
293
|
+
"""
|
|
294
|
+
Add a custom query against specified key.
|
|
295
|
+
|
|
296
|
+
Arguments:
|
|
297
|
+
key {str} -- key of query param
|
|
298
|
+
value {str} -- value of the query
|
|
299
|
+
|
|
300
|
+
Raises:
|
|
301
|
+
ValueError: If key or value is None
|
|
302
|
+
ValueError: if the type of key is not str
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
Query -- Query object, so you can chain this call
|
|
306
|
+
|
|
307
|
+
==============================
|
|
308
|
+
|
|
309
|
+
[Example]:
|
|
310
|
+
|
|
311
|
+
>>> from contentstack import Stack
|
|
312
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
313
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
314
|
+
>>> query = content_type.query()
|
|
315
|
+
>>> query = query.add_query("query_param_key", "query_param_value")
|
|
316
|
+
>>> result = query.find()
|
|
317
|
+
|
|
318
|
+
==============================
|
|
319
|
+
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
if key and value is None:
|
|
323
|
+
raise ValueError('Kindly provide a valid key and value')
|
|
324
|
+
if isinstance(key, str):
|
|
325
|
+
self.__query_params[key] = value
|
|
326
|
+
else:
|
|
327
|
+
raise ValueError('Kindly provide a valid input')
|
|
328
|
+
|
|
329
|
+
return self
|
|
330
|
+
|
|
331
|
+
def remove_query(self, key):
|
|
332
|
+
|
|
333
|
+
"""
|
|
334
|
+
Remove provided query key from custom query if exist.
|
|
335
|
+
|
|
336
|
+
Arguments:
|
|
337
|
+
key {str} -- The key to be constrained.
|
|
338
|
+
|
|
339
|
+
Raises:
|
|
340
|
+
ValueError: If key is None
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
Query -- Query object, so you can chain this call.
|
|
344
|
+
|
|
345
|
+
==============================
|
|
346
|
+
|
|
347
|
+
[Example]:
|
|
348
|
+
|
|
349
|
+
>>> from contentstack import Stack
|
|
350
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
351
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
352
|
+
>>> query = content_type.query()
|
|
353
|
+
>>> query = query.remove_query("query_key")
|
|
354
|
+
>>> result = query.find()
|
|
355
|
+
|
|
356
|
+
==============================
|
|
357
|
+
|
|
358
|
+
"""
|
|
359
|
+
if key is None:
|
|
360
|
+
raise ValueError('Kindly provide valid key')
|
|
361
|
+
if key in self.__query_params and isinstance(key, str):
|
|
362
|
+
self.__query_params.pop(key, None)
|
|
363
|
+
return self
|
|
364
|
+
|
|
365
|
+
def and_query(self, *query_objects):
|
|
366
|
+
|
|
367
|
+
"""
|
|
368
|
+
Get entries that satisfy all the conditions provided in the '$and' query.
|
|
369
|
+
|
|
370
|
+
Arguments:
|
|
371
|
+
query_objects {object} -- query_objects for variable number of arguments of type Query Object.
|
|
372
|
+
|
|
373
|
+
Raises:
|
|
374
|
+
ValueError: If query_objects is None
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
Query -- Query object, so you can chain this call.
|
|
378
|
+
|
|
379
|
+
==============================
|
|
380
|
+
|
|
381
|
+
[Example]:
|
|
382
|
+
|
|
383
|
+
Let’s say you want to retrieve entries in which the Title field is set to 'Redmi Note 3' and the Color
|
|
384
|
+
field is 'Gold'. The query to be used for such a case would be:
|
|
385
|
+
The response will contain the entries where the values for Title is 'Redmi Note 3' and Color is 'Gold'
|
|
386
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#and-operator]
|
|
387
|
+
|
|
388
|
+
>>> from contentstack import Stack
|
|
389
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
390
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
391
|
+
>>> query = content_type.query()
|
|
392
|
+
>>> query1 = query.where("title", "Redmi Note 3")
|
|
393
|
+
>>> query2 = query.where("color", "Gold")
|
|
394
|
+
>>> query.and_query(query1, query2)
|
|
395
|
+
>>> result = query.find()
|
|
396
|
+
|
|
397
|
+
==============================
|
|
398
|
+
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
if query_objects is None:
|
|
402
|
+
raise ValueError('Kindly provide a valid KEYs')
|
|
403
|
+
if len(query_objects) > 0:
|
|
404
|
+
query_list = []
|
|
405
|
+
for query in query_objects:
|
|
406
|
+
query_list.append(query.__query_dict)
|
|
407
|
+
self.__query_dict["$and"] = query_list
|
|
408
|
+
|
|
409
|
+
return self
|
|
410
|
+
|
|
411
|
+
def or_query(self, *query_objects):
|
|
412
|
+
|
|
413
|
+
"""
|
|
414
|
+
Get all entries that satisfy at least one of the given conditions provided in the '$or' query.
|
|
415
|
+
|
|
416
|
+
Arguments:
|
|
417
|
+
query_objects {object} -- query_objects for variable number of arguments of type Query Object.
|
|
418
|
+
|
|
419
|
+
Raises:
|
|
420
|
+
ValueError: If query_objects is None
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
Query -- Query object, so you can chain this call.
|
|
424
|
+
|
|
425
|
+
==============================
|
|
426
|
+
|
|
427
|
+
[Example]:
|
|
428
|
+
|
|
429
|
+
Let’s say you want to retrieve entries in which either the value for the
|
|
430
|
+
Color field is 'Gold' or 'Black'. The query to be used for such a case would be:
|
|
431
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#or-operator]
|
|
432
|
+
|
|
433
|
+
>>> from contentstack import Stack
|
|
434
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
435
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
436
|
+
>>> query = content_type.query()
|
|
437
|
+
>>> query1 = query.where("color", "Black")
|
|
438
|
+
>>> query2 = query.where("price", "price_in_usd")
|
|
439
|
+
>>> query.or_query(query1, query2)
|
|
440
|
+
>>> result = query.find()
|
|
441
|
+
|
|
442
|
+
==============================
|
|
443
|
+
|
|
444
|
+
"""
|
|
445
|
+
|
|
446
|
+
if query_objects is None:
|
|
447
|
+
raise ValueError('Kindly provide a valid KEYs')
|
|
448
|
+
query_list: list = []
|
|
449
|
+
for query in query_objects:
|
|
450
|
+
query_list.append(query.__query_dict)
|
|
451
|
+
self.__query_dict["$or"] = query_list
|
|
452
|
+
|
|
453
|
+
return self
|
|
454
|
+
|
|
455
|
+
def less_than(self, key, value):
|
|
456
|
+
|
|
457
|
+
"""
|
|
458
|
+
Get entries in which the value of a field is lesser than the value provided in the condition.
|
|
459
|
+
|
|
460
|
+
Arguments:
|
|
461
|
+
key {str} -- The key to be constrained
|
|
462
|
+
value {object} -- value The value that must be less than.
|
|
463
|
+
|
|
464
|
+
Raises:
|
|
465
|
+
ValueError: If key or value is None
|
|
466
|
+
ValueError: If type of key is not str
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
Query -- Query object, so you can chain this call.
|
|
470
|
+
|
|
471
|
+
==============================
|
|
472
|
+
|
|
473
|
+
[Example]:
|
|
474
|
+
|
|
475
|
+
Let’s say you want to retrieve all the entries that have value of the
|
|
476
|
+
Price in USD field set to a value that is less than but not equal to 600.
|
|
477
|
+
You can send the parameter as:
|
|
478
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#less-than]
|
|
479
|
+
|
|
480
|
+
>>> from contentstack import Stack
|
|
481
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
482
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
483
|
+
>>> query = content_type.query()
|
|
484
|
+
>>> query = query.less_than('price_in_usd', 600)
|
|
485
|
+
>>> result = query.find()
|
|
486
|
+
|
|
487
|
+
==============================
|
|
488
|
+
"""
|
|
489
|
+
|
|
490
|
+
if key and value is None:
|
|
491
|
+
raise ValueError('Kindly provide valid key and value')
|
|
492
|
+
self.__query_value["$lt"] = value
|
|
493
|
+
if isinstance(key, str):
|
|
494
|
+
self.__query_dict[key] = self.__query_value
|
|
495
|
+
else:
|
|
496
|
+
raise ValueError('key should be str type')
|
|
497
|
+
|
|
498
|
+
return self
|
|
499
|
+
|
|
500
|
+
def less_than_or_equal_to(self, key, value):
|
|
501
|
+
|
|
502
|
+
"""
|
|
503
|
+
Get entries in which the value of a field is lesser than or equal to the value
|
|
504
|
+
provided in the condition.
|
|
505
|
+
|
|
506
|
+
Arguments:
|
|
507
|
+
key {str} -- The key to be constrained
|
|
508
|
+
value {object} -- value The value that must be equalled.
|
|
509
|
+
|
|
510
|
+
Raises:
|
|
511
|
+
ValueError: If key or value is None
|
|
512
|
+
ValueError: If key is not str type
|
|
513
|
+
|
|
514
|
+
Returns:
|
|
515
|
+
Query -- Query object, so you can chain this call.
|
|
516
|
+
|
|
517
|
+
==============================
|
|
518
|
+
|
|
519
|
+
Example:
|
|
520
|
+
|
|
521
|
+
Let’s say you want to retrieve all the entries that have value of the Price in USD field
|
|
522
|
+
set to a value that is less than or equal to 146. To achieve this, send the parameter as:
|
|
523
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#less-than-or-equal-to]
|
|
524
|
+
|
|
525
|
+
>>> from contentstack import Stack
|
|
526
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
527
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
528
|
+
>>> query = content_type.query()
|
|
529
|
+
>>> query = query.less_than_or_equal_to('price_in_usd', 146)
|
|
530
|
+
>>> result = query.find()
|
|
531
|
+
|
|
532
|
+
==============================
|
|
533
|
+
|
|
534
|
+
"""
|
|
535
|
+
if key and value is None:
|
|
536
|
+
raise ValueError('Kindly provide valid key and value')
|
|
537
|
+
self.__query_value["$lte"] = value
|
|
538
|
+
if isinstance(key, str):
|
|
539
|
+
self.__query_dict[key] = self.__query_value
|
|
540
|
+
else:
|
|
541
|
+
raise ValueError('key should be str type')
|
|
542
|
+
|
|
543
|
+
return self
|
|
544
|
+
|
|
545
|
+
def greater_than(self, key, value):
|
|
546
|
+
|
|
547
|
+
"""
|
|
548
|
+
Add a constraint to the query that requires a particular key entry to be greater than the provided value
|
|
549
|
+
|
|
550
|
+
Arguments:
|
|
551
|
+
key {str} -- The key to be constrained.
|
|
552
|
+
value {object} -- value The value that provides an lower bound
|
|
553
|
+
|
|
554
|
+
Raises:
|
|
555
|
+
ValueError: If key or value is None
|
|
556
|
+
ValueError: If key is not str type
|
|
557
|
+
|
|
558
|
+
Returns:
|
|
559
|
+
Query -- Query object, so you can chain this call.
|
|
560
|
+
|
|
561
|
+
==============================
|
|
562
|
+
|
|
563
|
+
Example:
|
|
564
|
+
|
|
565
|
+
Let’s say you want to retrieve all the entries that have value of the Price in USD field set to a value
|
|
566
|
+
that is greater than but not equal to 146. You can send the parameter as:
|
|
567
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#greater-than]
|
|
568
|
+
|
|
569
|
+
>>> from contentstack import Stack
|
|
570
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
571
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
572
|
+
>>> query = content_type.query()
|
|
573
|
+
>>> query = query.greater_than('price_in_usd', 146)
|
|
574
|
+
>>> result = query.find()
|
|
575
|
+
|
|
576
|
+
==============================
|
|
577
|
+
"""
|
|
578
|
+
|
|
579
|
+
if key and value is None:
|
|
580
|
+
raise ValueError('Kindly provide valid key and value')
|
|
581
|
+
self.__query_value["$gt"] = value
|
|
582
|
+
if isinstance(key, str):
|
|
583
|
+
self.__query_dict[key] = self.__query_value
|
|
584
|
+
else:
|
|
585
|
+
raise ValueError('key should be str type')
|
|
586
|
+
|
|
587
|
+
return self
|
|
588
|
+
|
|
589
|
+
def greater_than_or_equal_to(self, key, value):
|
|
590
|
+
|
|
591
|
+
"""Add a constraint to the query that requires a particular key entry to be greater than or equal to
|
|
592
|
+
the provided value.
|
|
593
|
+
|
|
594
|
+
Arguments:
|
|
595
|
+
key {str} -- The key to be constrained.
|
|
596
|
+
value {object} -- value The value that provides an lower bound.
|
|
597
|
+
|
|
598
|
+
Raises:
|
|
599
|
+
ValueError: If key or value is None
|
|
600
|
+
ValueError: If key is not str type
|
|
601
|
+
|
|
602
|
+
Returns:
|
|
603
|
+
Query -- Query object, so you can chain this call.
|
|
604
|
+
|
|
605
|
+
==============================
|
|
606
|
+
|
|
607
|
+
Example:
|
|
608
|
+
|
|
609
|
+
Let’s say you want to retrieve all the entries that have value of the Price in USD field set to a value
|
|
610
|
+
that is greater than or equal to 146. You can send the parameter as:
|
|
611
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#greater-than-or-equal-to]
|
|
612
|
+
|
|
613
|
+
>>> from contentstack import Stack
|
|
614
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
615
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
616
|
+
>>> query = content_type.query()
|
|
617
|
+
>>> query = query.greater_than_or_equal_to('price_in_usd', 146)
|
|
618
|
+
>>> result = query.find()
|
|
619
|
+
|
|
620
|
+
==============================
|
|
621
|
+
|
|
622
|
+
"""
|
|
623
|
+
|
|
624
|
+
if key and value is None:
|
|
625
|
+
raise ValueError('Kindly provide valid key and value')
|
|
626
|
+
self.__query_value["$gte"] = value
|
|
627
|
+
if isinstance(key, str):
|
|
628
|
+
self.__query_dict[key] = self.__query_value
|
|
629
|
+
else:
|
|
630
|
+
raise ValueError('key should be str type')
|
|
631
|
+
|
|
632
|
+
return self
|
|
633
|
+
|
|
634
|
+
def not_equal_to(self, key, value):
|
|
635
|
+
|
|
636
|
+
"""
|
|
637
|
+
Add a constraint to the query that requires a particular key's
|
|
638
|
+
entry to be not equal to the provided value.
|
|
639
|
+
|
|
640
|
+
Arguments:
|
|
641
|
+
key {str} -- The key to be constrained.
|
|
642
|
+
value {object} -- The object that must not be equaled.
|
|
643
|
+
|
|
644
|
+
Raises:
|
|
645
|
+
ValueError: If key or value is None
|
|
646
|
+
ValueError: If key is not str type
|
|
647
|
+
|
|
648
|
+
Returns:
|
|
649
|
+
Query -- Query object, so you can chain this call.
|
|
650
|
+
|
|
651
|
+
==============================
|
|
652
|
+
|
|
653
|
+
Example:
|
|
654
|
+
|
|
655
|
+
In the Product content type, you have a field named Price in USD. Now,
|
|
656
|
+
you need to retrieve all entries where the value of this field not equal to '146'
|
|
657
|
+
for this field. The parameter can be used as:
|
|
658
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#not-equals-operator]
|
|
659
|
+
|
|
660
|
+
>>> from contentstack import Stack
|
|
661
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
662
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
663
|
+
>>> query = content_type.query()
|
|
664
|
+
>>> query = query.not_equal_to('price_in_usd', 146)
|
|
665
|
+
>>> result = query.find()
|
|
666
|
+
|
|
667
|
+
==============================
|
|
668
|
+
"""
|
|
669
|
+
|
|
670
|
+
if key and value is None:
|
|
671
|
+
raise ValueError('Kindly provide valid key and value')
|
|
672
|
+
self.__query_value["$ne"] = value
|
|
673
|
+
if isinstance(key, str):
|
|
674
|
+
self.__query_dict[key] = self.__query_value
|
|
675
|
+
else:
|
|
676
|
+
raise ValueError('key should be str type')
|
|
677
|
+
|
|
678
|
+
return self
|
|
679
|
+
|
|
680
|
+
def contained_in(self, key, *contained_in):
|
|
681
|
+
|
|
682
|
+
"""
|
|
683
|
+
Add a constraint to the query that requires a particular key's entry to be contained
|
|
684
|
+
in the provided array.
|
|
685
|
+
|
|
686
|
+
Arguments:
|
|
687
|
+
key {str} -- The key to be constrained.
|
|
688
|
+
contained_in -- The possible values for the key's object
|
|
689
|
+
|
|
690
|
+
Raises:
|
|
691
|
+
ValueError: If key is None
|
|
692
|
+
ValueError: key should be str type
|
|
693
|
+
|
|
694
|
+
Returns:
|
|
695
|
+
[Query] -- Query object, so you can chain this call.
|
|
696
|
+
|
|
697
|
+
==============================
|
|
698
|
+
|
|
699
|
+
Example:
|
|
700
|
+
|
|
701
|
+
In the Product content type, you have a field named Price in USD. Now,
|
|
702
|
+
you need to retrieve all the entries where value of this field is one among the given set of values.
|
|
703
|
+
The query fired using the '$in' parameter is given below:
|
|
704
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#array-equals-operator]
|
|
705
|
+
|
|
706
|
+
>>> from contentstack import Stack
|
|
707
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
708
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
709
|
+
>>> query = content_type.query()
|
|
710
|
+
>>> query = query.contained_in('price_in_usd', 101, 749)
|
|
711
|
+
>>> result = query.find()
|
|
712
|
+
|
|
713
|
+
==============================
|
|
714
|
+
|
|
715
|
+
"""
|
|
716
|
+
|
|
717
|
+
if key is None:
|
|
718
|
+
raise ValueError('Kindly provide valid key')
|
|
719
|
+
self.__query_value["$in"] = list(contained_in)
|
|
720
|
+
if isinstance(key, str):
|
|
721
|
+
self.__query_dict[key] = self.__query_value
|
|
722
|
+
else:
|
|
723
|
+
raise ValueError('key should be str type')
|
|
724
|
+
|
|
725
|
+
return self
|
|
726
|
+
|
|
727
|
+
def not_contained_in(self, key, *not_contained_in):
|
|
728
|
+
|
|
729
|
+
"""Get all entries in which the value of a field does not match to any of the given values.
|
|
730
|
+
This parameter will compare field values of entries to that of the values provided in the condition,
|
|
731
|
+
and the query will retrieve entries that have field values that does not match to any of the values provided.
|
|
732
|
+
|
|
733
|
+
Arguments:
|
|
734
|
+
key {str} -- The key to be constrained.
|
|
735
|
+
not_contained_in -- The possible values for the key's object
|
|
736
|
+
|
|
737
|
+
Raises:
|
|
738
|
+
ValueError: If key is None
|
|
739
|
+
ValueError: key should be str type
|
|
740
|
+
|
|
741
|
+
Returns:
|
|
742
|
+
[Query] -- Query object, so you can chain this call.
|
|
743
|
+
|
|
744
|
+
==============================
|
|
745
|
+
|
|
746
|
+
Example:
|
|
747
|
+
|
|
748
|
+
In the Product content type, you have a field named Price in USD. Now, you need to retrieve the entries
|
|
749
|
+
where the field value does not fall in the given set. You can send the parameter as:
|
|
750
|
+
for more: [https://www.contentstack.com/docs/apis/content-delivery-api/#array-not-equals-operator]
|
|
751
|
+
|
|
752
|
+
>>> from contentstack import Stack
|
|
753
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
754
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
755
|
+
>>> query = content_type.query()
|
|
756
|
+
>>> query = query.not_contained_in('price_in_usd', 101, 749)
|
|
757
|
+
>>> result = query.find()
|
|
758
|
+
|
|
759
|
+
==============================
|
|
760
|
+
|
|
761
|
+
"""
|
|
762
|
+
|
|
763
|
+
if key is None:
|
|
764
|
+
raise ValueError('Kindly provide valid key')
|
|
765
|
+
self.__query_value["$nin"] = list(not_contained_in)
|
|
766
|
+
if isinstance(key, str):
|
|
767
|
+
self.__query_dict[key] = self.__query_value
|
|
768
|
+
else:
|
|
769
|
+
raise ValueError('key should be str type')
|
|
770
|
+
|
|
771
|
+
return self
|
|
772
|
+
|
|
773
|
+
def exists(self, key):
|
|
774
|
+
|
|
775
|
+
"""
|
|
776
|
+
Get entries if value of the field, mentioned in the condition, exists.
|
|
777
|
+
|
|
778
|
+
Arguments:
|
|
779
|
+
key {str} -- The key to be constrained.
|
|
780
|
+
|
|
781
|
+
Raises:
|
|
782
|
+
ValueError: If key is None
|
|
783
|
+
ValueError: key should be str type
|
|
784
|
+
|
|
785
|
+
Returns:
|
|
786
|
+
[Query] -- Query object, so you can chain this call.
|
|
787
|
+
|
|
788
|
+
==============================
|
|
789
|
+
|
|
790
|
+
Example:
|
|
791
|
+
|
|
792
|
+
In the Product content type, we have a field named Price in USD. Now, you want to retrieve all the entries in
|
|
793
|
+
the content type in which the field exists
|
|
794
|
+
for more: https://www.contentstack.com/docs/apis/content-delivery-api/#exists
|
|
795
|
+
|
|
796
|
+
>>> from contentstack import Stack
|
|
797
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
798
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
799
|
+
>>> query = content_type.query()
|
|
800
|
+
>>> query = query.exists('price_in_usd')
|
|
801
|
+
>>> result = query.find()
|
|
802
|
+
|
|
803
|
+
==============================
|
|
804
|
+
"""
|
|
805
|
+
|
|
806
|
+
if key is None:
|
|
807
|
+
raise ValueError('Kindly provide valid key')
|
|
808
|
+
self.__query_value["$exists"] = True
|
|
809
|
+
if isinstance(key, str):
|
|
810
|
+
self.__query_dict[key] = self.__query_value
|
|
811
|
+
else:
|
|
812
|
+
raise ValueError('key should be str type')
|
|
813
|
+
|
|
814
|
+
return self
|
|
815
|
+
|
|
816
|
+
def not_exists(self, key):
|
|
817
|
+
|
|
818
|
+
"""
|
|
819
|
+
Add a constraint that requires, a specified key does not exists in response.
|
|
820
|
+
|
|
821
|
+
Arguments:
|
|
822
|
+
key {str} -- The key to be constrained.
|
|
823
|
+
|
|
824
|
+
Raises:
|
|
825
|
+
ValueError: If key is None
|
|
826
|
+
ValueError: key should be str type
|
|
827
|
+
|
|
828
|
+
Returns:
|
|
829
|
+
[Query] -- Query object, so you can chain this call.
|
|
830
|
+
|
|
831
|
+
==============================
|
|
832
|
+
|
|
833
|
+
Example:
|
|
834
|
+
|
|
835
|
+
In the Product content type, we have a field named Price in USD. Now, you want
|
|
836
|
+
to retrieve all the entries in the content type in which the field does not exists
|
|
837
|
+
|
|
838
|
+
for more: https://www.contentstack.com/docs/apis/content-delivery-api/#not_exists
|
|
839
|
+
|
|
840
|
+
>>> from contentstack import Stack
|
|
841
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
842
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
843
|
+
>>> query = content_type.query()
|
|
844
|
+
>>> query = query.not_exists('price_in_usd')
|
|
845
|
+
>>> result = query.find()
|
|
846
|
+
|
|
847
|
+
==============================
|
|
848
|
+
|
|
849
|
+
"""
|
|
850
|
+
|
|
851
|
+
if key is None:
|
|
852
|
+
raise ValueError('Kindly provide valid key')
|
|
853
|
+
self.__query_value["$exists"] = False
|
|
854
|
+
if isinstance(key, str):
|
|
855
|
+
self.__query_dict[key] = self.__query_value
|
|
856
|
+
else:
|
|
857
|
+
raise ValueError('key should be str type')
|
|
858
|
+
|
|
859
|
+
return self
|
|
860
|
+
|
|
861
|
+
def include_reference(self, key):
|
|
862
|
+
|
|
863
|
+
"""
|
|
864
|
+
When you fetch an entry of a content type that has a reference field, by default,
|
|
865
|
+
the content of the referred entry is not fetched. It only fetches the UID of the referred entry,
|
|
866
|
+
|
|
867
|
+
Arguments:
|
|
868
|
+
key {str} -- The key to be constrained.
|
|
869
|
+
|
|
870
|
+
Raises:
|
|
871
|
+
ValueError: If key is None
|
|
872
|
+
ValueError: key should be str type
|
|
873
|
+
|
|
874
|
+
Returns:
|
|
875
|
+
[Query] -- Query object, so you can chain this call.
|
|
876
|
+
|
|
877
|
+
==============================
|
|
878
|
+
|
|
879
|
+
Example:
|
|
880
|
+
|
|
881
|
+
If you wish to fetch the content of the entry that is included in the
|
|
882
|
+
reference field, you need to use the include[] parameter, and specify the UID of the reference field as
|
|
883
|
+
value. This informs Contentstack that the request also includes fetching the entry used in the specified
|
|
884
|
+
reference field
|
|
885
|
+
for more: https://www.contentstack.com/docs/apis/content-delivery-api/#include-reference
|
|
886
|
+
|
|
887
|
+
>>> from contentstack import Stack
|
|
888
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
889
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
890
|
+
>>> query = content_type.query()
|
|
891
|
+
>>> query = query.include_reference('categories')
|
|
892
|
+
>>> result = query.find()
|
|
893
|
+
|
|
894
|
+
==============================
|
|
895
|
+
|
|
896
|
+
"""
|
|
897
|
+
|
|
898
|
+
if key is None:
|
|
899
|
+
raise ValueError('Kindly provide valid key')
|
|
900
|
+
if isinstance(key, str):
|
|
901
|
+
self.__uid_include.append(key)
|
|
902
|
+
else:
|
|
903
|
+
raise ValueError('key should be str type')
|
|
904
|
+
|
|
905
|
+
return self
|
|
906
|
+
|
|
907
|
+
def tags(self, *tags):
|
|
908
|
+
|
|
909
|
+
"""
|
|
910
|
+
Include tags with which to search entries.
|
|
911
|
+
|
|
912
|
+
Arguments:
|
|
913
|
+
tags {object} -- tags Comma separated objects with which to search entries.
|
|
914
|
+
|
|
915
|
+
Raises:
|
|
916
|
+
ValueError: If key is None
|
|
917
|
+
|
|
918
|
+
Returns:
|
|
919
|
+
[Query] -- Query object, so you can chain this call.
|
|
920
|
+
|
|
921
|
+
==============================
|
|
922
|
+
|
|
923
|
+
Example:
|
|
924
|
+
|
|
925
|
+
>>> from contentstack import Stack
|
|
926
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
927
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
928
|
+
>>> query = content_type.query()
|
|
929
|
+
>>> query = query.tags('black', 'gold', 'silver')
|
|
930
|
+
>>> result = query.find()
|
|
931
|
+
|
|
932
|
+
==============================
|
|
933
|
+
"""
|
|
934
|
+
|
|
935
|
+
if tags is None:
|
|
936
|
+
raise ValueError('Kindly provide valid key')
|
|
937
|
+
tag_string = ",".join(tags)
|
|
938
|
+
self.__query_params["tags"] = tag_string
|
|
939
|
+
|
|
940
|
+
return self
|
|
941
|
+
|
|
942
|
+
def ascending(self, key):
|
|
943
|
+
|
|
944
|
+
"""
|
|
945
|
+
When fetching entries, you can sort them in the ascending order with respect to the value of a specific field
|
|
946
|
+
in the response body.
|
|
947
|
+
|
|
948
|
+
Arguments:
|
|
949
|
+
key {str} -- The key to order by.
|
|
950
|
+
|
|
951
|
+
Raises:
|
|
952
|
+
ValueError: If key is None
|
|
953
|
+
ValueError: key should be str type
|
|
954
|
+
|
|
955
|
+
Returns:
|
|
956
|
+
[Query] -- Query object, so you can chain this call.
|
|
957
|
+
|
|
958
|
+
==============================
|
|
959
|
+
|
|
960
|
+
Example:
|
|
961
|
+
|
|
962
|
+
In the Product content type, if you wish to sort the entries with respect to their prices,
|
|
963
|
+
the parameter can be used as:
|
|
964
|
+
|
|
965
|
+
>>> from contentstack import Stack
|
|
966
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
967
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
968
|
+
>>> query = content_type.query()
|
|
969
|
+
>>> query = query.ascending('price_in_usd')
|
|
970
|
+
>>> result = query.find()
|
|
971
|
+
|
|
972
|
+
==============================
|
|
973
|
+
"""
|
|
974
|
+
|
|
975
|
+
if key is None:
|
|
976
|
+
raise ValueError('Kindly provide valid key')
|
|
977
|
+
elif isinstance(key, str):
|
|
978
|
+
self.__query_params["asc"] = key
|
|
979
|
+
else:
|
|
980
|
+
raise ValueError('key type should be str')
|
|
981
|
+
|
|
982
|
+
return self
|
|
983
|
+
|
|
984
|
+
def descending(self, key):
|
|
985
|
+
|
|
986
|
+
"""When fetching entries, you can sort them in the descending order with respect to the value of a
|
|
987
|
+
specific field in the response body.
|
|
988
|
+
|
|
989
|
+
Arguments:
|
|
990
|
+
key {str} -- The key to order by
|
|
991
|
+
|
|
992
|
+
Raises:
|
|
993
|
+
ValueError: If key is None
|
|
994
|
+
ValueError: key should be str type
|
|
995
|
+
|
|
996
|
+
Returns:
|
|
997
|
+
[Query] -- Query object, so you can chain this call.
|
|
998
|
+
|
|
999
|
+
==============================
|
|
1000
|
+
|
|
1001
|
+
Example:
|
|
1002
|
+
|
|
1003
|
+
In the Product content type, if you wish to sort the entries
|
|
1004
|
+
with respect to their prices, the parameter can be used as:
|
|
1005
|
+
|
|
1006
|
+
>>> from contentstack import Stack
|
|
1007
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1008
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1009
|
+
>>> query = content_type.query()
|
|
1010
|
+
>>> query = query.descending('price_in_usd')
|
|
1011
|
+
>>> result = query.find()
|
|
1012
|
+
|
|
1013
|
+
==============================
|
|
1014
|
+
"""
|
|
1015
|
+
|
|
1016
|
+
if key is None:
|
|
1017
|
+
raise ValueError('Kindly provide valid key')
|
|
1018
|
+
elif isinstance(key, str):
|
|
1019
|
+
self.__query_params["desc"] = key
|
|
1020
|
+
else:
|
|
1021
|
+
raise ValueError('Kindly provide str type key')
|
|
1022
|
+
|
|
1023
|
+
return self
|
|
1024
|
+
|
|
1025
|
+
def except_field_uid(self, *field_uid):
|
|
1026
|
+
|
|
1027
|
+
"""
|
|
1028
|
+
Specifies list of field uids that would be excluded from the response.
|
|
1029
|
+
|
|
1030
|
+
Arguments:
|
|
1031
|
+
*field_uid {object} -- comma separated uid objects which get excluded from the response.
|
|
1032
|
+
|
|
1033
|
+
Raises:
|
|
1034
|
+
ValueError: If field_uid is None
|
|
1035
|
+
|
|
1036
|
+
Returns:
|
|
1037
|
+
[Query] -- Query object, so you can chain this call.
|
|
1038
|
+
|
|
1039
|
+
==============================
|
|
1040
|
+
|
|
1041
|
+
Example:
|
|
1042
|
+
|
|
1043
|
+
In the Product content type, if you wish to sort the entries
|
|
1044
|
+
with respect to their prices, the parameter can be used as:
|
|
1045
|
+
|
|
1046
|
+
>>> from contentstack import Stack
|
|
1047
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1048
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1049
|
+
>>> query = content_type.query()
|
|
1050
|
+
>>> except_field = query.except_field_uid('field_uid1', 'field_uid2')
|
|
1051
|
+
>>> result = query.find()
|
|
1052
|
+
|
|
1053
|
+
==============================
|
|
1054
|
+
|
|
1055
|
+
"""
|
|
1056
|
+
|
|
1057
|
+
if field_uid is None:
|
|
1058
|
+
raise ValueError('Kindly provide valid field_uid')
|
|
1059
|
+
if len(field_uid) > 0:
|
|
1060
|
+
for uid in field_uid:
|
|
1061
|
+
self.__uid_except.append(uid)
|
|
1062
|
+
|
|
1063
|
+
return self
|
|
1064
|
+
|
|
1065
|
+
def only(self, *field_uid):
|
|
1066
|
+
|
|
1067
|
+
"""Specifies an list of field_uid keys in BASE object that would be included in the response.
|
|
1068
|
+
|
|
1069
|
+
Arguments:
|
|
1070
|
+
*field_uid {object} -- comma seprated objects of the only reference keys to be included in response.
|
|
1071
|
+
|
|
1072
|
+
Raises:
|
|
1073
|
+
ValueError: If field_uid is None
|
|
1074
|
+
|
|
1075
|
+
Returns:
|
|
1076
|
+
[Query] -- Query object, so you can chain this call.
|
|
1077
|
+
|
|
1078
|
+
==============================
|
|
1079
|
+
|
|
1080
|
+
Example:
|
|
1081
|
+
|
|
1082
|
+
In the Product content type, if you wish to sort the entries
|
|
1083
|
+
with respect to their prices, the parameter can be used as:
|
|
1084
|
+
|
|
1085
|
+
>>> from contentstack import Stack
|
|
1086
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1087
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1088
|
+
>>> query = content_type.query()
|
|
1089
|
+
>>> query = query.only('price_in_usd', 'color')
|
|
1090
|
+
>>> result = query.find()
|
|
1091
|
+
|
|
1092
|
+
==============================
|
|
1093
|
+
|
|
1094
|
+
"""
|
|
1095
|
+
|
|
1096
|
+
if field_uid is None:
|
|
1097
|
+
raise ValueError('Kindly provide valid field_uid')
|
|
1098
|
+
if len(field_uid) > 0:
|
|
1099
|
+
for uid in field_uid:
|
|
1100
|
+
self.__uid_only.append(uid)
|
|
1101
|
+
|
|
1102
|
+
return self
|
|
1103
|
+
|
|
1104
|
+
def only_with_reference_uid(self, reference_field_uid, *field_uid):
|
|
1105
|
+
|
|
1106
|
+
"""Specifies an array of only keys that would be included in the response.
|
|
1107
|
+
|
|
1108
|
+
Arguments:
|
|
1109
|
+
reference_field_uid {[str]} -- reference_field_uid Key who has reference to some other class object.
|
|
1110
|
+
*field_uid {object} -- comma separated uid objects which get excluded from the response.
|
|
1111
|
+
|
|
1112
|
+
Raises:
|
|
1113
|
+
ValueError: If reference_field_uid is None
|
|
1114
|
+
ValueError: reference_field_uid should be str type
|
|
1115
|
+
|
|
1116
|
+
Returns:
|
|
1117
|
+
[Query] -- Query object, so you can chain this call.
|
|
1118
|
+
|
|
1119
|
+
==============================
|
|
1120
|
+
|
|
1121
|
+
[Example:]
|
|
1122
|
+
|
|
1123
|
+
>>> from contentstack import Stack
|
|
1124
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1125
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1126
|
+
>>> query = content_type.query()
|
|
1127
|
+
>>> query = query.only_with_reference_uid('reference_field_uid', 'field_uid 1', 'field_uid 2')
|
|
1128
|
+
>>> result = query.find()
|
|
1129
|
+
|
|
1130
|
+
==============================
|
|
1131
|
+
"""
|
|
1132
|
+
|
|
1133
|
+
if field_uid and reference_field_uid is None:
|
|
1134
|
+
raise ValueError('Kindly provide valid fields')
|
|
1135
|
+
if isinstance(reference_field_uid, str):
|
|
1136
|
+
self.__only_json[reference_field_uid] = list(field_uid)
|
|
1137
|
+
self.__uid_include.append(reference_field_uid)
|
|
1138
|
+
else:
|
|
1139
|
+
raise ValueError('reference_field_uid should be str type')
|
|
1140
|
+
|
|
1141
|
+
return self
|
|
1142
|
+
|
|
1143
|
+
def except_with_reference_uid(self, reference_field_uid, *field_uid):
|
|
1144
|
+
|
|
1145
|
+
"""Specifies an array of except keys that would be excluded in the response.
|
|
1146
|
+
|
|
1147
|
+
Arguments:
|
|
1148
|
+
reference_field_uid {str} -- who has reference to some other class object
|
|
1149
|
+
*field_uid {object} -- comma separated uid objects which get excluded from the response.
|
|
1150
|
+
|
|
1151
|
+
Raises:
|
|
1152
|
+
ValueError: If reference_field_uid is None or not str type
|
|
1153
|
+
|
|
1154
|
+
Returns:
|
|
1155
|
+
[Query] -- Query object, so you can chain this call.
|
|
1156
|
+
|
|
1157
|
+
==============================
|
|
1158
|
+
|
|
1159
|
+
[Example:]
|
|
1160
|
+
|
|
1161
|
+
>>> from contentstack import Stack
|
|
1162
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1163
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1164
|
+
>>> query = content_type.query()
|
|
1165
|
+
>>> query = query.except_with_reference_uid('price_in_usd', 'field_uid 1', 'field_uid 2')
|
|
1166
|
+
>>> result = query.find()
|
|
1167
|
+
|
|
1168
|
+
==============================
|
|
1169
|
+
"""
|
|
1170
|
+
|
|
1171
|
+
field_value_container = []
|
|
1172
|
+
for field in field_uid:
|
|
1173
|
+
field_value_container.append(field)
|
|
1174
|
+
if reference_field_uid is not None and isinstance(reference_field_uid, str):
|
|
1175
|
+
self.__except_Json[reference_field_uid] = field_value_container
|
|
1176
|
+
self.__uid_except.append(reference_field_uid)
|
|
1177
|
+
else:
|
|
1178
|
+
raise ValueError('Kindly provide a valid input')
|
|
1179
|
+
|
|
1180
|
+
return self
|
|
1181
|
+
|
|
1182
|
+
def include_count(self):
|
|
1183
|
+
|
|
1184
|
+
"""Retrieve count and data of objects in result
|
|
1185
|
+
|
|
1186
|
+
Returns:
|
|
1187
|
+
[Query] -- Query object, so you can chain this call.
|
|
1188
|
+
|
|
1189
|
+
==============================
|
|
1190
|
+
|
|
1191
|
+
[Example:]
|
|
1192
|
+
|
|
1193
|
+
>>> from contentstack import Stack
|
|
1194
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1195
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1196
|
+
>>> query = content_type.query()
|
|
1197
|
+
>>> query = query.include_count()
|
|
1198
|
+
>>> result = query.find()
|
|
1199
|
+
|
|
1200
|
+
==============================
|
|
1201
|
+
|
|
1202
|
+
"""
|
|
1203
|
+
|
|
1204
|
+
self.__query_params["include_count"] = 'true'
|
|
1205
|
+
|
|
1206
|
+
return self
|
|
1207
|
+
|
|
1208
|
+
def include_content_type(self):
|
|
1209
|
+
|
|
1210
|
+
"""
|
|
1211
|
+
Include Content Type of all returned objects along with objects themselves.
|
|
1212
|
+
|
|
1213
|
+
Returns:
|
|
1214
|
+
[Query] -- Query object, so you can chain this call.
|
|
1215
|
+
|
|
1216
|
+
==============================
|
|
1217
|
+
|
|
1218
|
+
[Example:]
|
|
1219
|
+
|
|
1220
|
+
>>> from contentstack import Stack
|
|
1221
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1222
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1223
|
+
>>> query = content_type.query()
|
|
1224
|
+
>>> query = query.include_content_type()
|
|
1225
|
+
>>> result = query.find()
|
|
1226
|
+
|
|
1227
|
+
==============================
|
|
1228
|
+
"""
|
|
1229
|
+
|
|
1230
|
+
include_content_type = {'include_content_type': 'true',
|
|
1231
|
+
'include_global_field_schema': 'true'}
|
|
1232
|
+
self.__query_params.update(include_content_type)
|
|
1233
|
+
|
|
1234
|
+
return self
|
|
1235
|
+
|
|
1236
|
+
def skip(self, number):
|
|
1237
|
+
|
|
1238
|
+
"""The number of objects to skip before returning any.
|
|
1239
|
+
|
|
1240
|
+
Arguments:
|
|
1241
|
+
number {int} -- No of objects to skip from returned objects
|
|
1242
|
+
|
|
1243
|
+
Raises:
|
|
1244
|
+
ValueError: If number is None
|
|
1245
|
+
ValueError: If type of number is not int
|
|
1246
|
+
|
|
1247
|
+
Returns:
|
|
1248
|
+
Query -- Query object, so you can chain this call.
|
|
1249
|
+
|
|
1250
|
+
==============================
|
|
1251
|
+
|
|
1252
|
+
[Example:]
|
|
1253
|
+
|
|
1254
|
+
>>> from contentstack import Stack
|
|
1255
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1256
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1257
|
+
>>> query = content_type.query()
|
|
1258
|
+
>>> query = query.skip(3)
|
|
1259
|
+
>>> result = query.find()
|
|
1260
|
+
|
|
1261
|
+
==============================
|
|
1262
|
+
|
|
1263
|
+
"""
|
|
1264
|
+
|
|
1265
|
+
if number is None:
|
|
1266
|
+
raise ValueError('Kindly provide valid number')
|
|
1267
|
+
elif isinstance(number, int):
|
|
1268
|
+
self.__query_params["skip"] = number
|
|
1269
|
+
else:
|
|
1270
|
+
raise ValueError('number should be int type')
|
|
1271
|
+
|
|
1272
|
+
return self
|
|
1273
|
+
|
|
1274
|
+
def limit(self, number):
|
|
1275
|
+
|
|
1276
|
+
"""A limit on the number of objects to return.
|
|
1277
|
+
|
|
1278
|
+
Arguments:
|
|
1279
|
+
number {int} -- Number of objects to limit.
|
|
1280
|
+
|
|
1281
|
+
Raises:
|
|
1282
|
+
ValueError: If number is None
|
|
1283
|
+
ValueError: If number is not int type
|
|
1284
|
+
|
|
1285
|
+
Returns:
|
|
1286
|
+
[Query] -- Query object, so you can chain this call.
|
|
1287
|
+
|
|
1288
|
+
==============================
|
|
1289
|
+
|
|
1290
|
+
[Example]
|
|
1291
|
+
|
|
1292
|
+
>>> from contentstack import Stack
|
|
1293
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1294
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1295
|
+
>>> query = content_type.query()
|
|
1296
|
+
>>> query = query.limit(3)
|
|
1297
|
+
>>> result = query.find()
|
|
1298
|
+
|
|
1299
|
+
==============================
|
|
1300
|
+
|
|
1301
|
+
"""
|
|
1302
|
+
|
|
1303
|
+
if number is None:
|
|
1304
|
+
raise ValueError('Kindly provide valid number')
|
|
1305
|
+
elif isinstance(number, int):
|
|
1306
|
+
self.__query_params["limit"] = number
|
|
1307
|
+
else:
|
|
1308
|
+
raise ValueError('number should be int type')
|
|
1309
|
+
|
|
1310
|
+
return self
|
|
1311
|
+
|
|
1312
|
+
def regex(self, key, regex, modifiers=None):
|
|
1313
|
+
|
|
1314
|
+
"""
|
|
1315
|
+
Add a regular expression constraint for finding string values that match the provided
|
|
1316
|
+
regular expression. This may be slow for large data sets.
|
|
1317
|
+
|
|
1318
|
+
Arguments:
|
|
1319
|
+
key {str} -- The key to be constrained.
|
|
1320
|
+
regex {str} -- The regular expression pattern to match
|
|
1321
|
+
|
|
1322
|
+
Keyword Arguments:
|
|
1323
|
+
modifiers {str} -- Any of the following supported Regular expression modifiers (default: {None})
|
|
1324
|
+
|
|
1325
|
+
<p>use <b> i </b> for case-insensitive matching.</p>
|
|
1326
|
+
<p>use <b> m </b> for making dot match newlines.</p>
|
|
1327
|
+
<p>use <b> x </b> for ignoring whitespace in regex</p>
|
|
1328
|
+
|
|
1329
|
+
Raises:
|
|
1330
|
+
ValueError: If key, regex is None
|
|
1331
|
+
|
|
1332
|
+
Returns:
|
|
1333
|
+
[Query] -- Query object, so you can chain this call
|
|
1334
|
+
|
|
1335
|
+
==============================
|
|
1336
|
+
|
|
1337
|
+
[Example:]
|
|
1338
|
+
|
|
1339
|
+
>>> from contentstack import Stack
|
|
1340
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1341
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1342
|
+
>>> query = content_type.query()
|
|
1343
|
+
>>> query = query.regex("name", "browser")
|
|
1344
|
+
>>> result = query.find()
|
|
1345
|
+
|
|
1346
|
+
==============================
|
|
1347
|
+
|
|
1348
|
+
"""
|
|
1349
|
+
if None in (key, regex):
|
|
1350
|
+
raise ValueError('Kindly provide valid key and regex params')
|
|
1351
|
+
elif isinstance(key, str) and isinstance(regex, str):
|
|
1352
|
+
self.__query_value.clear()
|
|
1353
|
+
self.__query_value["$regex"] = regex
|
|
1354
|
+
if modifiers is not None and isinstance(modifiers, str):
|
|
1355
|
+
self.__query_value["$options"] = modifiers
|
|
1356
|
+
self.__query_dict[key] = self.__query_value
|
|
1357
|
+
|
|
1358
|
+
return self
|
|
1359
|
+
|
|
1360
|
+
def search(self, value):
|
|
1361
|
+
|
|
1362
|
+
"""
|
|
1363
|
+
This method provides only the entries matching the specified value.
|
|
1364
|
+
|
|
1365
|
+
Arguments:
|
|
1366
|
+
value {str} -- value used to match or compare
|
|
1367
|
+
|
|
1368
|
+
Raises:
|
|
1369
|
+
ValueError: If value is None
|
|
1370
|
+
ValueError: If type od value is not str
|
|
1371
|
+
|
|
1372
|
+
Returns:
|
|
1373
|
+
[Query] -- Query object, so you can chain this call.
|
|
1374
|
+
|
|
1375
|
+
==============================
|
|
1376
|
+
|
|
1377
|
+
[Example]
|
|
1378
|
+
|
|
1379
|
+
>>> from contentstack import Stack
|
|
1380
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1381
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1382
|
+
>>> query = content_type.query()
|
|
1383
|
+
>>> query = query.search("search_keyword")
|
|
1384
|
+
>>> result = query.find()
|
|
1385
|
+
|
|
1386
|
+
==============================
|
|
1387
|
+
|
|
1388
|
+
"""
|
|
1389
|
+
if value is None:
|
|
1390
|
+
raise ValueError('Kindly provide a valid value')
|
|
1391
|
+
elif isinstance(value, str):
|
|
1392
|
+
self.__query_params["typeahead"] = value
|
|
1393
|
+
else:
|
|
1394
|
+
raise ValueError('value should be str type')
|
|
1395
|
+
|
|
1396
|
+
return self
|
|
1397
|
+
|
|
1398
|
+
def param(self, key, value):
|
|
1399
|
+
|
|
1400
|
+
"""
|
|
1401
|
+
This method adds key and value to an Entry.
|
|
1402
|
+
|
|
1403
|
+
Arguments:
|
|
1404
|
+
key {str} -- The key as string which needs to be added to the Query
|
|
1405
|
+
value {object} -- The value as string which needs to be added to the Query
|
|
1406
|
+
|
|
1407
|
+
Raises:
|
|
1408
|
+
ValueError: If key and value is None
|
|
1409
|
+
ValueError: If key is not str type
|
|
1410
|
+
|
|
1411
|
+
Returns:
|
|
1412
|
+
[Query] -- Query object, so you can chain this call.
|
|
1413
|
+
|
|
1414
|
+
==============================
|
|
1415
|
+
|
|
1416
|
+
[Example]
|
|
1417
|
+
|
|
1418
|
+
>>> from contentstack import Stack
|
|
1419
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1420
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1421
|
+
>>> query = content_type.query()
|
|
1422
|
+
>>> query = query.param("key", "value")
|
|
1423
|
+
>>> result = query.find()
|
|
1424
|
+
|
|
1425
|
+
==============================
|
|
1426
|
+
|
|
1427
|
+
"""
|
|
1428
|
+
if None in (key, value):
|
|
1429
|
+
raise ValueError('Kindly provide valid key and value')
|
|
1430
|
+
elif isinstance(key, str):
|
|
1431
|
+
self.__query_params[key] = value
|
|
1432
|
+
else:
|
|
1433
|
+
raise ValueError('key and value should be str type')
|
|
1434
|
+
|
|
1435
|
+
return self
|
|
1436
|
+
|
|
1437
|
+
def include_reference_content_type_uid(self):
|
|
1438
|
+
|
|
1439
|
+
"""
|
|
1440
|
+
This method also includes the content type UIDs of the referenced entries returned in the response
|
|
1441
|
+
|
|
1442
|
+
Returns:
|
|
1443
|
+
[Query] -- Query object, so you can chain this call.
|
|
1444
|
+
|
|
1445
|
+
==============================
|
|
1446
|
+
|
|
1447
|
+
[Example]
|
|
1448
|
+
|
|
1449
|
+
>>> from contentstack import Stack
|
|
1450
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1451
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1452
|
+
>>> query = content_type.query()
|
|
1453
|
+
>>> query = query.include_reference_content_type_uid()
|
|
1454
|
+
>>> result = query.find()
|
|
1455
|
+
|
|
1456
|
+
==============================
|
|
1457
|
+
|
|
1458
|
+
"""
|
|
1459
|
+
|
|
1460
|
+
self.__query_params['include_reference_content_type_uid'] = 'true'
|
|
1461
|
+
|
|
1462
|
+
return self
|
|
1463
|
+
|
|
1464
|
+
def where_in(self, key, query_object):
|
|
1465
|
+
|
|
1466
|
+
"""
|
|
1467
|
+
Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query
|
|
1468
|
+
conditions made on referenced fields.
|
|
1469
|
+
|
|
1470
|
+
Arguments:
|
|
1471
|
+
key {str} -- The key to be constrained
|
|
1472
|
+
|
|
1473
|
+
Raises:
|
|
1474
|
+
ValueError: If key is None
|
|
1475
|
+
ValueError: If key is not str type
|
|
1476
|
+
|
|
1477
|
+
Returns:
|
|
1478
|
+
[Query] -- Query object, so you can chain this call.
|
|
1479
|
+
|
|
1480
|
+
==============================
|
|
1481
|
+
|
|
1482
|
+
[Example]
|
|
1483
|
+
|
|
1484
|
+
>>> from contentstack import Stack
|
|
1485
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1486
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1487
|
+
>>> query = content_type.query()
|
|
1488
|
+
>>> query = query.where_in("brand")
|
|
1489
|
+
>>> result = query.find()
|
|
1490
|
+
|
|
1491
|
+
==============================
|
|
1492
|
+
|
|
1493
|
+
"""
|
|
1494
|
+
|
|
1495
|
+
if key is None:
|
|
1496
|
+
raise ValueError('Kindly provide a valid key')
|
|
1497
|
+
elif isinstance(key, str):
|
|
1498
|
+
if isinstance(query_object, Query):
|
|
1499
|
+
_query = query_object.__query_dict
|
|
1500
|
+
self.__query_dict = {key: {'$in_query': _query}}
|
|
1501
|
+
else:
|
|
1502
|
+
raise ValueError('query_object should be Query type')
|
|
1503
|
+
else:
|
|
1504
|
+
raise ValueError('key should be str type')
|
|
1505
|
+
|
|
1506
|
+
return self
|
|
1507
|
+
|
|
1508
|
+
def where_not_in(self, key, query_object):
|
|
1509
|
+
|
|
1510
|
+
"""Get entries having values based on referenced fields. This query works the opposite of $in_query and
|
|
1511
|
+
retrieves all entries that does not satisfy query conditions made on referenced fields.
|
|
1512
|
+
|
|
1513
|
+
Arguments:
|
|
1514
|
+
key {str} -- The key to be constrained
|
|
1515
|
+
|
|
1516
|
+
Raises:
|
|
1517
|
+
ValueError: If key is None
|
|
1518
|
+
ValueError: If key is not str type
|
|
1519
|
+
|
|
1520
|
+
Returns:
|
|
1521
|
+
[Query] -- Query object, so you can chain this call.
|
|
1522
|
+
|
|
1523
|
+
==============================
|
|
1524
|
+
|
|
1525
|
+
[Example]
|
|
1526
|
+
|
|
1527
|
+
>>> from contentstack import Stack
|
|
1528
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1529
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1530
|
+
>>> query = content_type.query()
|
|
1531
|
+
>>> query = query.where_not_in("brand")
|
|
1532
|
+
>>> result = query.find()
|
|
1533
|
+
|
|
1534
|
+
==============================
|
|
1535
|
+
|
|
1536
|
+
"""
|
|
1537
|
+
|
|
1538
|
+
if key is None:
|
|
1539
|
+
raise ValueError('Kindly provide a valid key')
|
|
1540
|
+
elif isinstance(key, str):
|
|
1541
|
+
if isinstance(query_object, Query):
|
|
1542
|
+
_query = query_object.__query_dict
|
|
1543
|
+
self.__query_dict = {key: {'$nin_query': _query}}
|
|
1544
|
+
else:
|
|
1545
|
+
raise ValueError('query_object should be Query type')
|
|
1546
|
+
else:
|
|
1547
|
+
raise ValueError('key should be str type')
|
|
1548
|
+
|
|
1549
|
+
return self
|
|
1550
|
+
|
|
1551
|
+
def __setup_queries(self):
|
|
1552
|
+
|
|
1553
|
+
if self.__query_dict is not None and len(self.__query_dict) > 0:
|
|
1554
|
+
self.__query_params["query"] = self.__query_dict
|
|
1555
|
+
if self.__uid_except is not None and len(self.__uid_except) > 0:
|
|
1556
|
+
self.__query_params["except[BASE][]"] = self.__uid_except
|
|
1557
|
+
self.__uid_except = None
|
|
1558
|
+
if self.__uid_only is not None and len(self.__uid_only) > 0:
|
|
1559
|
+
self.__query_params["only[BASE][]"] = self.__uid_only
|
|
1560
|
+
self.__uid_only = None
|
|
1561
|
+
if self.__only_json is not None and len(self.__only_json) > 0:
|
|
1562
|
+
self.__query_params["only"] = self.__only_json
|
|
1563
|
+
self.__only_json = None
|
|
1564
|
+
if self.__except_Json is not None and len(self.__except_Json) > 0:
|
|
1565
|
+
self.__query_params["except"] = self.__except_Json
|
|
1566
|
+
self.__except_Json = None
|
|
1567
|
+
if self.__uid_include is not None and len(self.__uid_include) > 0:
|
|
1568
|
+
self.__query_params["include[]"] = self.__uid_include
|
|
1569
|
+
self.__uid_include = None
|
|
1570
|
+
|
|
1571
|
+
return self
|
|
1572
|
+
|
|
1573
|
+
def find(self):
|
|
1574
|
+
|
|
1575
|
+
"""It fetches the query result.
|
|
1576
|
+
List of :class:`Entry <contentstack.entry.Entry>` objects.
|
|
1577
|
+
|
|
1578
|
+
Raises:
|
|
1579
|
+
ValueError: If content_type_id is None
|
|
1580
|
+
ValueError: If content_type_id is empty or not str type
|
|
1581
|
+
|
|
1582
|
+
Returns:
|
|
1583
|
+
list[Entry] -- List of <contentstack.entry.Entry>
|
|
1584
|
+
|
|
1585
|
+
==============================
|
|
1586
|
+
|
|
1587
|
+
[Example]:
|
|
1588
|
+
|
|
1589
|
+
>>> from contentstack import Stack
|
|
1590
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1591
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1592
|
+
>>> query = content_type.query()
|
|
1593
|
+
>>> result = query.find()
|
|
1594
|
+
|
|
1595
|
+
==============================
|
|
1596
|
+
|
|
1597
|
+
|
|
1598
|
+
"""
|
|
1599
|
+
|
|
1600
|
+
if self.__content_type_id is None:
|
|
1601
|
+
raise ValueError('Kindly provide a valid content_type_id')
|
|
1602
|
+
elif isinstance(self.__content_type_id, str) and len(self.__content_type_id) > 0:
|
|
1603
|
+
return self.__execute_query()
|
|
1604
|
+
else:
|
|
1605
|
+
raise ValueError('Invalid content_type_id')
|
|
1606
|
+
|
|
1607
|
+
def find_one(self):
|
|
1608
|
+
|
|
1609
|
+
""" It returns only one result.
|
|
1610
|
+
|
|
1611
|
+
Returns:
|
|
1612
|
+
list[Entry] -- List of <contentstack.entry.Entry>
|
|
1613
|
+
|
|
1614
|
+
==============================
|
|
1615
|
+
|
|
1616
|
+
[Example]:
|
|
1617
|
+
|
|
1618
|
+
>>> from contentstack import Stack
|
|
1619
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1620
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1621
|
+
>>> query = content_type.query()
|
|
1622
|
+
>>> result = query.find_one()
|
|
1623
|
+
|
|
1624
|
+
==============================
|
|
1625
|
+
"""
|
|
1626
|
+
self.__query_params["limit"] = 1
|
|
1627
|
+
return self.__execute_query()
|
|
1628
|
+
|
|
1629
|
+
def __execute_query(self):
|
|
1630
|
+
self.__setup_queries()
|
|
1631
|
+
result = self.__http_request.get_result(self.__query_url, self.__query_params, self.__headers)
|
|
1632
|
+
return result
|