bapp-api-client 0.4.1__tar.gz → 0.4.3__tar.gz
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.
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/CHANGELOG.md +1 -1
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/PKG-INFO +1 -1
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/bapp_api_client/client.py +24 -4
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/pyproject.toml +1 -1
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/.github/workflows/publish.yml +0 -0
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/LICENSE +0 -0
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/README.md +0 -0
- {bapp_api_client-0.4.1 → bapp_api_client-0.4.3}/bapp_api_client/__init__.py +0 -0
|
@@ -54,15 +54,19 @@ class BappApiClient:
|
|
|
54
54
|
host="https://panel.bapp.ro/api",
|
|
55
55
|
tenant=None,
|
|
56
56
|
app="account",
|
|
57
|
+
user_agent=None,
|
|
57
58
|
):
|
|
58
59
|
self.host = host.rstrip("/")
|
|
59
60
|
self.tenant = tenant
|
|
60
61
|
self.app = app
|
|
62
|
+
self.user_agent = user_agent
|
|
61
63
|
self._session = requests.Session()
|
|
62
64
|
if bearer:
|
|
63
65
|
self._session.headers["Authorization"] = f"Bearer {bearer}"
|
|
64
66
|
elif token:
|
|
65
67
|
self._session.headers["Authorization"] = f"Token {token}"
|
|
68
|
+
if user_agent:
|
|
69
|
+
self._session.headers["User-Agent"] = user_agent
|
|
66
70
|
|
|
67
71
|
# -- internals -----------------------------------------------------------
|
|
68
72
|
|
|
@@ -202,7 +206,8 @@ class BappApiClient:
|
|
|
202
206
|
})
|
|
203
207
|
return views
|
|
204
208
|
|
|
205
|
-
def get_document_url(self, record, output="html", label=None,
|
|
209
|
+
def get_document_url(self, record, output="html", label=None,
|
|
210
|
+
variation=None, download=False):
|
|
206
211
|
"""Build a document render/download URL from a record.
|
|
207
212
|
|
|
208
213
|
Works with both ``public_view`` and ``view_token`` formats.
|
|
@@ -217,6 +222,11 @@ class BappApiClient:
|
|
|
217
222
|
variation: Variation code for ``public_view`` entries that
|
|
218
223
|
support variations (e.g. ``"v4"``). Falls back to the
|
|
219
224
|
entry's ``default_variation`` when *None*.
|
|
225
|
+
download: When *True* the response is sent as an attachment
|
|
226
|
+
(``Content-Disposition: attachment``). For ``public_view``
|
|
227
|
+
this appends ``&download=true``; for legacy ``view_token``
|
|
228
|
+
with ``output="pdf"`` this selects ``pdf.download`` instead
|
|
229
|
+
of ``pdf.view``.
|
|
220
230
|
|
|
221
231
|
Returns:
|
|
222
232
|
URL string, or *None* if the record has no view tokens.
|
|
@@ -243,14 +253,21 @@ class BappApiClient:
|
|
|
243
253
|
v = variation or view.get("default_variation")
|
|
244
254
|
if v:
|
|
245
255
|
url += f"&variation={v}"
|
|
256
|
+
if download:
|
|
257
|
+
url += "&download=true"
|
|
246
258
|
return url
|
|
247
259
|
|
|
248
260
|
# Legacy view_token
|
|
249
|
-
|
|
250
|
-
|
|
261
|
+
if output == "pdf":
|
|
262
|
+
action = "pdf.download" if download else "pdf.view"
|
|
263
|
+
elif output == "context":
|
|
264
|
+
action = "pdf.context"
|
|
265
|
+
else:
|
|
266
|
+
action = "pdf.preview"
|
|
251
267
|
return f"{self.host}/documents/{action}?token={token}"
|
|
252
268
|
|
|
253
|
-
def get_document_content(self, record, output="html", label=None,
|
|
269
|
+
def get_document_content(self, record, output="html", label=None,
|
|
270
|
+
variation=None, download=False):
|
|
254
271
|
"""Fetch document content (PDF, HTML, JPG, etc.) as bytes.
|
|
255
272
|
|
|
256
273
|
Builds the URL via :meth:`get_document_url` and fetches the raw
|
|
@@ -262,6 +279,8 @@ class BappApiClient:
|
|
|
262
279
|
``"context"``.
|
|
263
280
|
label: Select a specific view by label.
|
|
264
281
|
variation: Variation code for ``public_view`` entries.
|
|
282
|
+
download: When *True* the server sends the response as an
|
|
283
|
+
attachment.
|
|
265
284
|
|
|
266
285
|
Returns:
|
|
267
286
|
``bytes`` content, or *None* if the record has no view tokens.
|
|
@@ -271,6 +290,7 @@ class BappApiClient:
|
|
|
271
290
|
"""
|
|
272
291
|
url = self.get_document_url(
|
|
273
292
|
record, output=output, label=label, variation=variation,
|
|
293
|
+
download=download,
|
|
274
294
|
)
|
|
275
295
|
if url is None:
|
|
276
296
|
return None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|