ul-api-utils 9.0.0a2__py3-none-any.whl → 9.0.0a3__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 ul-api-utils might be problematic. Click here for more details.

@@ -1,6 +1,7 @@
1
1
  import json
2
2
  from typing import NamedTuple, Iterable, Any, List, Tuple, Dict, Optional
3
3
 
4
+ from flask_sqlalchemy.query import Query
4
5
  from pydantic import model_validator, BaseModel
5
6
 
6
7
  from ul_api_utils.errors import SimpleValidateApiError
@@ -14,11 +15,7 @@ class ApiRequestQueryPagination(NamedTuple):
14
15
  offset: int
15
16
  per_page: int
16
17
 
17
- def mk_sqlalchemy_pagination(self, items: Iterable[Any], total: int, query: Any = None) -> 'ApiPagination':
18
- if has_already_imported_db():
19
- from flask_sqlalchemy import Pagination
20
- return Pagination(total=total, query=query, per_page=self.per_page, page=self.page, items=items) # type: ignore
21
- assert query is None
18
+ def mk_item_pagination(self, items: Iterable[Any], total: int) -> ApiPagination:
22
19
  return ApiPagination(
23
20
  total=total,
24
21
  per_page=self.per_page,
@@ -26,6 +23,12 @@ class ApiRequestQueryPagination(NamedTuple):
26
23
  items=items,
27
24
  )
28
25
 
26
+ # TODO: Not sure that is worked. Check it if will be found usages
27
+ def mk_sqlalchemy_pagination(self, items: Iterable[Any], total: int, query: Query = None) -> 'ApiPagination':
28
+ if has_already_imported_db() and query:
29
+ return query.paginate(total=total, query=query, per_page=self.per_page, page=self.page, items=items) # type: ignore
30
+ return self.mk_item_pagination(items, total)
31
+
29
32
 
30
33
  class ApiRequestQuerySortBy(NamedTuple):
31
34
  params: List[Tuple[str, str]]
@@ -293,13 +293,10 @@ class ApiResource:
293
293
  mimetype: Optional[str], # it will be auto-detected by extension if mimetype==None
294
294
  as_attachment: bool = False,
295
295
  download_name: Optional[str] = None,
296
- attachment_filename: Optional[str] = None,
297
296
  conditional: bool = True,
298
297
  etag: Union[bool, str] = True,
299
- add_etags: Optional[bool] = None,
300
298
  last_modified: Optional[Union[datetime, int, float]] = None,
301
299
  max_age: Optional[Union[int, Callable[[Optional[str]], Optional[int]]]] = None,
302
- cache_timeout: Optional[int] = None,
303
300
  ) -> FileApiResponse:
304
301
  ApiResourceType.FILE.validate(self._type)
305
302
  if isinstance(path_or_file, str) and not os.path.exists(path_or_file):
@@ -311,13 +308,10 @@ class ApiResource:
311
308
  mimetype=mimetype,
312
309
  as_attachment=as_attachment,
313
310
  download_name=download_name,
314
- attachment_filename=attachment_filename,
315
311
  conditional=conditional,
316
312
  etag=etag,
317
- add_etags=add_etags,
318
313
  last_modified=last_modified,
319
314
  max_age=max_age,
320
- cache_timeout=cache_timeout,
321
315
  )
322
316
 
323
317
  def response_created_ok(self, payload: 'TPayloadInputUnion', total_count: Optional[int] = None) -> JsonApiResponse[Any]:
@@ -93,13 +93,10 @@ class FileApiResponse(ApiResponse):
93
93
  mimetype: Optional[str] = None # it will be auto-detected by extension if mimetype==None
94
94
  as_attachment: bool = False
95
95
  download_name: Optional[str] = None
96
- attachment_filename: Optional[str] = None
97
96
  conditional: bool = True
98
97
  etag: Union[bool, str] = True
99
- add_etags: Optional[bool] = None
100
98
  last_modified: Optional[Union[datetime, int, float]] = None
101
99
  max_age: Optional[Union[int, Callable[[Optional[str]], Optional[int]]]] = None
102
- cache_timeout: Optional[int] = None
103
100
 
104
101
  @classmethod
105
102
  def _internal_use__mk_schema(cls, inner_type: Optional[Type[BaseModel]]) -> Type[BaseModel]:
@@ -113,13 +110,10 @@ class FileApiResponse(ApiResponse):
113
110
  mimetype=self.mimetype,
114
111
  as_attachment=self.as_attachment,
115
112
  download_name=self.download_name,
116
- attachment_filename=self.attachment_filename,
117
113
  conditional=self.conditional,
