Skip to content

Commit 0af7a23

Browse files
Merge pull request #97 from contentstack/development
Development
2 parents ae7679c + e66fc91 commit 0af7a23

File tree

100 files changed

+396
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+396
-220
lines changed

.talismanrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,10 @@ fileignoreconfig:
354354
checksum: c7323b95249759bc67c33d3a89d3d2e8b3ed3d146b944682d451ebebe22567c0
355355
- filename: .github/workflows/secrets-scan.yml
356356
checksum: d79ec3f3288964f7d117b9ad319a54c0ebc152e35f69be8fde95522034fdfb2a
357-
version: ""
357+
- filename: tests/api/global_fields/test_global_fields_api.py
358+
checksum: 1cd57383fcad33cfaddc03aec9a7ee3e85b27de35e4545462fca33e74768e812
359+
- filename: tests/unit/global_fields/test_global_fields_unittest.py
360+
checksum: 9bb05624cf1dadb770b3cf17fbfe915cf3133d622110da30a7dfebdeab0a315c
361+
- filename: tests/api/global_fields/test_global_fields_api.py
362+
checksum: ef69455a51168ea34d62a68caea0984504d3feeafb78010947fa99d7c54d9e9c
363+
version: "1.0"

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Content Management SDK For Python
44
---
5+
## v1.4.0
6+
7+
#### Date: 09 June 2025
8+
9+
- Release 2.0 support.
10+
- Nested Global fields support
11+
---
512
## v1.3.3
613

714
#### Date: 12 May 2025

contentstack_management/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
)
7070

7171
__title__ = 'contentstack-management-python'
72-
__author__ = 'ishaileshmishra'
72+
__author__ = 'dev-ex'
7373
__status__ = 'debug'
7474
__region__ = 'na'
75-
__version__ = '1.3.3'
75+
__version__ = '1.4.0'
7676
__host__ = 'api.contentstack.io'
7777
__protocol__ = 'https://'
7878
__api_version__ = 'v3'

