1414from contentstack .https_connection import HTTPSConnection
1515from contentstack .image_transform import ImageTransform
1616
17- __author__ = "ishaileshmishra (ishaileshmishra@gmail .com)"
17+ __author__ = "ishaileshmishra (shailesh.mishra@contentstack .com)"
1818__license__ = "MIT"
19- __version__ = '1.7 .0'
19+ __version__ = '1.8 .0'
2020
2121log = logging .getLogger (__name__ )
2222DEFAULT_HOST = 'cdn.contentstack.io'
@@ -79,13 +79,14 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
7979 **Example:**
8080
8181 >>> _strategy = Retry(total=5, backoff_factor=1, status_forcelist=[408, 429])
82+ >>> import contentstack
8283 >>> stack = contentstack.Stack("api_key", "delivery_token", "environment",
8384 live_preview={enable=True, authorization='your auth token'}, retry_strategy= _strategy)
8485 ```
8586 """
87+ logging .basicConfig (level = logging .DEBUG )
8688 if live_preview is None :
8789 live_preview = {'enable' : False }
88- logging .basicConfig (level = logging .DEBUG )
8990 self .headers = {}
9091 self ._query_params = {}
9192 self .sync_param = {}
@@ -144,10 +145,6 @@ def _validate_stack(self):
144145 def _validate_live_preview (self ):
145146 if isinstance (self .live_preview_dict , dict ):
146147 if 'enable' in self .live_preview_dict and self .live_preview_dict ['enable' ]:
147- if 'authorization' not in self .live_preview_dict :
148- raise PermissionError ("management token is required" )
149- if 'host' not in self .live_preview_dict :
150- raise PermissionError ("host is required" )
151148 self .headers ['authorization' ] = self .live_preview_dict ['authorization' ]
152149 self .host = self .live_preview_dict ['host' ]
153150 self .endpoint = f'https://{ self .host } /{ self .version } '
@@ -200,7 +197,7 @@ def content_type(self, content_type_uid=None):
200197 """
201198 Content type defines the structure or schema of a page or a section
202199 of your web or mobile property.
203- : param content_type_uid:
200+ param content_type_uid:
204201 :return: ContentType
205202 """
206203 return ContentType (self .http_instance , content_type_uid )
@@ -209,7 +206,7 @@ def asset(self, uid):
209206 """
210207 Assets refer to all the media files (images, videos, PDFs, audio files, and so on)
211208 uploaded in your Contentstack repository for future use.
212- : param uid: asset_uid of the Asset
209+ param uid: asset_uid of the Asset
213210 :return: Asset
214211
215212 -----------------------------
@@ -242,7 +239,7 @@ def asset_query(self):
242239 def sync_init (self , content_type_uid = None , start_from = None , locale = None , publish_type = None ):
243240 """
244241 Set init to ‘true’ if you want to sync all the published entries and assets.
245- This is usually used when the app does not have any content and you want to
242+ This is usually used when the app does not have any content, and you want to
246243 get all the content for the first time.\n
247244
248245 :param content_type_uid: (optional) content type UID. e.g., products
@@ -285,7 +282,7 @@ def pagination(self, pagination_token: str):
285282 paginated. It provides pagination token in the response.
286283 However, you do not have to use the pagination token
287284 manually to get the next batch.
288- : param pagination_token:
285+ param pagination_token:
289286 :return: list of sync items
290287 ------------------------------
291288 Example:
@@ -303,7 +300,7 @@ def sync_token(self, sync_token):
303300 to get the updated content next time. The sync token fetches
304301 only the content that was added
305302 after your last sync, and the details of the content that was deleted or updated.
306- : param sync_token: sync_token
303+ param sync_token: sync_token
307304 :return: list of Sync Result
308305 ------------------------------
309306 [Example]:
@@ -318,7 +315,7 @@ def sync_token(self, sync_token):
318315
319316 def __sync_request (self ):
320317 r"""Sends a GET request.
321- : param url URL for :class:`Request` object.
318+ param url is URL for :class:`Request` object.
322319 in the query string for the :class:`Request`.
323320 :param \*\*kwargs: Optional arguments that ``request`` takes.
324321 :return: :class:`Response <Response>` object
@@ -350,6 +347,27 @@ def image_transform(self, image_url, **kwargs):
350347 def live_preview_query (self , ** kwargs ):
351348 """
352349 live_preview_query accepts key value pair objects to the query
353- i.e hash and content_type_uid
350+ hash, content_type_uid and entry_uid
351+ Example:
352+ # def live_preview_query(**kwargs):
353+ # kwargs is a dict of the keyword args passed to the function
354+ for key, value in kwargs.iteritems():
355+ print "%s = %s" % (key, value)
356+ Uses:=>
357+ live_preview_query(
358+ host='api.contentstack.io',
359+ entry_uid='your_entry_uid',
360+ hash='hashcode'
361+ )
354362 """
355363 self .live_preview_dict .update (kwargs )
364+ self ._execute_management_api ()
365+ return self
366+
367+ def _execute_management_api (self ):
368+ _ct_uid = self .live_preview_dict .get ("content_type_uid" )
369+ _entry_uid = self .live_preview_dict .get ("entry_uid" )
370+ _url = f'{ self .http_instance .endpoint } /content_types/{ _ct_uid } /entries/{ _entry_uid } '
371+ _resp = self .http_instance .get (_url )
372+ self .live_preview_dict ['resp' ] = _resp ['entry' ]
373+ return self
0 commit comments