internal 1.1.35.3__py3-none-any.whl → 1.1.36__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 internal might be problematic. Click here for more details.
internal/model/base_model.py
CHANGED
|
@@ -28,7 +28,8 @@ class InternalBaseDocument(Document):
|
|
|
28
28
|
@classmethod
|
|
29
29
|
async def get_pagination_list(cls, app: FastAPI, query: list = None, sort: List[Tuple] = None,
|
|
30
30
|
page_size: int = DEF_PAGE_SIZE, page_no: int = DEF_PAGE_NO,
|
|
31
|
-
ignore_cache: bool = False, fetch_links: bool = False,
|
|
31
|
+
ignore_cache: bool = False, fetch_links: bool = False,
|
|
32
|
+
exclude_field_list: List[str] = None):
|
|
32
33
|
if not query:
|
|
33
34
|
final_query = []
|
|
34
35
|
else:
|
|
@@ -48,22 +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()
|
|
90
|
+
|
|
91
|
+
total_pages = (total_num + page_size - 1) // page_size
|
|
61
92
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
if total_pages == 0:
|
|
94
|
+
page_no = 1
|
|
95
|
+
page_data = []
|
|
96
|
+
else:
|
|
97
|
+
page_no = max(1, min(page_no, total_pages))
|
|
65
98
|
|
|
66
|
-
|
|
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()
|
|
67
101
|
|
|
68
102
|
return page_no, page_size, total_num, page_data
|
|
69
103
|
|
|
@@ -92,7 +126,7 @@ class InternalBaseDocument(Document):
|
|
|
92
126
|
|
|
93
127
|
@classmethod
|
|
94
128
|
async def get_list(cls, app: FastAPI, query: list = None, sort: List[Tuple] = None, ignore_cache: bool = False,
|
|
95
|
-
fetch_links: bool = False,
|
|
129
|
+
fetch_links: bool = False, exclude_field_list: List[str] = None):
|
|
96
130
|
if not query:
|
|
97
131
|
final_query = []
|
|
98
132
|
else:
|
|
@@ -112,11 +146,33 @@ class InternalBaseDocument(Document):
|
|
|
112
146
|
continue
|
|
113
147
|
final_sort.append((cls.id, pymongo.ASCENDING))
|
|
114
148
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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()
|
|
120
176
|
|
|
121
177
|
return data
|
|
122
178
|
|
|
@@ -31,10 +31,10 @@ internal/interface/base_interface.py,sha256=3YaVjIgLi_pZpLk5SEIk8WVkuICM8qPavT8r
|
|
|
31
31
|
internal/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
internal/middleware/log_request.py,sha256=OFwWnGfzXnllcQsBHolAWVsahXKoEhw3OQ1YWOm7RHM,2087
|
|
33
33
|
internal/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
-
internal/model/base_model.py,sha256=
|
|
34
|
+
internal/model/base_model.py,sha256=vZPDpqzH7Eigwdfw1BgCtr40mflpf41M2__-6DyUPpQ,7987
|
|
35
35
|
internal/model/operate.py,sha256=QSM6yXYXpJMwrqkUGEWZLrEBaUgqHwVHY_Fi4S42hKc,3190
|
|
36
36
|
internal/utils.py,sha256=wK1QumW1AaWE1ga2-WcDH2rtXRr2hSLwXzy-iI5dTzY,3962
|
|
37
37
|
internal/validator_utils.py,sha256=CqjaVFoAu5MqvBG_AkTP-r7AliWawtUWB851USj4moI,1519
|
|
38
|
-
internal-1.1.
|
|
39
|
-
internal-1.1.
|
|
40
|
-
internal-1.1.
|
|
38
|
+
internal-1.1.36.dist-info/METADATA,sha256=RuaBTuS0BgSHQSI9ODnMW_JCkXcFCVQLq1pnwCGe4i0,939
|
|
39
|
+
internal-1.1.36.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
|
40
|
+
internal-1.1.36.dist-info/RECORD,,
|
|
File without changes
|