contentstack_management/auditlogs/auditlog.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
The create(), read(), update(), and delete() methods each correspond to
44
the CRUD operations that can be performed on the API """
55

6-
import json
76
from ..common import Parameter
8-
from urllib.parse import quote
97
from .._errors import ArgumentException
108

119
class Auditlog(Parameter):

contentstack_management/bulk_operations/bulk_operation.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,96 @@ def update(self, data: dict):
227227
data = json.dumps(data)
228228
return self.client.post(url, headers = self.client.headers, data = data, params=self.params)
229229

230+
def add_items(self, data: dict, headers: dict = None):
231+
"""
232+
The Add items to bulk operation request allows you to add multiple entries and assets to a bulk operation.
233+
234+
:return: The `add_items` method is returning the result of the `post` request made by the
235+
`client.post` method.
236+
-------------------------------
237+
[Example:]
238+
>>> data = {
239+
>>> "release": "release_uid"
240+
>>> "action": "publish",
241+
>>> "locale": ["en-us", "hi-in"]
242+
>>> "reference": true
243+
>>> "items": [
244+
>>> {
245+
>>> "uid": "blt63177c0f00f20b61",
246+
>>> "content_type_uid": "my_blog"
247+
>>> }
248+
>>> ]
249+
>>> }
250+
>>> import contentstack_management
251+
>>> client = contentstack_management.Client(authtoken='your_authtoken')
252+
>>> result = client.stack('api_key').bulk_operation().add_items(data).json()
253+
254+
-------------------------------
255+
"""
256+
if headers is not None:
257+
self.client.headers.update(headers)
258+
url = f"{self.path}/release/items"
259+
data = json.dumps(data)
260+
return self.client.post(url, headers = self.client.headers, data = data, params=self.params)
261+
262+
def update_items(self, data: dict, headers: dict = None):
263+
"""
264+
The update items to bulk operation request allows you to update multiple entries and assets to a bulk operation.
265+
266+
:return: The `update_items` method is returning the result of the `put` request made by the
267+
`client.post` method.
268+
-------------------------------
269+
[Example:]
270+
>>> data = {
271+
>>> "release": "release_uid",
272+
>>> "items": [
273+
>>> {
274+
>>> "uid": "entry_uid",
275+
>>> "locale": "en-us"
276+
>>> },
277+
>>> {
278+
>>> "uid": "entry_uid",
279+
>>> "locale": "en-us",
280+
>>> "variant_id": "entry_variant_id"
281+
>>> }
282+
>>> ]
283+
>>> or
284+
>>> [ '$all' ]
285+
>>> }
286+
>>> import contentstack_management
287+
>>> client = contentstack_management.Client(authtoken='your_authtoken')
288+
>>> result = client.stack('api_key').bulk_operation().update_items(data).json()
289+
290+
-------------------------------
291+
"""
292+
if headers is not None:
293+
self.client.headers.update(headers)
294+
url = f"{self.path}/release/update_items"
295+
data = json.dumps(data)
296+
return self.client.put(url, headers = self.client.headers, data = data, params=self.params)
297+
298+
def job_status(self, job_uid: str, headers: dict = None):
299+
"""
300+
The Job status request allows you to get the status of a bulk operation job.
301+
302+
:param job_uid: The `job_uid` parameter is a string that represents the unique identifier of the job
303+
whose status you want to retrieve
304+
:type job_uid: str
305+
:return: The `job_status` method is returning the result of the `get` request made by the
306+
`client.get` method.
307+
-------------------------------
308+
[Example:]
309+
>>> import contentstack_management
310+
>>> client = contentstack_management.Client(authtoken='your_authtoken')
311+
>>> result = client.stack('api_key').bulk_operation().job_status('job_uid').json()
312+
313+
-------------------------------
314+
"""
315+
if job_uid is None:
316+
raise ArgumentException("job_uid", "job_uid cannot be None")
317+
if headers is not None:
318+
self.client.headers.update(headers)
319+
url = f"{self.path}/jobs/{quote(job_uid)}"
320+
return self.client.get(url, headers = self.client.headers, params=self.params)
321+
230322

contentstack_management/content_types/content_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def imports(self, file_path):
340340
>>> response = content_type.imports()
341341
--------------------------------
342342
"""
343-
url = f"content_types/import"
343+
url = "content_types/import"
344344
self.client.headers['Content-Type'] = "multipart/form-data"
345345
files = {'content_type': open(f"{file_path}", 'rb')}
346346
return self.client.post(url, headers=self.client.headers, params=self.params, files=files)

contentstack_management/contentstack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import contentstack_management
21
from enum import Enum
32
from ._api_client import _APIClient
43
from contentstack_management.organizations import organization

contentstack_management/delivery_token/delivery_token.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class DeliveryToken(Parameter):

contentstack_management/environments/environment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class Environment(Parameter):

contentstack_management/extensions/extension.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109
from requests_toolbelt.multipart.encoder import MultipartEncoder
1110

