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/entry.py
ADDED
|
@@ -0,0 +1,1162 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
Created by Shailesh Mishra on 22/06/19.
|
|
4
|
+
Copyright 2019 Contentstack. All rights reserved.
|
|
5
|
+
|
|
6
|
+
contentstack.entry
|
|
7
|
+
~~~~~~~~~~~~~~~~~~
|
|
8
|
+
|
|
9
|
+
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#entries
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Entry:
|
|
15
|
+
"""
|
|
16
|
+
[Note]: If no version is mentioned, this request will retrieve the
|
|
17
|
+
latest published version of the entry.To retrieve a specific version, make use of the version parameter
|
|
18
|
+
and keep the environment parameter blank.
|
|
19
|
+
|
|
20
|
+
==============================
|
|
21
|
+
|
|
22
|
+
[Example:]
|
|
23
|
+
|
|
24
|
+
>>> from contentstack import Stack
|
|
25
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
26
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
27
|
+
>>> entry = content_type.entry('uid')
|
|
28
|
+
>>> entry = entry.fetch()
|
|
29
|
+
|
|
30
|
+
==============================
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, content_type_id=None):
|
|
35
|
+
self.__content_type_id = content_type_id
|
|
36
|
+
self.__stack_instance = None
|
|
37
|
+
self.__http_request = None
|
|
38
|
+
self.__config = None
|
|
39
|
+
self.__entry_url = None
|
|
40
|
+
|
|
41
|
+
self.__local_params = {}
|
|
42
|
+
self.__entry_headers = {}
|
|
43
|
+
self.__only_dict = {}
|
|
44
|
+
self.__result_json = {}
|
|
45
|
+
|
|
46
|
+
self.__uid_for_except = {}
|
|
47
|
+
self.__except_field = []
|
|
48
|
+
self.__uid_for_only = []
|
|
49
|
+
self.__tags = []
|
|
50
|
+
|
|
51
|
+
self.__entry_uid = str
|
|
52
|
+
self.__title = str
|
|
53
|
+
self.__description = str
|
|
54
|
+
self.__url = str
|
|
55
|
+
self.__locale = str
|
|
56
|
+
self.__created_at = str
|
|
57
|
+
self.__created_by = str
|
|
58
|
+
self.__updated_at = str
|
|
59
|
+
self.__updated_by = str
|
|
60
|
+
self.__version = str
|
|
61
|
+
|
|
62
|
+
def _instance(self, stack_instance):
|
|
63
|
+
# This is the protected from outside users, so they can't access this function.
|
|
64
|
+
self.__stack_instance = stack_instance
|
|
65
|
+
self.__config = self.__stack_instance.config
|
|
66
|
+
self.__entry_url = self.__config.endpoint
|
|
67
|
+
if self.__content_type_id is not None:
|
|
68
|
+
self.__entry_url = '{}/content_types/{}/entries/'.format(self.__entry_url, self.__content_type_id)
|
|
69
|
+
self.__http_request = self.__stack_instance.get_http_instance
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
def _configure(self, model):
|
|
73
|
+
if model is not None and isinstance(model, dict):
|
|
74
|
+
self.__result_json = model
|
|
75
|
+
if self.__result_json is not None:
|
|
76
|
+
if 'title' in self.__result_json:
|
|
77
|
+
self.__title = self.__result_json['title']
|
|
78
|
+
if 'url' in self.__result_json:
|
|
79
|
+
self.__url = self.__result_json['url']
|
|
80
|
+
if 'uid' in self.__result_json:
|
|
81
|
+
self.__entry_uid = self.__result_json['uid']
|
|
82
|
+
if 'tags' in self.__result_json:
|
|
83
|
+
self.__tags = self.__result_json['tags']
|
|
84
|
+
if 'created_by' in self.__result_json:
|
|
85
|
+
self.__created_by = self.__result_json['created_by']
|
|
86
|
+
if 'created_at' in self.__result_json:
|
|
87
|
+
self.__created_at = self.__result_json['created_at']
|
|
88
|
+
if 'updated_at' in self.__result_json:
|
|
89
|
+
self.__updated_at = self.__result_json['updated_at']
|
|
90
|
+
if 'updated_by' in self.__result_json:
|
|
91
|
+
self.__updated_by = self.__result_json['updated_by']
|
|
92
|
+
if 'locale' in self.__result_json:
|
|
93
|
+
self.__locale = self.__result_json['locale']
|
|
94
|
+
if '_version' in self.__result_json:
|
|
95
|
+
self.__version = self.__result_json['_version']
|
|
96
|
+
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
def add_header(self, key, value):
|
|
100
|
+
|
|
101
|
+
"""
|
|
102
|
+
It is useful to accept the API key, access_token of stack of which you wish to retrieve
|
|
103
|
+
the content types.
|
|
104
|
+
|
|
105
|
+
Arguments:
|
|
106
|
+
key {str} -- key of header
|
|
107
|
+
value {str} -- value of header
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
KeyError: If case when key or value is None
|
|
111
|
+
|
|
112
|
+
KeyError: key and value type should be str
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Entry -- Entry class instance, that helps to chain the call
|
|
116
|
+
|
|
117
|
+
==============================
|
|
118
|
+
|
|
119
|
+
[Example:]
|
|
120
|
+
|
|
121
|
+
>>> from contentstack import Stack
|
|
122
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
123
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
124
|
+
>>> entry = content_type.entry('uid')
|
|
125
|
+
>>> entry = entry.add_header('key', 'value')
|
|
126
|
+
>>> entry = entry.fetch()
|
|
127
|
+
|
|
128
|
+
==============================
|
|
129
|
+
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
if None in (key, value):
|
|
133
|
+
raise KeyError
|
|
134
|
+
elif isinstance(key, str) and isinstance(value, str):
|
|
135
|
+
self.__entry_headers[key] = value
|
|
136
|
+
else:
|
|
137
|
+
raise KeyError('key and value type should be str')
|
|
138
|
+
|
|
139
|
+
return self
|
|
140
|
+
|
|
141
|
+
def remove_header(self, key):
|
|
142
|
+
|
|
143
|
+
"""
|
|
144
|
+
To remove desired header key
|
|
145
|
+
|
|
146
|
+
Arguments:
|
|
147
|
+
key {str} -- existing key of header
|
|
148
|
+
|
|
149
|
+
Raises:
|
|
150
|
+
KeyError: Kindly provide a valid key, key should not be None or str
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Entry -- Entry class object so we can chain the call
|
|
154
|
+
|
|
155
|
+
==============================
|
|
156
|
+
|
|
157
|
+
[Example:]
|
|
158
|
+
|
|
159
|
+
>>> from contentstack import Stack
|
|
160
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
161
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
162
|
+
>>> entry = content_type.entry('uid')
|
|
163
|
+
>>> entry = entry.remove_header('key')
|
|
164
|
+
>>> entry = entry.fetch()
|
|
165
|
+
|
|
166
|
+
==============================
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
if key is None or not isinstance(key, str):
|
|
170
|
+
raise KeyError('Kindly provide valid KEY')
|
|
171
|
+
elif isinstance(key, str):
|
|
172
|
+
if key in self.__entry_headers:
|
|
173
|
+
self.__entry_headers.pop(key, None)
|
|
174
|
+
|
|
175
|
+
return self
|
|
176
|
+
|
|
177
|
+
@property
|
|
178
|
+
def uid(self):
|
|
179
|
+
|
|
180
|
+
"""
|
|
181
|
+
uid of the entry
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
str -- str type entry uid
|
|
185
|
+
|
|
186
|
+
==============================
|
|
187
|
+
|
|
188
|
+
[Example:]
|
|
189
|
+
|
|
190
|
+
>>> from contentstack import Stack
|
|
191
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
192
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
193
|
+
>>> entry = content_type.entry('uid')
|
|
194
|
+
>>> entry = entry.fetch()
|
|
195
|
+
>>> entry_uid = entry.uid
|
|
196
|
+
|
|
197
|
+
==============================
|
|
198
|
+
"""
|
|
199
|
+
return self.__entry_uid
|
|
200
|
+
|
|
201
|
+
@uid.setter
|
|
202
|
+
def uid(self, uid):
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
The unique ID of the content type of which you wish to retrieve the details.
|
|
206
|
+
The content type UID is generated based on the title of the content type
|
|
207
|
+
and it is unique across a stack.
|
|
208
|
+
|
|
209
|
+
Arguments:
|
|
210
|
+
uid {str} -- entry uid
|
|
211
|
+
|
|
212
|
+
Raises:
|
|
213
|
+
KeyError: key should not be None or empty str
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
Entry -- Entry class object so we can chain the call
|
|
217
|
+
|
|
218
|
+
==============================
|
|
219
|
+
|
|
220
|
+
[Example:]
|
|
221
|
+
|
|
222
|
+
>>> from contentstack import Stack
|
|
223
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
224
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
225
|
+
>>> entry = content_type.entry('uid')
|
|
226
|
+
>>> entry.uid = 'bltsomethingasuid'
|
|
227
|
+
>>> entry = entry.fetch()
|
|
228
|
+
|
|
229
|
+
==============================
|
|
230
|
+
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
if uid is None or not isinstance(uid, str):
|
|
234
|
+
raise KeyError('Kindly provide a valid uid')
|
|
235
|
+
self.__entry_uid = uid
|
|
236
|
+
|
|
237
|
+
return self
|
|
238
|
+
|
|
239
|
+
@property
|
|
240
|
+
def locale(self):
|
|
241
|
+
|
|
242
|
+
"""
|
|
243
|
+
It returns code of the language of which the entries needs to be included.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
str -- language of the entry
|
|
247
|
+
|
|
248
|
+
==============================
|
|
249
|
+
|
|
250
|
+
[Example:]
|
|
251
|
+
|
|
252
|
+
>>> from contentstack import Stack
|
|
253
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
254
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
255
|
+
>>> entry = content_type.entry('uid')
|
|
256
|
+
>>> entry = entry.fetch()
|
|
257
|
+
>>> locale = entry.locale
|
|
258
|
+
|
|
259
|
+
==============================
|
|
260
|
+
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
if 'locale' in self.__result_json:
|
|
264
|
+
return self.__result_json['locale']
|
|
265
|
+
else:
|
|
266
|
+
return self.__locale
|
|
267
|
+
|
|
268
|
+
@locale.setter
|
|
269
|
+
def locale(self, locale):
|
|
270
|
+
|
|
271
|
+
"""
|
|
272
|
+
Locale accepts code of the language of which the entries needs to be included.
|
|
273
|
+
Only the entries published in this locale will be displayed.
|
|
274
|
+
|
|
275
|
+
Arguments:
|
|
276
|
+
locale {str} -- language code
|
|
277
|
+
|
|
278
|
+
Raises:
|
|
279
|
+
KeyError: locale should not be None or empty, type of locale should be str
|
|
280
|
+
|
|
281
|
+
==============================
|
|
282
|
+
|
|
283
|
+
[Example:]
|
|
284
|
+
|
|
285
|
+
>>> from contentstack import Stack
|
|
286
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
287
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
288
|
+
>>> entry = content_type.entry('uid')
|
|
289
|
+
>>> entry.locale = 'en-us'
|
|
290
|
+
>>> entry = entry.fetch()
|
|
291
|
+
|
|
292
|
+
==============================
|
|
293
|
+
"""
|
|
294
|
+
|
|
295
|
+
if locale is None and not isinstance(locale, str):
|
|
296
|
+
raise KeyError('Kindly provide a valid locale')
|
|
297
|
+
self.__local_params["locale"] = locale
|
|
298
|
+
|
|
299
|
+
@property
|
|
300
|
+
def title(self):
|
|
301
|
+
|
|
302
|
+
"""This method returns title of the entry
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
str -- title of the entry
|
|
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
|
+
>>> entry = content_type.entry('uid')
|
|
315
|
+
>>> entry = entry.fetch()
|
|
316
|
+
>>> title = entry.title
|
|
317
|
+
|
|
318
|
+
==============================
|
|
319
|
+
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
return self.__title
|
|
323
|
+
|
|
324
|
+
@property
|
|
325
|
+
def url(self):
|
|
326
|
+
|
|
327
|
+
"""
|
|
328
|
+
This method returns url of the entry
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
str -- url of the entry
|
|
332
|
+
|
|
333
|
+
==============================
|
|
334
|
+
|
|
335
|
+
[Example:]
|
|
336
|
+
|
|
337
|
+
>>> from contentstack import Stack
|
|
338
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
339
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
340
|
+
>>> entry = content_type.entry('uid')
|
|
341
|
+
>>> entry = entry.fetch()
|
|
342
|
+
>>> url = entry.url
|
|
343
|
+
|
|
344
|
+
==============================
|
|
345
|
+
|
|
346
|
+
"""
|
|
347
|
+
|
|
348
|
+
return self.__url
|
|
349
|
+
|
|
350
|
+
@property
|
|
351
|
+
def tags(self):
|
|
352
|
+
|
|
353
|
+
"""This method returns list of tags of the entry
|
|
354
|
+
|
|
355
|
+
Returns:
|
|
356
|
+
list -- tags of entry
|
|
357
|
+
|
|
358
|
+
==============================
|
|
359
|
+
|
|
360
|
+
[Example:]
|
|
361
|
+
|
|
362
|
+
>>> from contentstack import Stack
|
|
363
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
364
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
365
|
+
>>> entry = content_type.entry('uid')
|
|
366
|
+
>>> entry = entry.fetch()
|
|
367
|
+
>>> tags = entry.tags
|
|
368
|
+
|
|
369
|
+
==============================
|
|
370
|
+
"""
|
|
371
|
+
|
|
372
|
+
return self.__tags
|
|
373
|
+
|
|
374
|
+
@property
|
|
375
|
+
def content_type(self):
|
|
376
|
+
|
|
377
|
+
"""This method returns content_type of the entry
|
|
378
|
+
|
|
379
|
+
Returns:
|
|
380
|
+
str -- content_type_uid of the entry
|
|
381
|
+
|
|
382
|
+
==============================
|
|
383
|
+
|
|
384
|
+
[Example:]
|
|
385
|
+
|
|
386
|
+
>>> from contentstack import Stack
|
|
387
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
388
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
389
|
+
>>> entry = content_type.entry('uid')
|
|
390
|
+
>>> entry = entry.fetch()
|
|
391
|
+
>>> content_type = entry.content_type
|
|
392
|
+
|
|
393
|
+
==============================
|
|
394
|
+
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
return self.__content_type_id
|
|
398
|
+
|
|
399
|
+
@property
|
|
400
|
+
def headers(self):
|
|
401
|
+
|
|
402
|
+
"""This method is useful to get dictionary of the headers
|
|
403
|
+
|
|
404
|
+
Returns:
|
|
405
|
+
dict -- The method is used to get list of headers.
|
|
406
|
+
|
|
407
|
+
==============================
|
|
408
|
+
|
|
409
|
+
[Example:]
|
|
410
|
+
|
|
411
|
+
>>> from contentstack import Stack
|
|
412
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
413
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
414
|
+
>>> entry = content_type.entry('uid')
|
|
415
|
+
>>> entry = entry.fetch()
|
|
416
|
+
>>> headers = entry.headers
|
|
417
|
+
|
|
418
|
+
==============================
|
|
419
|
+
|
|
420
|
+
"""
|
|
421
|
+
|
|
422
|
+
return self.__entry_headers
|
|
423
|
+
|
|
424
|
+
@property
|
|
425
|
+
def json(self):
|
|
426
|
+
|
|
427
|
+
"""
|
|
428
|
+
This method returns response of the entry in dictionary formats
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
dict -- response of the entry
|
|
432
|
+
|
|
433
|
+
==============================
|
|
434
|
+
|
|
435
|
+
[Example:]
|
|
436
|
+
|
|
437
|
+
>>> from contentstack import Stack
|
|
438
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
439
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
440
|
+
>>> entry = content_type.entry('uid')
|
|
441
|
+
>>> entry = entry.fetch()
|
|
442
|
+
>>> result = entry.json
|
|
443
|
+
|
|
444
|
+
==============================
|
|
445
|
+
|
|
446
|
+
"""
|
|
447
|
+
# return None if self.__result_json == None else self.__result_json
|
|
448
|
+
if self.__result_json is None:
|
|
449
|
+
return None
|
|
450
|
+
else:
|
|
451
|
+
return self.__result_json
|
|
452
|
+
|
|
453
|
+
@property
|
|
454
|
+
def created_at(self):
|
|
455
|
+
|
|
456
|
+
"""
|
|
457
|
+
Returns:
|
|
458
|
+
str -- value of creation time of entry
|
|
459
|
+
|
|
460
|
+
==============================
|
|
461
|
+
|
|
462
|
+
[Example:]
|
|
463
|
+
|
|
464
|
+
>>> from contentstack import Stack
|
|
465
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
466
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
467
|
+
>>> entry = content_type.entry('uid')
|
|
468
|
+
>>> entry = entry.fetch()
|
|
469
|
+
>>> created_at = entry.created_at
|
|
470
|
+
|
|
471
|
+
==============================
|
|
472
|
+
"""
|
|
473
|
+
|
|
474
|
+
return self.__created_at
|
|
475
|
+
|
|
476
|
+
@property
|
|
477
|
+
def created_by(self):
|
|
478
|
+
|
|
479
|
+
"""
|
|
480
|
+
Returns:
|
|
481
|
+
str -- uid who created this entry
|
|
482
|
+
|
|
483
|
+
==============================
|
|
484
|
+
|
|
485
|
+
[Example:]
|
|
486
|
+
|
|
487
|
+
>>> from contentstack import Stack
|
|
488
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
489
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
490
|
+
>>> entry = content_type.entry('uid')
|
|
491
|
+
>>> entry = entry.fetch()
|
|
492
|
+
>>> created_by = entry.created_by
|
|
493
|
+
|
|
494
|
+
==============================
|
|
495
|
+
"""
|
|
496
|
+
|
|
497
|
+
return self.__created_by
|
|
498
|
+
|
|
499
|
+
@property
|
|
500
|
+
def updated_at(self):
|
|
501
|
+
|
|
502
|
+
"""
|
|
503
|
+
Returns:
|
|
504
|
+
str -- updating time of entry.
|
|
505
|
+
|
|
506
|
+
==============================
|
|
507
|
+
|
|
508
|
+
[Example:]
|
|
509
|
+
|
|
510
|
+
>>> from contentstack import Stack
|
|
511
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
512
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
513
|
+
>>> entry = content_type.entry('uid')
|
|
514
|
+
>>> entry = entry.fetch()
|
|
515
|
+
>>> result = entry.updated_at
|
|
516
|
+
|
|
517
|
+
==============================
|
|
518
|
+
|
|
519
|
+
"""
|
|
520
|
+
|
|
521
|
+
return self.__updated_at
|
|
522
|
+
|
|
523
|
+
@property
|
|
524
|
+
def updated_by(self):
|
|
525
|
+
|
|
526
|
+
"""
|
|
527
|
+
|
|
528
|
+
Returns:
|
|
529
|
+
str -- uid who updated entry.
|
|
530
|
+
|
|
531
|
+
==============================
|
|
532
|
+
|
|
533
|
+
[Example:]
|
|
534
|
+
|
|
535
|
+
>>> from contentstack import Stack
|
|
536
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
537
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
538
|
+
>>> entry = content_type.entry('uid')
|
|
539
|
+
>>> entry = entry.fetch()
|
|
540
|
+
>>> result = entry.updated_by
|
|
541
|
+
|
|
542
|
+
==============================
|
|
543
|
+
"""
|
|
544
|
+
|
|
545
|
+
return self.__updated_by
|
|
546
|
+
|
|
547
|
+
def get(self, key):
|
|
548
|
+
|
|
549
|
+
"""
|
|
550
|
+
This method returns value of respective key of the entry
|
|
551
|
+
|
|
552
|
+
Arguments:
|
|
553
|
+
key {str} -- field_uid as key
|
|
554
|
+
|
|
555
|
+
Returns:
|
|
556
|
+
object -- onject by key you wants to access
|
|
557
|
+
|
|
558
|
+
==============================
|
|
559
|
+
|
|
560
|
+
[Example:]
|
|
561
|
+
|
|
562
|
+
>>> from contentstack import Stack
|
|
563
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
564
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
565
|
+
>>> entry = content_type.entry('uid')
|
|
566
|
+
>>> entry = entry.fetch()
|
|
567
|
+
>>> result = entry.get('key')
|
|
568
|
+
|
|
569
|
+
==============================
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
if key is None:
|
|
573
|
+
raise ValueError('Kindly provide a valid argument')
|
|
574
|
+
elif isinstance(key, str):
|
|
575
|
+
if key in self.__result_json:
|
|
576
|
+
return self.__result_json[key]
|
|
577
|
+
|
|
578
|
+
def add_param(self, key, value):
|
|
579
|
+
|
|
580
|
+
"""
|
|
581
|
+
This method is useful to add additional Query parameters to the entry
|
|
582
|
+
|
|
583
|
+
Arguments:
|
|
584
|
+
key {str} -- key The key as string which needs to be added to an Entry
|
|
585
|
+
value {object} -- value The value as string which needs to be added to an Entry
|
|
586
|
+
|
|
587
|
+
Raises:
|
|
588
|
+
ValueError: If key or value is None
|
|
589
|
+
ValueError: If key is not type of str
|
|
590
|
+
|
|
591
|
+
Returns:
|
|
592
|
+
Entry -- So can we chain the call
|
|
593
|
+
|
|
594
|
+
==============================
|
|
595
|
+
|
|
596
|
+
[Example:]
|
|
597
|
+
|
|
598
|
+
>>> from contentstack import Stack
|
|
599
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
600
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
601
|
+
>>> entry = content_type.entry('uid')
|
|
602
|
+
>>> entry = entry.fetch()
|
|
603
|
+
>>> entry = entry.add_param('key', 'value')
|
|
604
|
+
|
|
605
|
+
==============================
|
|
606
|
+
|
|
607
|
+
"""
|
|
608
|
+
|
|
609
|
+
if None in (key, value):
|
|
610
|
+
raise ValueError('Kindly provide valid KEY and Value arguments')
|
|
611
|
+
elif isinstance(key, str):
|
|
612
|
+
self.__local_params[key] = value
|
|
613
|
+
else:
|
|
614
|
+
raise ValueError('Params key should be str')
|
|
615
|
+
|
|
616
|
+
return self
|
|
617
|
+
|
|
618
|
+
def version(self, version):
|
|
619
|
+
|
|
620
|
+
"""
|
|
621
|
+
Enter the version number of the entry that you want to retrieve.
|
|
622
|
+
However, to retrieve a specific version of an entry, you need to keep the environment parameter blank.
|
|
623
|
+
|
|
624
|
+
Arguments:
|
|
625
|
+
version {str} -- version if entry
|
|
626
|
+
|
|
627
|
+
Raises:
|
|
628
|
+
ValueError: If version is None or not str type
|
|
629
|
+
|
|
630
|
+
Returns:
|
|
631
|
+
Entry -- So we can chain the call
|
|
632
|
+
|
|
633
|
+
==============================
|
|
634
|
+
|
|
635
|
+
[Example:]
|
|
636
|
+
|
|
637
|
+
>>> from contentstack import Stack
|
|
638
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
639
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
640
|
+
>>> entry = content_type.entry('uid')
|
|
641
|
+
>>> entry = entry.fetch()
|
|
642
|
+
>>> entry = entry.version('7')
|
|
643
|
+
|
|
644
|
+
==============================
|
|
645
|
+
|
|
646
|
+
"""
|
|
647
|
+
|
|
648
|
+
if version is None or not isinstance(version, str):
|
|
649
|
+
raise ValueError('Kindly provide valid')
|
|
650
|
+
elif isinstance(version, str):
|
|
651
|
+
self.__local_params["version"] = version
|
|
652
|
+
|
|
653
|
+
return self
|
|
654
|
+
|
|
655
|
+
def get_string(self, key):
|
|
656
|
+
|
|
657
|
+
"""
|
|
658
|
+
This method returns str type result of the entry
|
|
659
|
+
|
|
660
|
+
Arguments:
|
|
661
|
+
key {str} -- field_uid
|
|
662
|
+
|
|
663
|
+
Returns:
|
|
664
|
+
str -- value from the dict of respective key
|
|
665
|
+
|
|
666
|
+
==============================
|
|
667
|
+
|
|
668
|
+
[Example:]
|
|
669
|
+
|
|
670
|
+
>>> from contentstack import Stack
|
|
671
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
672
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
673
|
+
>>> entry = content_type.entry('uid')
|
|
674
|
+
>>> entry = entry.fetch()
|
|
675
|
+
>>> result = entry.get_string('key')
|
|
676
|
+
|
|
677
|
+
==============================
|
|
678
|
+
"""
|
|
679
|
+
|
|
680
|
+
value = self.get(key)
|
|
681
|
+
if isinstance(value, str):
|
|
682
|
+
return value
|
|
683
|
+
return None
|
|
684
|
+
|
|
685
|
+
def get_boolean(self, key):
|
|
686
|
+
|
|
687
|
+
"""
|
|
688
|
+
This method returns bool type result of the entry
|
|
689
|
+
|
|
690
|
+
Arguments:
|
|
691
|
+
key {str} -- field_uid
|
|
692
|
+
|
|
693
|
+
Raises:
|
|
694
|
+
KeyError: If key instance is not str
|
|
695
|
+
|
|
696
|
+
Returns:
|
|
697
|
+
bool -- boolean value
|
|
698
|
+
|
|
699
|
+
==============================
|
|
700
|
+
|
|
701
|
+
[Example:]
|
|
702
|
+
|
|
703
|
+
>>> from contentstack import Stack
|
|
704
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
705
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
706
|
+
>>> entry = content_type.entry('uid')
|
|
707
|
+
>>> entry = entry.fetch()
|
|
708
|
+
>>> result = entry.get_boolean('bool_key')
|
|
709
|
+
|
|
710
|
+
==============================
|
|
711
|
+
"""
|
|
712
|
+
|
|
713
|
+
if isinstance(key, str):
|
|
714
|
+
value = self.get(key)
|
|
715
|
+
if isinstance(value, bool):
|
|
716
|
+
return value
|
|
717
|
+
else:
|
|
718
|
+
raise KeyError('Kindly provide valid KEY')
|
|
719
|
+
|
|
720
|
+
def get_json(self, key):
|
|
721
|
+
|
|
722
|
+
"""
|
|
723
|
+
This method is useful to get result of respective key if result is dict
|
|
724
|
+
|
|
725
|
+
Arguments:
|
|
726
|
+
key {str} -- field_uid
|
|
727
|
+
|
|
728
|
+
Returns:
|
|
729
|
+
dict -- result dict by key
|
|
730
|
+
|
|
731
|
+
==============================
|
|
732
|
+
|
|
733
|
+
[Example:]
|
|
734
|
+
|
|
735
|
+
>>> from contentstack import Stack
|
|
736
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
737
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
738
|
+
>>> entry = content_type.entry('uid')
|
|
739
|
+
>>> entry = entry.fetch()
|
|
740
|
+
>>> result = entry.get_json('key')
|
|
741
|
+
|
|
742
|
+
==============================
|
|
743
|
+
"""
|
|
744
|
+
|
|
745
|
+
value = self.get(key)
|
|
746
|
+
if isinstance(value, dict):
|
|
747
|
+
return value
|
|
748
|
+
else:
|
|
749
|
+
return None
|
|
750
|
+
|
|
751
|
+
def get_list(self, key):
|
|
752
|
+
|
|
753
|
+
"""
|
|
754
|
+
It returns the list type data
|
|
755
|
+
|
|
756
|
+
Arguments:
|
|
757
|
+
key {str} -- field_uid
|
|
758
|
+
|
|
759
|
+
Returns:
|
|
760
|
+
list -- list of data from the entry
|
|
761
|
+
|
|
762
|
+
==============================
|
|
763
|
+
|
|
764
|
+
[Example:]
|
|
765
|
+
|
|
766
|
+
>>> from contentstack import Stack
|
|
767
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
768
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
769
|
+
>>> entry = content_type.entry('uid')
|
|
770
|
+
>>> entry = entry.fetch()
|
|
771
|
+
>>> result = entry.get_list('key')
|
|
772
|
+
|
|
773
|
+
==============================
|
|
774
|
+
|
|
775
|
+
"""
|
|
776
|
+
|
|
777
|
+
value = self.get(key)
|
|
778
|
+
if isinstance(value, list):
|
|
779
|
+
return value
|
|
780
|
+
else:
|
|
781
|
+
return None
|
|
782
|
+
|
|
783
|
+
def asset(self, key):
|
|
784
|
+
|
|
785
|
+
"""
|
|
786
|
+
Get an asset from the entry on the basis of the key
|
|
787
|
+
|
|
788
|
+
Arguments:
|
|
789
|
+
key {str} -- field_uid
|
|
790
|
+
|
|
791
|
+
Returns:
|
|
792
|
+
Asset -- Asset of the entry
|
|
793
|
+
|
|
794
|
+
==============================
|
|
795
|
+
|
|
796
|
+
[Example:]
|
|
797
|
+
|
|
798
|
+
>>> from contentstack import Stack
|
|
799
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
800
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
801
|
+
>>> entry = content_type.entry('uid')
|
|
802
|
+
>>> entry = entry.fetch()
|
|
803
|
+
>>> result = entry.asset("key")
|
|
804
|
+
|
|
805
|
+
==============================
|
|
806
|
+
"""
|
|
807
|
+
|
|
808
|
+
from contentstack import Asset
|
|
809
|
+
asset = Asset()
|
|
810
|
+
|
|
811
|
+
if key is None:
|
|
812
|
+
raise KeyError('Kindly provide valid key')
|
|
813
|
+
elif isinstance(key, str):
|
|
814
|
+
result = self.get_json(key)
|
|
815
|
+
if result is not None and isinstance(result, dict):
|
|
816
|
+
asset = asset._configure(result)
|
|
817
|
+
|
|
818
|
+
return asset
|
|
819
|
+
|
|
820
|
+
def get_assets(self, key):
|
|
821
|
+
|
|
822
|
+
"""
|
|
823
|
+
Get an assets from the entry. This works with multiple true fields
|
|
824
|
+
|
|
825
|
+
Arguments:
|
|
826
|
+
key {str} -- field_uid
|
|
827
|
+
|
|
828
|
+
Returns:
|
|
829
|
+
list[Asset] -- list of Asset
|
|
830
|
+
|
|
831
|
+
==============================
|
|
832
|
+
|
|
833
|
+
[Example:]
|
|
834
|
+
|
|
835
|
+
>>> from contentstack import Stack
|
|
836
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
837
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
838
|
+
>>> entry = content_type.entry('uid')
|
|
839
|
+
>>> entry = entry.fetch()
|
|
840
|
+
>>> result = entry.get_assets("key")
|
|
841
|
+
|
|
842
|
+
==============================
|
|
843
|
+
"""
|
|
844
|
+
assets = []
|
|
845
|
+
from contentstack import Asset
|
|
846
|
+
|
|
847
|
+
if key is None:
|
|
848
|
+
raise KeyError('Kindly provide valid key')
|
|
849
|
+
elif isinstance(key, str):
|
|
850
|
+
assetlist = self.get_list(key)
|
|
851
|
+
if isinstance(assetlist, list):
|
|
852
|
+
for assetobj in assetlist:
|
|
853
|
+
if isinstance(assetobj, dict):
|
|
854
|
+
asset = Asset()
|
|
855
|
+
model = asset._configure(assetobj)
|
|
856
|
+
assets.append(model)
|
|
857
|
+
return assets
|
|
858
|
+
|
|
859
|
+
def get_all_entries(self, ref_key, ref_content_type):
|
|
860
|
+
|
|
861
|
+
"""
|
|
862
|
+
Get value for the given reference key.
|
|
863
|
+
|
|
864
|
+
Arguments:
|
|
865
|
+
ref_key {str} -- ref_key key of a reference field.
|
|
866
|
+
ref_content_type {str} -- ref_content_type class uid.
|
|
867
|
+
|
|
868
|
+
Returns:
|
|
869
|
+
list[Asset] -- Entry instances. Also specified content_type value will be set as class uid for all
|
|
870
|
+
|
|
871
|
+
==============================
|
|
872
|
+
|
|
873
|
+
[Example:]
|
|
874
|
+
|
|
875
|
+
>>> from contentstack import Stack
|
|
876
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
877
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
878
|
+
>>> entry = content_type.entry('uid')
|
|
879
|
+
>>> entry = entry.fetch()
|
|
880
|
+
>>> all_entries = entry.get_all_entries("reference_key", "reference_content_type")
|
|
881
|
+
|
|
882
|
+
==============================
|
|
883
|
+
|
|
884
|
+
"""
|
|
885
|
+
|
|
886
|
+
all_entries = []
|
|
887
|
+
if self.__result_json is not None and isinstance(ref_key, str):
|
|
888
|
+
if ref_key in self.__result_json:
|
|
889
|
+
list_entry = self.__result_json[ref_key]
|
|
890
|
+
if isinstance(list_entry, list):
|
|
891
|
+
for entry_obj in list_entry:
|
|
892
|
+
entry = self.__stack_instance.content_type(ref_content_type).entry()
|
|
893
|
+
model = list_entry[entry_obj]
|
|
894
|
+
entry._configure(model)
|
|
895
|
+
all_entries.append(entry)
|
|
896
|
+
return all_entries
|
|
897
|
+
return None
|
|
898
|
+
|
|
899
|
+
def excepts(self, *field_uid):
|
|
900
|
+
|
|
901
|
+
"""
|
|
902
|
+
Specifies list of field field_uid that would be excluded from the response.
|
|
903
|
+
|
|
904
|
+
Returns:
|
|
905
|
+
Entry -- Entry object, so you can chain this call.
|
|
906
|
+
|
|
907
|
+
==============================
|
|
908
|
+
|
|
909
|
+
[Example:]
|
|
910
|
+
|
|
911
|
+
>>> from contentstack import Stack
|
|
912
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
913
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
914
|
+
>>> entry = content_type.entry('uid')
|
|
915
|
+
>>> entry = entry.fetch()
|
|
916
|
+
>>> entry = entry.excepts('title', 'color', 'price_in_usd')
|
|
917
|
+
|
|
918
|
+
==============================
|
|
919
|
+
|
|
920
|
+
"""
|
|
921
|
+
|
|
922
|
+
if field_uid is None:
|
|
923
|
+
raise ValueError('Kindly provide a valid argument')
|
|
924
|
+
self.__except_field = list(field_uid)
|
|
925
|
+
|
|
926
|
+
return self
|
|
927
|
+
|
|
928
|
+
def except_with_reference_uid(self, reference_field_uid, *field_uid):
|
|
929
|
+
|
|
930
|
+
"""
|
|
931
|
+
Specifies an array of 'except' keys that would be excluded in the response.
|
|
932
|
+
|
|
933
|
+
Arguments:
|
|
934
|
+
reference_field_uid {str} -- Key who has reference to some other class object.
|
|
935
|
+
field_uid {str}: field_uid for variable number of arguments
|
|
936
|
+
|
|
937
|
+
Raises:
|
|
938
|
+
ValueError: reference_field_uid and field_uid should not be None
|
|
939
|
+
ValueError: reference_field_uid should be str type
|
|
940
|
+
|
|
941
|
+
Returns:
|
|
942
|
+
Entry -- Entry object, so you can chain this call.
|
|
943
|
+
|
|
944
|
+
==============================
|
|
945
|
+
|
|
946
|
+
[Example:]
|
|
947
|
+
|
|
948
|
+
>>> from contentstack import Stack
|
|
949
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
950
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
951
|
+
>>> entry = content_type.entry('uid')
|
|
952
|
+
>>> entry = entry.fetch()
|
|
953
|
+
>>> entry = entry.except_with_reference_uid('reference_field_uid', "field1", 'field2', 'field3')
|
|
954
|
+
|
|
955
|
+
==============================
|
|
956
|
+
|
|
957
|
+
"""
|
|
958
|
+
|
|
959
|
+
if (reference_field_uid, field_uid) is None:
|
|
960
|
+
raise ValueError('Kindly provide valid arguments')
|
|
961
|
+
elif isinstance(reference_field_uid, str):
|
|
962
|
+
self.__uid_for_except[reference_field_uid] = list(field_uid)
|
|
963
|
+
self.include_reference(reference_field_uid)
|
|
964
|
+
else:
|
|
965
|
+
raise ValueError('Kindly provide a valid input')
|
|
966
|
+
|
|
967
|
+
return self
|
|
968
|
+
|
|
969
|
+
def include_reference(self, *reference_uid):
|
|
970
|
+
|
|
971
|
+
"""
|
|
972
|
+
Add a constraint that requires a particular reference key details.
|
|
973
|
+
|
|
974
|
+
Raises:
|
|
975
|
+
ValueError: if reference_uid is None
|
|
976
|
+
|
|
977
|
+
Returns:
|
|
978
|
+
Entry -- Entry object, so you can chain this call.
|
|
979
|
+
|
|
980
|
+
==============================
|
|
981
|
+
|
|
982
|
+
[Example:]
|
|
983
|
+
|
|
984
|
+
>>> from contentstack import Stack
|
|
985
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
986
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
987
|
+
>>> entry = content_type.entry('uid')
|
|
988
|
+
>>> entry = entry.fetch()
|
|
989
|
+
>>> entry.include_reference('uid1', 'uid2', 'uid3')
|
|
990
|
+
|
|
991
|
+
==============================
|
|
992
|
+
"""
|
|
993
|
+
|
|
994
|
+
if reference_uid is None:
|
|
995
|
+
raise ValueError('Kindly provide a valid argument')
|
|
996
|
+
self.__local_params["include[]"] = list(reference_uid)
|
|
997
|
+
|
|
998
|
+
return self
|
|
999
|
+
|
|
1000
|
+
def only(self, *field_uid):
|
|
1001
|
+
|
|
1002
|
+
"""
|
|
1003
|
+
Specifies an array of only keys in BASE object that would be included in the response.
|
|
1004
|
+
:param field_uid: field_uid for variable number of arguments to be included in response.
|
|
1005
|
+
field_uid for variable number of arguments
|
|
1006
|
+
|
|
1007
|
+
Returns:
|
|
1008
|
+
Entry -- Entry object, so you can chain this call.
|
|
1009
|
+
|
|
1010
|
+
==============================
|
|
1011
|
+
|
|
1012
|
+
[Example:]
|
|
1013
|
+
|
|
1014
|
+
>>> from contentstack import Stack
|
|
1015
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1016
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1017
|
+
>>> entry = content_type.entry('uid')
|
|
1018
|
+
>>> entry = entry.fetch()
|
|
1019
|
+
>>> entry.only('uid1', 'uid2', 'uid3')
|
|
1020
|
+
|
|
1021
|
+
==============================
|
|
1022
|
+
"""
|
|
1023
|
+
|
|
1024
|
+
if field_uid is None:
|
|
1025
|
+
raise KeyError
|
|
1026
|
+
for uid in field_uid:
|
|
1027
|
+
self.__uid_for_only.append(uid)
|
|
1028
|
+
|
|
1029
|
+
return self
|
|
1030
|
+
|
|
1031
|
+
def only_with_reference_uid(self, reference_field_uid, *field_uid):
|
|
1032
|
+
|
|
1033
|
+
"""
|
|
1034
|
+
Specifies an array of only keys that would be included in the response.
|
|
1035
|
+
|
|
1036
|
+
Arguments:
|
|
1037
|
+
reference_field_uid {str} -- Key who has reference to some other class object.
|
|
1038
|
+
field_uid {comma seprated str objects} -- for variable number of arguments
|
|
1039
|
+
|
|
1040
|
+
Raises:
|
|
1041
|
+
ValueError: If reference_field_uid is None or not str type
|
|
1042
|
+
|
|
1043
|
+
Returns:
|
|
1044
|
+
Entry -- Entry object, so you can chain this call.
|
|
1045
|
+
|
|
1046
|
+
==============================
|
|
1047
|
+
|
|
1048
|
+
[Example:]
|
|
1049
|
+
|
|
1050
|
+
>>> from contentstack import Stack
|
|
1051
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1052
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1053
|
+
>>> entry = content_type.entry('uid')
|
|
1054
|
+
>>> entry = entry.fetch()
|
|
1055
|
+
>>> entry.only_with_reference_uid('reference_uid', 'uid1', 'uid2', 'uid3')
|
|
1056
|
+
|
|
1057
|
+
==============================
|
|
1058
|
+
|
|
1059
|
+
"""
|
|
1060
|
+
|
|
1061
|
+
field_value_list = []
|
|
1062
|
+
for field in field_uid:
|
|
1063
|
+
field_value_list.append(field)
|
|
1064
|
+
if reference_field_uid is not None and isinstance(reference_field_uid, str):
|
|
1065
|
+
self.__only_dict[reference_field_uid] = field_value_list
|
|
1066
|
+
self.include_reference(reference_field_uid)
|
|
1067
|
+
else:
|
|
1068
|
+
raise ValueError('Kindly provide a valid input')
|
|
1069
|
+
|
|
1070
|
+
return self
|
|
1071
|
+
|
|
1072
|
+
def include_reference_content_type_uid(self):
|
|
1073
|
+
|
|
1074
|
+
"""
|
|
1075
|
+
description This method also includes the content type UIDs
|
|
1076
|
+
of the referenced entries returned in the response.
|
|
1077
|
+
|
|
1078
|
+
Returns:
|
|
1079
|
+
Entry -- Entry object, so you can chain this call.
|
|
1080
|
+
|
|
1081
|
+
==============================
|
|
1082
|
+
|
|
1083
|
+
[Example:]
|
|
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
|
+
>>> entry = content_type.entry('uid')
|
|
1089
|
+
>>> entry = entry.fetch()
|
|
1090
|
+
>>> entry.include_reference_content_type_uid()
|
|
1091
|
+
|
|
1092
|
+
==============================
|
|
1093
|
+
"""
|
|
1094
|
+
|
|
1095
|
+
self.__local_params['include_reference_content_type_uid'] = 'true'
|
|
1096
|
+
|
|
1097
|
+
return self
|
|
1098
|
+
|
|
1099
|
+
def include_content_type(self):
|
|
1100
|
+
|
|
1101
|
+
"""
|
|
1102
|
+
Include the details of the content type along with the entry/entries details.
|
|
1103
|
+
|
|
1104
|
+
Returns:
|
|
1105
|
+
Entry -- Entry object, so you can chain this call.
|
|
1106
|
+
|
|
1107
|
+
==============================
|
|
1108
|
+
|
|
1109
|
+
[Example:]
|
|
1110
|
+
|
|
1111
|
+
>>> from contentstack import Stack
|
|
1112
|
+
>>> stack = Stack(api_key='stack_api_key', access_token='stack_access_token', environment='env')
|
|
1113
|
+
>>> content_type = stack.content_type('content_type_uid')
|
|
1114
|
+
>>> entry = content_type.entry('uid')
|
|
1115
|
+
>>> entry = entry.fetch()
|
|
1116
|
+
>>> entry.include_content_type()
|
|
1117
|
+
|
|
1118
|
+
==============================
|
|
1119
|
+
"""
|
|
1120
|
+
include_content_type = {'include_content_type': 'true',
|
|
1121
|
+
'include_global_field_schema': 'true'}
|
|
1122
|
+
self.__local_params.update(include_content_type)
|
|
1123
|
+
|
|
1124
|
+
return self
|
|
1125
|
+
|
|
1126
|
+
def __set_include_json(self):
|
|
1127
|
+
if self.__uid_for_only is not None and len(self.__uid_for_only) > 0:
|
|
1128
|
+
self.__local_params["only[BASE][]"] = self.__uid_for_only
|
|
1129
|
+
self.__uid_for_only = None
|
|
1130
|
+
|
|
1131
|
+
if self.__except_field is not None and len(self.__except_field) > 0:
|
|
1132
|
+
self.__local_params["except[BASE][]"] = self.__except_field
|
|
1133
|
+
self.__except_field = None
|
|
1134
|
+
|
|
1135
|
+
if self.__uid_for_except is not None and len(self.__uid_for_except) > 0:
|
|
1136
|
+
self.__local_params["except"] = self.__uid_for_except
|
|
1137
|
+
self.__uid_for_except = None
|
|
1138
|
+
|
|
1139
|
+
if self.__only_dict is not None and len(self.__only_dict) > 0:
|
|
1140
|
+
self.__local_params["only"] = self.__only_dict
|
|
1141
|
+
self.__only_dict = None
|
|
1142
|
+
|
|
1143
|
+
return self
|
|
1144
|
+
|
|
1145
|
+
def fetch(self):
|
|
1146
|
+
|
|
1147
|
+
"""Fetches the latest version of the entries from stack
|
|
1148
|
+
|
|
1149
|
+
Raises:
|
|
1150
|
+
KeyError: If entry_uid is None
|
|
1151
|
+
|
|
1152
|
+
Returns:
|
|
1153
|
+
Entry - Entry object, so you can chain this call.
|
|
1154
|
+
|
|
1155
|
+
"""
|
|
1156
|
+
|
|
1157
|
+
if self.__entry_uid is None:
|
|
1158
|
+
raise KeyError('Kindly provide entry uid')
|
|
1159
|
+
self.__set_include_json()
|
|
1160
|
+
self.__entry_url = '{}{}'.format(self.__entry_url, self.__entry_uid)
|
|
1161
|
+
result = self.__http_request.get_result(self.__entry_url, self.__local_params, self.__entry_headers)
|
|
1162
|
+
return result
|