Skip to content

Commit d30e2f7

Browse files
mshaileshr@gmail.commshaileshr@gmail.com
authored andcommitted
v1.1.0 updated include_reference in Queryable class
1 parent 5c60d6c commit d30e2f7

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

changelog.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
CHANGELOG
33
=========
44

5+
*Date: 7-Aug-2020 - initial release*
6+
7+
**v1.1.0**
8+
============
9+
- **EntryQueyable**
10+
- updated include_reference function.
11+
12+
-----------------------------
13+
514
*Date: 17-Jun-2020 - initial release*
615

716
**v1.0.0**
817
============
918

1019
- **Stack**
11-
- Initialisation of stack has been modified
12-
- External config support moved to stack initialisation optional paramters
13-
- Added support for whereIn(String key) and whereNotIn(String key) methods in Query
20+
- Initialization of the stack has been modified
21+
- External config support moved to stack initialization optional parameters
1422

1523
- **Asset**
1624
- changes incorporated in Asset class.

contentstack/entryqueryable.py

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
import enum
2-
3-
4-
class Include(enum.Enum):
5-
"""
6-
Include is enum that Provides Options to perform operation to query the result.
7-
8-
Available Options for QueryOperation are below.
9-
DEFAULT, ONLY, EXCEPT
10-
11-
Arguments:
12-
enum {Include} -- Type of IncludeReference
13-
"""
14-
EXCEPT = 'except'
15-
ONLY = 'only'
16-
DEFAULT = ''
171

182

193
class EntryQueryable:
204
"""
215
This class is base class for the Entry and Query class that shares common functions
226
"""
7+
238
def __init__(self):
249
self.entry_queryable_param = {}
10+
self.entry_include_array = []
11+
self.entry_include_dict = {}
2512

2613
def locale(self, locale: str):
2714
"""
@@ -53,7 +40,7 @@ def locale(self, locale: str):
5340
self.entry_queryable_param['locale'] = locale
5441
return self
5542

56-
def only(self, field_uid):
43+
def only(self, field_uid: str):
5744
"""
5845
Specifies an array of only keys in BASE object that would be included in the response.
5946
It refers to the top-level fields of the schema
@@ -62,57 +49,56 @@ def only(self, field_uid):
6249
self -- so you can chain this call.
6350
"""
6451
if field_uid is not None:
65-
self.entry_queryable_param['only[BASE][]'] = field_uid
66-
return self
52+
if isinstance(field_uid, str):
53+
self.entry_queryable_param['only[BASE][]'] = [field_uid]
54+
else:
55+
raise KeyError("Invalid field_uid provided")
56+
return self
6757

68-
def excepts(self, field_uid):
58+
def excepts(self, field_uid: str):
6959
"""
7060
Specifies list of field_uid that would be excluded from the response.
7161
It refers to the top-level fields of the schema
7262
:param field_uid: to be excluded from the response.
7363
:return: self -- so you can chain this call.
7464
"""
7565
if field_uid is not None:
76-
self.entry_queryable_param['except[BASE][]'] = field_uid
77-
return self
66+
if isinstance(field_uid, str):
67+
self.entry_queryable_param['except[BASE][]'] = [field_uid]
68+
else:
69+
raise KeyError("Invalid field_uid provided")
70+
return self
7871

79-
def include_reference(self, include_reference_type: Include, reference_field_uid: str, field_uid=None):
72+
def include_reference(self, field_uid):
8073
"""
8174
**Include Reference:**
8275
When you fetch an entry of a content type that has a reference field,
8376
by default, the content of the referred entry is not fetched.
8477
It only fetches the UID of the referred entry, along with the content of
8578
the specified entry.
8679
80+
Note: The maximum reference depth limit to which a multiple content type
81+
referencing Reference field works is three levels deep
82+
8783
Arguments:
88-
reference_field_uid {str} -- Key who has reference to some other class object.
8984
Array of the only reference keys to be included in response
90-
include_type {Include} -- Provides three options, none, only and except
91-
i.e accepts list of field_uid
92-
field_uid {list} -- list of field_uid on which include operation to perform
85+
field_uid {str or list of str} -- [str/list of str] of field_uid on which include operation to perform
9386
9487
Returns:
9588
self -- So you can chain this call.
9689
"""
97-
container = {}
98-
if reference_field_uid is None:
99-
raise KeyError("reference_field_uid can't be None")
100-
if include_reference_type.name == 'DEFAULT':
101-
self.entry_queryable_param["include[]"] = reference_field_uid
102-
else:
103-
container[reference_field_uid] = field_uid
104-
self.entry_queryable_param["include[]"] = {include_reference_type.value: container}
90+
if field_uid is not None and isinstance(field_uid, str):
91+
self.entry_queryable_param["include[]"] = [field_uid]
92+
if field_uid is not None and isinstance(field_uid, list) and len(field_uid) > 0:
93+
self.entry_queryable_param["include[]"] = field_uid
10594
return self
10695

10796
def include_content_type(self):
10897
"""
10998
This method also includes the ContentType in the entry
11099
:return: self: so you can chain this call.
111-
112100
-------------------------------
113-
114101
[Example: for Entry]
115-
116102
>>> import contentstack
117103
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
118104
>>> content_type = stack.content_type('content_type_uid')