contentstack_management/global_fields/global_fields.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ class GlobalFields(Parameter):
1818
methods each correspond to the CRUD
1919
operations that can be performed on the API """
2020

21-
def __init__(self, client, global_field_uid=None):
21+
def __init__(self, client, global_field_uid=None, options=None):
2222
self.client = client
2323
self.global_field_uid = global_field_uid
24+
self.options = options
2425
super().__init__(self.client)
26+
if self.options and 'api_version' in self.options:
27+
Parameter.add_header(self, 'api_version', str(self.options['api_version']))
2528

2629
def find(self):
2730
"""
@@ -34,7 +37,12 @@ def find(self):
3437
>>> result = client.stack("api_key").global_fields('global_field_uid').find().json()
3538
-------------------------------
3639
"""
37-
return self.client.get(_path, headers=self.client.headers, params = self.params)
40+
response = self.client.get(_path, headers=self.client.headers, params = self.params)
41+
# Remove the api_version header after request
42+
if self.options and 'api_version' in self.options:
43+
self.client.headers.pop('api_version', None)
44+
45+
return response
3846

3947
def fetch(self):
4048
"""
@@ -50,7 +58,12 @@ def fetch(self):
5058
-------------------------------
5159
"""
5260
url = f"{_path}/{self.global_field_uid}"
53-
return self.client.get(url, headers=self.client.headers, params = self.params)
61+
response = self.client.get(url, headers=self.client.headers, params = self.params)
62+
# Remove the api_version header after request
63+
if self.options and 'api_version' in self.options:
64+
self.client.headers.pop('api_version', None)
65+
66+
return response
5467

5568
def create(self, data):
5669
"""
@@ -74,7 +87,12 @@ def create(self, data):
7487
-------------------------------
7588
"""
7689
data = json.dumps(data)
77-
return self.client.post(_path, headers=self.client.headers, data=data, params = self.params)
90+
response = self.client.post(_path, headers=self.client.headers, data=data, params = self.params)
91+
# Remove the api_version header after request
92+
if self.options and 'api_version' in self.options:
93+
self.client.headers.pop('api_version', None)
94+
95+
return response
7896

7997
def update(self, data):
8098
"""
@@ -99,7 +117,12 @@ def update(self, data):
99117
"""
100118
url = f"{_path}/{self.global_field_uid}"
101119
data = json.dumps(data)
102-
return self.client.put(url, headers=self.client.headers, params=self.params, data=data)
120+
response = self.client.put(url, headers=self.client.headers, params=self.params, data=data)
121+
# Remove the api_version header after request
122+
if self.options and 'api_version' in self.options:
123+
self.client.headers.pop('api_version', None)
124+
125+
return response
103126

104127
def delete(self):
105128
"""
@@ -114,7 +137,12 @@ def delete(self):
114137
-------------------------------
115138
"""
116139
url = f"{_path}/{self.global_field_uid}"
117-
return self.client.delete(url, headers=self.client.headers, params=self.params)
140+
response = self.client.delete(url, headers=self.client.headers, params=self.params)
141+
# Remove the api_version header after request
142+
if self.options and 'api_version' in self.options:
143+
self.client.headers.pop('api_version', None)
144+
145+
return response
118146

119147
def imports(self, file_path):
120148
"""
@@ -131,7 +159,12 @@ def imports(self, file_path):
131159
"""
132160
self.client.headers['Content-Type'] = "multipart/form-data"
133161
files = {'global_field': open(f"{file_path}", 'rb')}
134-
return self.client.post('global_fields/import', headers=self.client.headers, params=self.params, files=files)
162+
response = self.client.post('global_fields/import', headers=self.client.headers, params=self.params, files=files)
163+
# Remove the api_version header after request
164+
if self.options and 'api_version' in self.options:
165+
self.client.headers.pop('api_version', None)
166+
167+
return response
135168

136169
def export(self):
137170
"""
@@ -148,4 +181,9 @@ def export(self):
148181
if self.global_field_uid is None or '':
149182
raise Exception('global_field_uid is required')
150183
url = f"{_path}/{self.global_field_uid}/export"
151-
return self.client.get(url, headers=self.client.headers, params=self.params)
184+
response = self.client.get(url, headers=self.client.headers, params=self.params)
185+
# Remove the api_version header after request
186+
if self.options and 'api_version' in self.options:
187+
self.client.headers.pop('api_version', None)
188+
189+
return response

contentstack_management/labels/label.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class Label(Parameter):

contentstack_management/locale/locale.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class Locale(Parameter):

contentstack_management/management_token/management_token.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class ManagementToken(Parameter):

contentstack_management/metadata/metadata.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
from ..common import Parameter
8-
from urllib.parse import quote
98
from .._errors import ArgumentException
109

1110
class Metadata(Parameter):

contentstack_management/publish_queue/publish_queue.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
The create(), read(), update(), and delete() methods each correspond to
44
the CRUD operations that can be performed on the API """
55

6-
import json
76
from ..common import Parameter
8-
from urllib.parse import quote
97
from .._errors import ArgumentException
108

119
class PublishQueue(Parameter):

0 commit comments

Comments
 (0)