clear-skies 1.22.2__py3-none-any.whl → 1.22.3__py3-none-any.whl
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.
Potentially problematic release.
This version of clear-skies might be problematic. Click here for more details.
- {clear_skies-1.22.2.dist-info → clear_skies-1.22.3.dist-info}/METADATA +1 -1
- {clear_skies-1.22.2.dist-info → clear_skies-1.22.3.dist-info}/RECORD +6 -5
- clearskies/backends/api_get_only_backend.py +101 -0
- clearskies/column_types/has_many.py +8 -0
- {clear_skies-1.22.2.dist-info → clear_skies-1.22.3.dist-info}/LICENSE +0 -0
- {clear_skies-1.22.2.dist-info → clear_skies-1.22.3.dist-info}/WHEEL +0 -0
|
@@ -47,6 +47,7 @@ clearskies/autodoc/schema/password.py,sha256=Ptj8OeddAL4h69KWqZ6ubZ2awR13xdDIrNe
|
|
|
47
47
|
clearskies/autodoc/schema/string.py,sha256=oxZPCxYYhWnNHdbtwD3QuniStbj8XbBBpDTFXgPR1VU,244
|
|
48
48
|
clearskies/backends/__init__.py,sha256=IqIpTNdA0U14wFNBkotwc9kZr_mMw3ry8LnldOZ0HLs,755
|
|
49
49
|
clearskies/backends/api_backend.py,sha256=PQyT00pMtZZUQhfWySzVbXZ2GpycO93CRKVOmUFeo10,15073
|
|
50
|
+
clearskies/backends/api_get_only_backend.py,sha256=OWXdoaSaF5fWb7GN1OgkGED3edKfoeOBMHc8bKtm2ig,3885
|
|
50
51
|
clearskies/backends/backend.py,sha256=fkL-De0MUdzcS2JG_spSUQZIVL9oRFvaL6SP26JPpcI,7399
|
|
51
52
|
clearskies/backends/cursor_backend.py,sha256=VntlPS6z6bnZOC3XRJ-WFf5gK3pFUhH_qJpnZn8hl9U,11278
|
|
52
53
|
clearskies/backends/example_backend.py,sha256=jVpv0LZpNUEJGko0XqioLkHmZHbCW6M4YyNvzKlZcDw,1413
|
|
@@ -73,7 +74,7 @@ clearskies/column_types/datetime.py,sha256=xtuZpUC9fA16i1oO80kPIx--8RDPuei9RdsDD
|
|
|
73
74
|
clearskies/column_types/datetime_micro.py,sha256=ewQSniCc2MmNIyX2XNuNcCIwh5Fpf1HcvpLfzB8lz8g,382
|
|
74
75
|
clearskies/column_types/email.py,sha256=qq0Yo_C3KxUqT68q2HWXocBBR4xwMqjxcIdgZRv218U,584
|
|
75
76
|
clearskies/column_types/float.py,sha256=j8jJeBueSOusPtAFCWgLHYBncfLnqT1U7bh1zcAkYiA,1332
|
|
76
|
-
clearskies/column_types/has_many.py,sha256=
|
|
77
|
+
clearskies/column_types/has_many.py,sha256=z1tco_KWLr8WqKk5X8HJwdfjxpT2WwWNb5hgwDHM2fU,7432
|
|
77
78
|
clearskies/column_types/has_one.py,sha256=uphIPUuHLwwmhljLMaKKPujR6TYTT7onn-hHUF6S_IY,2230
|
|
78
79
|
clearskies/column_types/integer.py,sha256=dGIluusPmhLRNg7PplOJLbQI2AXojqRBUHt8ekYWNVI,1386
|
|
79
80
|
clearskies/column_types/json.py,sha256=TbZkdwCoZYhbALUxof2jENGfaq2i5TlcyBcmo7XzDGQ,652
|
|
@@ -206,7 +207,7 @@ clearskies/tests/simple_api/models/__init__.py,sha256=nUA0W6fgXw_Bxa9CudkaDkC80t
|
|
|
206
207
|
clearskies/tests/simple_api/models/status.py,sha256=PEhPbaQh5qdUNHp8O0gz91LOLENAEBtqSaHxUPXchaM,699
|
|
207
208
|
clearskies/tests/simple_api/models/user.py,sha256=5_P4Tp1tTdX7PkMJ__epPM5MA7JAeVYGas69vcWloLc,819
|
|
208
209
|
clearskies/tests/simple_api/users_api.py,sha256=KYXCgEofDxHeRdQK67txN5oYUPvxxmB8JTku7L-apk4,2344
|
|
209
|
-
clear_skies-1.22.
|
|
210
|
-
clear_skies-1.22.
|
|
211
|
-
clear_skies-1.22.
|
|
212
|
-
clear_skies-1.22.
|
|
210
|
+
clear_skies-1.22.3.dist-info/LICENSE,sha256=3Ehd0g3YOpCj8sqj0Xjq5qbOtjjgk9qzhhD9YjRQgOA,1053
|
|
211
|
+
clear_skies-1.22.3.dist-info/METADATA,sha256=YtXu3sQzPtg-LoA92QMTlV0R6cQEuzkO_e5AXs_1JVw,1817
|
|
212
|
+
clear_skies-1.22.3.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
|
213
|
+
clear_skies-1.22.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from .api_backend import ApiBackend
|
|
2
|
+
from typing import Any, Callable, Dict, List, Tuple
|
|
3
|
+
from .. import model
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ApiGetOnlyBackend(ApiBackend):
|
|
7
|
+
_requests = None
|
|
8
|
+
_auth = None
|
|
9
|
+
_id_column_name = None
|
|
10
|
+
|
|
11
|
+
_allowed_configs = [
|
|
12
|
+
"wheres",
|
|
13
|
+
"table_name",
|
|
14
|
+
"model_columns",
|
|
15
|
+
"select_all",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
def __init__(self, requests):
|
|
19
|
+
self._requests = requests
|
|
20
|
+
|
|
21
|
+
def configure(self, auth=None, origin=None, id_column_name="id"):
|
|
22
|
+
self._auth = auth
|
|
23
|
+
self._origin = origin
|
|
24
|
+
self._id_column_name = id_column_name
|
|
25
|
+
|
|
26
|
+
def records_url(self, configuration):
|
|
27
|
+
record_id = None
|
|
28
|
+
for where in configuration["wheres"]:
|
|
29
|
+
if where["column"] == "id":
|
|
30
|
+
record_id = where["values"][0]
|
|
31
|
+
if record_id:
|
|
32
|
+
return self.auth_origin + configuration["table_name"].strip("/") + f"/{record_id}"
|
|
33
|
+
return self.auth_origin + configuration["table_name"].strip("/") + "/search"
|
|
34
|
+
|
|
35
|
+
def delete_url(self, id: str, model: model.Model) -> str:
|
|
36
|
+
table_name = model.table_name().rstrip("/")
|
|
37
|
+
return f"{table_name}/{id}"
|
|
38
|
+
|
|
39
|
+
def update_url(self, id: str, model: model.Model) -> str:
|
|
40
|
+
table_name = model.table_name().rstrip("/")
|
|
41
|
+
return f"{table_name}/{id}"
|
|
42
|
+
|
|
43
|
+
def create_url(self, data: Dict[str, Any], model: model.Model) -> str:
|
|
44
|
+
return model.table_name().rstrip("/")
|
|
45
|
+
|
|
46
|
+
def records_method(self, configuration: Dict[str, Any]) -> str:
|
|
47
|
+
return "POST"
|
|
48
|
+
|
|
49
|
+
def count_method(self, configuration: Dict[str, Any]) -> str:
|
|
50
|
+
return "POST"
|
|
51
|
+
|
|
52
|
+
def _build_delete_request(self, id, model):
|
|
53
|
+
data = model.data
|
|
54
|
+
(url, data) = self._finalize_url_and_data(self.delete_url(id, model), data)
|
|
55
|
+
return [url, self.delete_method(id, model), {}, {}]
|
|
56
|
+
|
|
57
|
+
def _build_count_request(self, configuration):
|
|
58
|
+
[url, method, json_data, headers] = super()._build_count_request(configuration)
|
|
59
|
+
json_data["count_only"] = True
|
|
60
|
+
return [url, method, json_data, headers]
|
|
61
|
+
|
|
62
|
+
def records(self, configuration, model, next_page_data={}):
|
|
63
|
+
configuration = self._check_query_configuration(configuration)
|
|
64
|
+
[url, method, json_data, headers] = self._build_records_request(configuration)
|
|
65
|
+
response = self._execute_request(url, method, json=json_data, headers=headers).json()
|
|
66
|
+
records = self._map_records_response(response)
|
|
67
|
+
for next_page_key in ["nextPage", "NextPage", "next_page"]:
|
|
68
|
+
if response.get("pagination", {}).get(next_page_key):
|
|
69
|
+
for key, value in response["pagination"][next_page_key].items():
|
|
70
|
+
next_page_data[key] = value
|
|
71
|
+
return records
|
|
72
|
+
|
|
73
|
+
def _as_post_data(self, configuration):
|
|
74
|
+
data = {
|
|
75
|
+
"where": list(
|
|
76
|
+
map(lambda where: self._where_for_post(where, configuration["model_columns"]), configuration["wheres"])
|
|
77
|
+
),
|
|
78
|
+
"sort": configuration["sorts"],
|
|
79
|
+
"start": configuration["pagination"].get("start", 0),
|
|
80
|
+
"limit": configuration["limit"],
|
|
81
|
+
}
|
|
82
|
+
return {key: value for (key, value) in data.items() if value}
|
|
83
|
+
|
|
84
|
+
def _where_for_post(self, where, columns):
|
|
85
|
+
prefix = ""
|
|
86
|
+
if where.get("table"):
|
|
87
|
+
prefix = where["table"] + "."
|
|
88
|
+
return {
|
|
89
|
+
"column": prefix + where["column"],
|
|
90
|
+
"operator": where["operator"],
|
|
91
|
+
"value": self.normalize_outgoing_value(where, columns, where["values"][0]),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
def normalize_outgoing_value(self, where, columns, value):
|
|
95
|
+
column_name = where["column"]
|
|
96
|
+
if where.get("table") or column_name not in columns:
|
|
97
|
+
return value
|
|
98
|
+
normalized_data = self.column_to_backend(columns[column_name], {column_name: value})
|
|
99
|
+
if column_name in normalized_data:
|
|
100
|
+
return normalized_data[column_name]
|
|
101
|
+
return value
|
|
@@ -101,6 +101,14 @@ class HasMany(Column):
|
|
|
101
101
|
f"{error_prefix} 'where' must be a list of where conditions or callables that return where conditions, but the item in entry #${index+1} was neither a string nor a callable"
|
|
102
102
|
)
|
|
103
103
|
|
|
104
|
+
def _finalize_configuration(self, configuration):
|
|
105
|
+
return {
|
|
106
|
+
**super()._finalize_configuration(configuration),
|
|
107
|
+
**{
|
|
108
|
+
"where": configuration.get("where", []),
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
104
112
|
def get_child_columns(self):
|
|
105
113
|
if "child_columns" not in self.configuration:
|
|
106
114
|
self.configuration["child_columns"] = self.child_models.columns()
|
|
File without changes
|
|
File without changes
|