internal 0.1.73__tar.gz → 0.1.75__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.

Potentially problematic release.


This version of internal might be problematic. Click here for more details.

Files changed (27) hide show
  1. {internal-0.1.73 → internal-0.1.75}/PKG-INFO +1 -1
  2. {internal-0.1.73 → internal-0.1.75}/pyproject.toml +1 -1
  3. {internal-0.1.73 → internal-0.1.75}/src/internal/exception/internal_exception.py +9 -0
  4. {internal-0.1.73 → internal-0.1.75}/src/internal/http/responses.py +1 -1
  5. {internal-0.1.73 → internal-0.1.75}/src/internal/model/base_model.py +30 -4
  6. {internal-0.1.73 → internal-0.1.75}/README.md +0 -0
  7. {internal-0.1.73 → internal-0.1.75}/src/internal/__init__.py +0 -0
  8. {internal-0.1.73 → internal-0.1.75}/src/internal/base_config.py +0 -0
  9. {internal-0.1.73 → internal-0.1.75}/src/internal/base_factory.py +0 -0
  10. {internal-0.1.73 → internal-0.1.75}/src/internal/common_enum/__init__.py +0 -0
  11. {internal-0.1.73 → internal-0.1.75}/src/internal/common_enum/contact_type.py +0 -0
  12. {internal-0.1.73 → internal-0.1.75}/src/internal/common_enum/operator_type.py +0 -0
  13. {internal-0.1.73 → internal-0.1.75}/src/internal/const.py +0 -0
  14. {internal-0.1.73 → internal-0.1.75}/src/internal/database.py +0 -0
  15. {internal-0.1.73 → internal-0.1.75}/src/internal/exception/__init__.py +0 -0
  16. {internal-0.1.73 → internal-0.1.75}/src/internal/exception/base_exception.py +0 -0
  17. {internal-0.1.73 → internal-0.1.75}/src/internal/ext/__init__.py +0 -0
  18. {internal-0.1.73 → internal-0.1.75}/src/internal/ext/amazon/__init__.py +0 -0
  19. {internal-0.1.73 → internal-0.1.75}/src/internal/ext/amazon/aws/__init__.py +0 -0
  20. {internal-0.1.73 → internal-0.1.75}/src/internal/ext/amazon/aws/const.py +0 -0
  21. {internal-0.1.73 → internal-0.1.75}/src/internal/http/__init__.py +0 -0
  22. {internal-0.1.73 → internal-0.1.75}/src/internal/http/requests.py +0 -0
  23. {internal-0.1.73 → internal-0.1.75}/src/internal/interface/__init__.py +0 -0
  24. {internal-0.1.73 → internal-0.1.75}/src/internal/interface/base_interface.py +0 -0
  25. {internal-0.1.73 → internal-0.1.75}/src/internal/model/__init__.py +0 -0
  26. {internal-0.1.73 → internal-0.1.75}/src/internal/model/operate.py +0 -0
  27. {internal-0.1.73 → internal-0.1.75}/src/internal/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 0.1.73
3
+ Version: 0.1.75
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "internal"
3
- version = "0.1.73"
3
+ version = "0.1.75"
4
4
  description = ""
5
5
  authors = ["Ray <ray@cruisys.com>"]
6
6
  readme = "README.md"
@@ -36,3 +36,12 @@ class DatabaseConnectFailureException(InternalBaseException):
36
36
  def __init__(self, message: str = None, **kwargs):
37
37
  _message = message or self.message
38
38
  super().__init__(status.HTTP_500_INTERNAL_SERVER_ERROR, self.code, _message, **kwargs)
39
+
40
+
41
+ class NoChangeException(InternalBaseException):
42
+ code = "error_no_change"
43
+ message = "Document no change"
44
+
45
+ def __init__(self, message: str = None, **kwargs):
46
+ _message = message or self.message
47
+ super().__init__(status.HTTP_200_OK, self.code, _message, **kwargs)
@@ -9,7 +9,7 @@ from beanie import Document, Link
9
9
  async def async_response(data=None, message=None, code=None, page_no=None, total_num=None, page_size=None,
10
10
  status_code=status.HTTP_200_OK):
11
11
  def _serialize(data):
12
- if issubclass(data, Document):
12
+ if issubclass(type(data), Document):
13
13
  link_field_list = []
14
14
  for field_name in data.__annotations__:
15
15
  field_type = getattr(data, field_name)
@@ -1,13 +1,16 @@
1
1
  from datetime import datetime
2
2
  from enum import Enum
3
- from typing import List, Tuple
3
+ from typing import List, Tuple, Union, Dict, Type
4
4
 
5
+ import arrow
5
6
  import pymongo
6
- from fastapi import FastAPI
7
7
  from beanie import Document
8
- from pydantic import Field
8
+ from fastapi import FastAPI
9
+ from pydantic import Field, BaseModel
9
10
 
11
+ from .operate import Operate
10
12
  from ..const import DEF_PAGE_SIZE, DEF_PAGE_NO
13
+ from ..exception.internal_exception import NoChangeException
11
14
 
12
15
 
13
16
  class InternalBaseDocument(Document):
@@ -16,7 +19,8 @@ class InternalBaseDocument(Document):
16
19
 
17
20
  @classmethod
18
21
  async def get_pagination_list(cls, app: FastAPI, query: list = None, sort: List[Tuple] = None,
19
- page_size: int = DEF_PAGE_SIZE, page_no: int = DEF_PAGE_NO, ignore_cache: bool = False,
22
+ page_size: int = DEF_PAGE_SIZE, page_no: int = DEF_PAGE_NO,
23
+ ignore_cache: bool = False,
20
24
  fetch_links: bool = False):
21
25
  if not query:
22
26
  final_query = []
@@ -46,6 +50,28 @@ class InternalBaseDocument(Document):
46
50
 
47
51
  return page_no, page_size, total_num, page_data
48
52
 
53
+ async def update_wrap(self, schema: Union[Dict, Type[BaseModel]]) -> Tuple[Operate, 'InternalBaseDocument']:
54
+ if not issubclass(type(schema), dict) and not issubclass(type(schema), BaseModel):
55
+ raise TypeError("Schema must be a subclass of BaseModel or dict")
56
+
57
+ original_model = self.model_copy(deep=True)
58
+ delta_dict = schema
59
+ if issubclass(type(schema), BaseModel):
60
+ delta_dict = schema.model_dump()
61
+
62
+ for key, value in delta_dict.items():
63
+ if value is not None and hasattr(self, key):
64
+ setattr(self, key, value)
65
+
66
+ operate = await Operate.generate_operate(original_model.model_dump(), self.model_dump())
67
+ if not operate.add and not operate.remove and not operate.change:
68
+ raise NoChangeException()
69
+
70
+ self.update_time = arrow.utcnow().datetime
71
+
72
+ await self.save()
73
+ return operate, self
74
+
49
75
 
50
76
  class OrderTypeEnum(str, Enum):
51
77
  ASC = "ASC"
File without changes