dplex 0.2.8__tar.gz → 0.3.0__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.
- {dplex-0.2.8 → dplex-0.3.0}/PKG-INFO +1 -1
- {dplex-0.2.8 → dplex-0.3.0}/dplex/dp_filters.py +14 -4
- {dplex-0.2.8 → dplex-0.3.0}/dplex/dp_service.py +7 -5
- {dplex-0.2.8 → dplex-0.3.0}/dplex/internal/sort.py +3 -2
- {dplex-0.2.8 → dplex-0.3.0}/pyproject.toml +1 -1
- {dplex-0.2.8 → dplex-0.3.0}/LICENSE +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/README.md +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/__init__.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/dp_repo.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/internal/filter_applier.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/internal/filters.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/internal/query_builder.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/internal/types.py +0 -0
- {dplex-0.2.8 → dplex-0.3.0}/dplex/py.typed +0 -0
|
@@ -235,12 +235,17 @@ class DPFilters[SortFieldType](BaseModel):
|
|
|
235
235
|
|
|
236
236
|
def has_sort(self) -> bool:
|
|
237
237
|
"""
|
|
238
|
-
Проверить, установлены ли параметры
|
|
238
|
+
Проверить, установлены ли параметры сортировки.
|
|
239
239
|
|
|
240
240
|
Returns:
|
|
241
|
-
True если
|
|
241
|
+
True если есть хотя бы одно правило Sort с заданным полем (by is not None), иначе False.
|
|
242
|
+
Sort(by=None) не считается активной сортировкой.
|
|
242
243
|
"""
|
|
243
|
-
|
|
244
|
+
if self.sort is None:
|
|
245
|
+
return False
|
|
246
|
+
if isinstance(self.sort, list):
|
|
247
|
+
return any(s.by is not None for s in self.sort)
|
|
248
|
+
return self.sort.by is not None
|
|
244
249
|
|
|
245
250
|
def __repr__(self) -> str:
|
|
246
251
|
"""
|
|
@@ -299,7 +304,12 @@ class DPFilters[SortFieldType](BaseModel):
|
|
|
299
304
|
parts.append(f"{count} active filters")
|
|
300
305
|
|
|
301
306
|
if self.has_sort():
|
|
302
|
-
|
|
307
|
+
if isinstance(self.sort, list):
|
|
308
|
+
items = self.sort
|
|
309
|
+
else:
|
|
310
|
+
assert self.sort is not None # has_sort() guarantees this
|
|
311
|
+
items = [self.sort]
|
|
312
|
+
sort_count = len([s for s in items if s.by is not None])
|
|
303
313
|
parts.append(f"{sort_count} sort rule(s)")
|
|
304
314
|
|
|
305
315
|
if self.has_pagination():
|
|
@@ -276,17 +276,17 @@ class DPService[
|
|
|
276
276
|
sort: list[Sort[SortFieldSchemaType]] | Sort[SortFieldSchemaType] | None,
|
|
277
277
|
) -> list[Sort[SortFieldSchemaType]]:
|
|
278
278
|
"""
|
|
279
|
-
Нормализовать сортировку в
|
|
279
|
+
Нормализовать сортировку в список.
|
|
280
|
+
Элементы Sort с by=None отфильтровываются — сортировка по ним не применяется.
|
|
280
281
|
Args:
|
|
281
282
|
sort: Один элемент Sort, список Sort или None
|
|
282
283
|
Returns:
|
|
283
|
-
Список элементов сортировки (может быть пустым)
|
|
284
|
+
Список элементов сортировки с заданным полем (может быть пустым)
|
|
284
285
|
"""
|
|
285
286
|
if sort is None:
|
|
286
287
|
return []
|
|
287
|
-
if isinstance(sort, list)
|
|
288
|
-
|
|
289
|
-
return [sort]
|
|
288
|
+
items = sort if isinstance(sort, list) else [sort]
|
|
289
|
+
return [s for s in items if s.by is not None]
|
|
290
290
|
|
|
291
291
|
def _apply_sort_to_query(
|
|
292
292
|
self,
|
|
@@ -302,6 +302,8 @@ class DPService[
|
|
|
302
302
|
QueryBuilder с примененной сортировкой
|
|
303
303
|
"""
|
|
304
304
|
for sort_item in sort_list:
|
|
305
|
+
if sort_item.by is None:
|
|
306
|
+
continue
|
|
305
307
|
column_name = self._sort_field_to_column_name(sort_item.by)
|
|
306
308
|
column = self._get_model_column(column_name)
|
|
307
309
|
desc_order = sort_item.order == Order.DESC
|
|
@@ -65,7 +65,7 @@ class Sort[SortByType]:
|
|
|
65
65
|
SortByType: Тип поля для сортировки (обычно str или Enum)
|
|
66
66
|
|
|
67
67
|
Attributes:
|
|
68
|
-
by: Поле для
|
|
68
|
+
by: Поле для сортировки; если None — сортировка не применяется (удобно для запросов с опциональным sort_by)
|
|
69
69
|
order: Направление сортировки (по умолчанию ASC)
|
|
70
70
|
nulls: Размещение NULL значений (по умолчанию None - поведение СУБД)
|
|
71
71
|
|
|
@@ -73,8 +73,9 @@ class Sort[SortByType]:
|
|
|
73
73
|
Notes:
|
|
74
74
|
- Класс immutable (frozen=True) для безопасного использования в хешируемых структурах
|
|
75
75
|
- Параметр nulls опционален - если None, используется поведение СУБД по умолчанию
|
|
76
|
+
- При by=None правило сортировки игнорируется (можно передавать Sort(by=request.sort_by, order=...) при опциональном sort_by)
|
|
76
77
|
"""
|
|
77
78
|
|
|
78
|
-
by: SortByType
|
|
79
|
+
by: SortByType | None = None
|
|
79
80
|
order: Order = Order.ASC
|
|
80
81
|
nulls: NullsPlacement | None = None
|
|
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
|