118
114
  etag=self.etag,
119
- add_etags=self.add_etags,
120
115
  last_modified=self.last_modified,
121
116
  max_age=self.max_age,
122
- cache_timeout=self.cache_timeout,
123
117
  )
124
118
 
125
119
  resp.headers.update(self.headers)
@@ -10,6 +10,13 @@ from uuid import UUID
10
10
  from frozendict import frozendict
11
11
  from pydantic import BaseModel
12
12
 
13
+ from flask_sqlalchemy.query import Query
14
+ from flask_sqlalchemy.model import Model, DefaultMeta
15
+
16
+ from sqlalchemy.orm import Query, registry
17
+
18
+ from ul_db_utils.modules.postgres_modules.db import DbModel
19
+ from ul_db_utils.model.base_model import BaseModel as DbBaseModel
13
20
  from ul_api_utils.utils.imports import has_already_imported_db
14
21
 
15
22
  if TYPE_CHECKING:
@@ -26,11 +33,6 @@ def to_dict(obj: 'TDictable') -> Optional[Dict[str, Any]]:
26
33
  if isinstance(obj, BaseModel):
27
34
  return obj.model_dump()
28
35
  if has_already_imported_db():
29
- from ul_db_utils.modules.postgres_modules.db import DbModel
30
- from flask_sqlalchemy import BaseQuery, Model
31
- from sqlalchemy.orm import registry
32
- from ul_db_utils.model.base_model import BaseModel as DbBaseModel
33
-
34
36
  if isinstance(obj, DbBaseModel) or isinstance(obj, DbModel):
35
37
  return obj.to_dict()
36
38
  if isinstance(obj, Model):
@@ -38,7 +40,7 @@ def to_dict(obj: 'TDictable') -> Optional[Dict[str, Any]]:
38
40
  for field in (x for x in dir(obj) if not x.startswith('_') and x != 'metadata'):
39
41
  val = obj.__getattribute__(field)
40
42
  # is this field method defination, or an SQLalchemy object
41
- if not hasattr(val, "__call__") and not isinstance(val, BaseQuery): # noqa: B004
43
+ if not hasattr(val, "__call__") and not isinstance(val, Query): # noqa: B004
42
44
  if isinstance(val, datetime):
43
45
  val = str(val.isoformat())
44
46
  if isinstance(val, UUID):
@@ -76,9 +78,7 @@ class CustomJSONEncoder(JSONEncoder):
76
78
  return str(obj.__html__())
77
79
 
78
80
  if has_already_imported_db():
79
- from ul_db_utils.model.base_model import BaseModel as DbBaseModel
80
- from flask_sqlalchemy import BaseQuery, Model, DefaultMeta
81
- from sqlalchemy.orm import Query, registry
81
+
82
82
 
83
83
  if isinstance(obj, DbBaseModel):
84
84
  return obj.to_dict()
@@ -89,7 +89,7 @@ class CustomJSONEncoder(JSONEncoder):
89
89
  for field in [x for x in dir(obj) if not x.startswith('_') and x != 'metadata']:
90
90
  val = obj.__getattribute__(field)
91
91
  # is this field method defination, or an SQLalchemy object
92
- if not hasattr(val, "__call__") and not isinstance(val, BaseQuery): # noqa: B004
92
+ if not hasattr(val, "__call__") and not isinstance(val, Query): # noqa: B004
93
93
  if isinstance(val, datetime):
94
94
  val = str(val.isoformat())
95
95
  if isinstance(val, UUID):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 9.0.0a2
3
+ Version: 9.0.0a3
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -25,13 +25,13 @@ ul_api_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  ul_api_utils/sentry.py,sha256=UH_SwZCAoKH-Nw5B9CVQMoF-b1BJOp-ZTzwqUZ3Oq84,1801
26
26
  ul_api_utils/access/__init__.py,sha256=NUyRNvCVwfePrfdn5ATFVfHeSO3iq4-Syeup4IAZGzs,4526
27
27
  ul_api_utils/api_resource/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
- ul_api_utils/api_resource/api_request.py,sha256=6Ag2trKIkenhYYPU2--hnfNJC5lLgBxVQ7jXj5D1eXM,3303
29
- ul_api_utils/api_resource/api_resource.py,sha256=j-E8KJiXWS1L0oVIerJZlbGpDL2ijlQrck4GrJPWPyE,17840
28
+ ul_api_utils/api_resource/api_request.py,sha256=gB7imtE1uTI8eSTFql3Zk92kkQKD47YN8KQfshY-DQc,3488
29
+ ul_api_utils/api_resource/api_resource.py,sha256=WMGYtBKoobpRJVNLLWdbuVpq2IcIAI9kK5_Hgd4TqqM,17575
30
30
  ul_api_utils/api_resource/api_resource_config.py,sha256=l9OYJy75UZLshOkEQDO5jlhXeb5H4HDPu-nLOjuoexw,769
