internal 1.1.35.2__tar.gz → 1.1.35.4__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.
- {internal-1.1.35.2 → internal-1.1.35.4}/PKG-INFO +1 -1
- {internal-1.1.35.2 → internal-1.1.35.4}/pyproject.toml +1 -1
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/model/base_model.py +75 -26
- {internal-1.1.35.2 → internal-1.1.35.4}/README.md +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/base_config.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/base_factory.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/cache_redis.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/car_relation_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/description_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/device_code.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/event_code.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/lpr_direction.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/notify_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/operator_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/order_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/point_type.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/common_enum/websocket_channel.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/const.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/database.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/exception/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/exception/app_exception.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/exception/base_exception.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/exception/internal_exception.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/ext/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/ext/amazon/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/ext/amazon/aws/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/ext/amazon/aws/const.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/http/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/http/requests.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/http/responses.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/interface/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/interface/base_interface.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/middleware/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/middleware/log_request.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/model/__init__.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/model/operate.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/utils.py +0 -0
- {internal-1.1.35.2 → internal-1.1.35.4}/src/internal/validator_utils.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
from idlelib import query
|
|
2
3
|
|
|
3
4
|
from typing import List, Tuple, Union, Dict, Type, Optional, Any, Literal, Union, Set, Mapping
|
|
4
5
|
import typing_extensions
|
|
@@ -28,7 +29,7 @@ class InternalBaseDocument(Document):
|
|
|
28
29
|
async def get_pagination_list(cls, app: FastAPI, query: list = None, sort: List[Tuple] = None,
|
|
29
30
|
page_size: int = DEF_PAGE_SIZE, page_no: int = DEF_PAGE_NO,
|
|
30
31
|
ignore_cache: bool = False, fetch_links: bool = False,
|
|
31
|
-
|
|
32
|
+
exclude_field_list: List[str] = None):
|
|
32
33
|
if not query:
|
|
33
34
|
final_query = []
|
|
34
35
|
else:
|
|
@@ -48,26 +49,55 @@ class InternalBaseDocument(Document):
|
|
|
48
49
|
continue
|
|
49
50
|
final_sort.append((cls.id, pymongo.ASCENDING))
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
if exclude_field_list:
|
|
53
|
+
# 當需要排除欄位時,使用 Motor 直接操作
|
|
54
|
+
collection = cls.get_motor_collection()
|
|
55
|
+
projection = {field: 0 for field in exclude_field_list}
|
|
56
|
+
|
|
57
|
+
# 建立查詢條件
|
|
58
|
+
mongo_query = {}
|
|
59
|
+
for q in final_query:
|
|
60
|
+
if hasattr(q, 'query'):
|
|
61
|
+
mongo_query.update(q.query)
|
|
62
|
+
|
|
63
|
+
# 計算總數
|
|
64
|
+
total_num = await collection.count_documents(mongo_query)
|
|
65
|
+
total_pages = (total_num + page_size - 1) // page_size
|
|
66
|
+
|
|
67
|
+
if total_pages == 0:
|
|
68
|
+
page_no = 1
|
|
69
|
+
page_data = []
|
|
70
|
+
else:
|
|
71
|
+
page_no = max(1, min(page_no, total_pages))
|
|
72
|
+
|
|
73
|
+
# 執行分頁查詢
|
|
74
|
+
cursor = collection.find(mongo_query, projection).sort(final_sort).skip(
|
|
75
|
+
(page_no - 1) * page_size).limit(page_size)
|
|
76
|
+
documents = await cursor.to_list(None)
|
|
77
|
+
|
|
78
|
+
# 轉換為 Pydantic 模型
|
|
79
|
+
page_data = []
|
|
80
|
+
for doc in documents:
|
|
81
|
+
try:
|
|
82
|
+
page_data.append(cls.model_validate(doc))
|
|
83
|
+
except Exception as e:
|
|
84
|
+
print(f"模型驗證失敗: {e}")
|
|
85
|
+
continue
|
|
59
86
|
else:
|
|
60
|
-
|
|
87
|
+
# 沒有排除欄位時使用 Beanie 的方法
|
|
88
|
+
total_num = await cls.find(*final_query, ignore_cache=ignore_cache, fetch_links=fetch_links).sort(
|
|
89
|
+
*final_sort).count()
|
|
61
90
|
|
|
62
|
-
|
|
63
|
-
data_query = cls.find(*final_query, ignore_cache=ignore_cache, fetch_links=fetch_links)
|
|
91
|
+
total_pages = (total_num + page_size - 1) // page_size
|
|
64
92
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
if total_pages == 0:
|
|
94
|
+
page_no = 1
|
|
95
|
+
page_data = []
|
|
96
|
+
else:
|
|
97
|
+
page_no = max(1, min(page_no, total_pages))
|
|
69
98
|
|
|
70
|
-
|
|
99
|
+
page_data = await cls.find(*final_query, ignore_cache=ignore_cache, fetch_links=fetch_links).sort(
|
|
100
|
+
*final_sort).limit(page_size).skip((page_no - 1) * page_size).to_list()
|
|
71
101
|
|
|
72
102
|
return page_no, page_size, total_num, page_data
|
|
73
103
|
|
|
@@ -96,7 +126,7 @@ class InternalBaseDocument(Document):
|
|
|
96
126
|
|
|
97
127
|
@classmethod
|
|
98
128
|
async def get_list(cls, app: FastAPI, query: list = None, sort: List[Tuple] = None, ignore_cache: bool = False,
|
|
99
|
-
fetch_links: bool = False,
|
|
129
|
+
fetch_links: bool = False, exclude_field_list: List[str] = None):
|
|
100
130
|
if not query:
|
|
101
131
|
final_query = []
|
|
102
132
|
else:
|
|
@@ -116,15 +146,34 @@ class InternalBaseDocument(Document):
|
|
|
116
146
|
continue
|
|
117
147
|
final_sort.append((cls.id, pymongo.ASCENDING))
|
|
118
148
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
149
|
+
if exclude_field_list:
|
|
150
|
+
# 當需要排除欄位時,使用 Motor 直接操作
|
|
151
|
+
collection = cls.get_motor_collection()
|
|
152
|
+
projection = {field: 0 for field in exclude_field_list}
|
|
153
|
+
|
|
154
|
+
# 建立查詢條件
|
|
155
|
+
mongo_query = {}
|
|
156
|
+
for q in final_query:
|
|
157
|
+
if hasattr(q, 'query'):
|
|
158
|
+
mongo_query.update(q.query)
|
|
159
|
+
|
|
160
|
+
# 執行查詢
|
|
161
|
+
cursor = collection.find(mongo_query, projection).sort(final_sort)
|
|
162
|
+
documents = await cursor.to_list(None)
|
|
163
|
+
|
|
164
|
+
# 轉換為 Pydantic 模型
|
|
165
|
+
data = []
|
|
166
|
+
for doc in documents:
|
|
167
|
+
try:
|
|
168
|
+
data.append(cls.model_validate(doc))
|
|
169
|
+
except Exception as e:
|
|
170
|
+
print(f"模型驗證失敗: {e}")
|
|
171
|
+
continue
|
|
172
|
+
else:
|
|
173
|
+
# 沒有排除欄位時使用 Beanie 的方法
|
|
174
|
+
data = await cls.find(*final_query, ignore_cache=ignore_cache, fetch_links=fetch_links).sort(
|
|
175
|
+
*final_sort).to_list()
|
|
126
176
|
|
|
127
|
-
data = await query_obj.sort(*final_sort).to_list()
|
|
128
177
|
return data
|
|
129
178
|
|
|
130
179
|
def model_dump(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|