|
| 1 | +""" |
| 2 | +Content type defines the structure or schema of a page or a section of your web |
| 3 | +or mobile property. To create content for your application, you are required |
| 4 | +to first create a content type, and then create entries using the |
| 5 | +content type. |
| 6 | +""" |
| 7 | + |
| 8 | + |
| 9 | +# ************* Module asset ************** |
| 10 | +# Your code has been rated at 9.09/10 by pylint |
| 11 | + |
| 12 | + |
| 13 | +class ContentType: |
| 14 | + """ |
| 15 | + Content type defines the structure or schema of a page or a |
| 16 | + section of your web or mobile property. To create |
| 17 | + content for your application, you are required to |
| 18 | + first create a content type, and then create entries using the |
| 19 | + content type. |
| 20 | + """ |
| 21 | + |
| 22 | + def __init__(self, http_instance, content_type_uid): |
| 23 | + self.__http_instance = http_instance |
| 24 | + self.__content_type_uid = content_type_uid |
| 25 | + |
| 26 | + def entry(self, uid): |
| 27 | + """ |
| 28 | + An entry is the actual piece of content created using one of the defined content types. |
| 29 | + :param uid: {str} -- uid of the entry |
| 30 | + :return: Entry -- Returns the Entry class object so we can chain the entry functions |
| 31 | + -------------------------------- |
| 32 | + [Example:] |
| 33 | +
|
| 34 | + >>> import contentstack |
| 35 | + >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment') |
| 36 | + >>> content_type = stack.content_type('content_type_uid') |
| 37 | + >>> entry = content_type.entry(uid='entry_uid') |
| 38 | + -------------------------------- |
| 39 | + """ |
| 40 | + from contentstack import Entry |
| 41 | + entry = Entry(self.__http_instance, self.__content_type_uid, entry_uid=uid) |
| 42 | + return entry |
| 43 | + |
| 44 | + def query(self): |
| 45 | + """ |
| 46 | + It returns query class object so we can query on entry of specified ContentType |
| 47 | + :return: Query -- query object instance, so we can chain the query functions to it. |
| 48 | + ------------------------------ |
| 49 | + [Example:] |
| 50 | +
|
| 51 | + >>> import contentstack |
| 52 | + >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment') |
| 53 | + >>> content_type = stack.content_type('content_type_uid') |
| 54 | + >>> query = content_type.query() |
| 55 | + ------------------------------ |
| 56 | + """ |
| 57 | + from contentstack.query import Query |
| 58 | + query = Query(self.__content_type_uid) |
| 59 | + return query |
| 60 | + |
| 61 | + def fetch(self, params=None): |
| 62 | + """ |
| 63 | + This method is useful to fetch ContentType of the of the stack. |
| 64 | + :param params: dictionary of params |
| 65 | + :return:dict -- contentType response |
| 66 | + ------------------------------ |
| 67 | + Example: |
| 68 | +
|
| 69 | + >>> import contentstack |
| 70 | + >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment') |
| 71 | + >>> content_type = stack.content_type('content_type_uid') |
| 72 | + >>> content_type.add_header('key', 'someheader') |
| 73 | + >>> some_dict = {'abc':'something'} |
| 74 | + >>> response = content_type.fetch(some_dict) |
| 75 | + ------------------------------ |
| 76 | + """ |
| 77 | + if params is None: |
| 78 | + params = {} |
| 79 | + params_dict = {} |
| 80 | + url = '{}/content_types'.format(self.__http_instance.endpoint) |
| 81 | + content_type_url = '{0}/{1}'.format(url, self.__content_type_uid) |
| 82 | + if params is not None and isinstance(params, dict): |
| 83 | + params_dict.update(params) |
| 84 | + # params_dict, self.__stack_headers |
| 85 | + result = self.__http_instance.get(content_type_url) |
| 86 | + return result |
0 commit comments