31
31
  ul_api_utils/api_resource/api_resource_error_handling.py,sha256=E0SWpjFSIP-4SumbgzrHtFuFiGe9q38WsvLROt0YcPE,1168
32
32
  ul_api_utils/api_resource/api_resource_fn_typing.py,sha256=n5bux_azlV8aRtRQdoIP553tXWHCi7P-brKUAgj502E,18970
33
33
  ul_api_utils/api_resource/api_resource_type.py,sha256=mgjSQI3swGpgpLI6y35LYtFrdN-kXyV5cQorwGW7h6g,462
34
- ul_api_utils/api_resource/api_response.py,sha256=bfnWo5GZUCzwJm8rDfzcpuYL4l63pBedJ0tTguP--qw,10069
34
+ ul_api_utils/api_resource/api_response.py,sha256=OnIQepPuJoTm57SGmwTbdosKSLzSZnyEquZp9mjO6vE,9804
35
35
  ul_api_utils/api_resource/api_response_db.py,sha256=ucY6ANPlHZml7JAbvq-PL85z0bvERTjEJKvz-REPyok,888
36
36
  ul_api_utils/api_resource/api_response_payload_alias.py,sha256=FoD0LhQGZ2T8A5-VKRX5ADyzSgm7_dd3qxU2BgCVXkA,587
37
37
  ul_api_utils/api_resource/db_types.py,sha256=NxHBYetUogWZow7Vhd3e00Y3L62-dxjwRzJlXywYlV4,439
@@ -111,7 +111,7 @@ ul_api_utils/utils/deprecated.py,sha256=xR3ELgoDj7vJEY4CAYeEhdbtSJTfkukbjxcULtpM
111
111
  ul_api_utils/utils/flags.py,sha256=AYN5nKWp4-uu6PSlPptL7ZiLqr3Pu-x5dffF6SBsqfg,957
112
112
  ul_api_utils/utils/imports.py,sha256=i8PhoD0c_jnWTeXt_VxW_FihynwXSL_dHRT7jQiFyXE,376
113
113
  ul_api_utils/utils/instance_checks.py,sha256=9punTfY5uabuJhmSGLfTgBqRderoFysCXBSI8rvbPco,467
114
- ul_api_utils/utils/json_encoder.py,sha256=ra43WhkAadIvVpUY3uik_Nzg0LVXUXTGYvx4Gx7fD_g,4578
114
+ ul_api_utils/utils/json_encoder.py,sha256=_QG2VugHUyUJ9V1GG_z6-Yh0qaBpJGQS5McSYR-7vOU,4392
115
115
  ul_api_utils/utils/load_modules.py,sha256=_CPmQuB6o_33FE6zFl_GyO5xS5gmjfNffB6k-cglKAA,685
116
116
  ul_api_utils/utils/token_check.py,sha256=-Quuh8gOs9fNE1shYhdiMpQedafsLN7MB2ilSxG_F8E,489
117
117
  ul_api_utils/utils/token_check_through_request.py,sha256=OyyObu6Btk9br7auIYvWcMULhNznNSD5T0mWOwZX7Uk,663
@@ -148,9 +148,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
148
148
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
149
149
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
150
150
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=20gLlnm1Ithsbbz3NIUXVAd92lW6YwVRSg_nETZhfaI,1442
151
- ul_api_utils-9.0.0a2.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
152
- ul_api_utils-9.0.0a2.dist-info/METADATA,sha256=0dKlK__iEBPXqpkoGQI3TMWA4DLK_vCWs8P13qCwalc,14714
153
- ul_api_utils-9.0.0a2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
154
- ul_api_utils-9.0.0a2.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
155
- ul_api_utils-9.0.0a2.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
156
- ul_api_utils-9.0.0a2.dist-info/RECORD,,
151
+ ul_api_utils-9.0.0a3.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
152
+ ul_api_utils-9.0.0a3.dist-info/METADATA,sha256=6W9QhXPwD_bFPydsEgTj9c-3WxoUjrsHicmipFpuKY8,14714
153
+ ul_api_utils-9.0.0a3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
154
+ ul_api_utils-9.0.0a3.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
155
+ ul_api_utils-9.0.0a3.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
156
+ ul_api_utils-9.0.0a3.dist-info/RECORD,,