contentstack/https_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def user_agents():
4444
# "pylint doesn't know what's best" - use your own judgement but as a rule.
4545
class HTTPSConnection:
4646
"""Make Https Request to fetch the result as per requested url"""
47+
4748
def __init__(self, endpoint, headers):
4849
if None not in (endpoint, headers):
4950
self.payload = None
@@ -76,10 +77,9 @@ def update_connection_timeout(self, timeout: int):
7677
"""Facilitate to update timeout for the https request"""
7778
self.default_timeout = timeout
7879

79-
def get_complete_url(self, base_url: str, params:dict):
80+
def get_complete_url(self, base_url: str, params: dict):
8081
if 'query' in params:
8182
params["query"] = json.dumps(params["query"])
8283
query = urlparse.urlencode(params)
8384
url = '{}&{}'.format(base_url, query)
8485
return url
85-

requirements.txt

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
docutils~=0.15.2
2-
dnspython~=1.16.0
3-
idna~=2.9
4-
pip~=20.1.1
5-
wheel~=0.33.6
6-
keyring~=19.2.0
7-
pytz~=2019.3
1+
docutils~=0.16
2+
dnspython~=2.0.0
3+
idna~=2.10
4+
pip~=20.2
5+
wheel~=0.34.2
6+
keyring~=21.2.1
7+
pytz~=2020.1
88
Babel~=2.8.0
99
pkginfo~=1.5.0.1
10-
MarkupSafe~=1.1.1
11-
Sphinx~=2.4.3
12-
packaging~=20.1
13-
Jinja2~=2.11.1
10+
MarkupSafe~=2.0.0a1
11+
Sphinx~=3.1.2
12+
packaging~=20.4
13+
Jinja2~=3.0.0a1
1414
imagesize~=1.2.0
1515
enum34~=1.1.10
16-
requests~=2.23.0
16+
requests~=2.24.0
1717
snowballstemmer~=2.0.0
18-
Pygments~=2.4.2
19-
certifi~=2019.11.28
18+
Pygments~=2.6.1
19+
certifi~=2020.6.20
2020
chardet~=3.0.4
21-
six~=1.13.0
22-
toml~=0.10.0
23-
urllib3~=1.25.8
21+
six~=1.15.0
22+
toml~=0.10.1
23+
urllib3~=1.25.10
2424
alabaster~=0.7.12
25-
pyparsing~=2.4.6
26-
setuptools~=41.6.0
27-
zipp~=0.6.0
28-
html-testRunner~=1.2.1
25+
pyparsing~=3.0.0.a2
26+
setuptools~=49.2.0
27+
zipp~=3.1.0
28+
html-testRunner~=1.2.1
29+
py~=1.9.0
30+
pytest~=6.0.1
31+
attrs~=19.3.0
32+
pluggy~=1.0.0.dev0
33+
wcwidth~=0.2.5
34+
coverage~=5.2.1

0 commit comments

Comments
 (0)