TypeDAL 3.15.5__tar.gz → 3.16.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.
Potentially problematic release.
This version of TypeDAL might be problematic. Click here for more details.
- {typedal-3.15.5 → typedal-3.16.0}/CHANGELOG.md +6 -0
- {typedal-3.15.5 → typedal-3.16.0}/PKG-INFO +1 -1
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/__about__.py +1 -1
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/core.py +40 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_main.py +31 -2
- {typedal-3.15.5 → typedal-3.16.0}/.github/workflows/su6.yml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/.gitignore +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/.readthedocs.yml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/README.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/coverage.svg +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/1_getting_started.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/2_defining_tables.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/3_building_queries.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/4_relationships.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/5_py4web.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/6_migrations.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/7_mixins.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/css/code_blocks.css +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/index.md +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/docs/requirements.txt +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/example_new.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/example_old.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/mkdocs.yml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/pyproject.toml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/__init__.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/caching.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/cli.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/config.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/fields.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/for_py4web.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/for_web2py.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/helpers.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/mixins.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/py.typed +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/serializers/as_json.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/types.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/src/typedal/web2py_py4web_shared.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/__init__.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/configs/simple.toml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/configs/valid.env +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/configs/valid.toml +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_cli.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_config.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_docs_examples.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_helpers.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_json.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_mixins.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_mypy.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_orm.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_py4web.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_query_builder.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_relationships.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_row.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_stats.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_table.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_web2py.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/test_xx_others.py +0 -0
- {typedal-3.15.5 → typedal-3.16.0}/tests/timings.py +0 -0
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<!--next-version-placeholder-->
|
|
4
4
|
|
|
5
|
+
## v3.16.0 (2025-09-01)
|
|
6
|
+
|
|
7
|
+
### Feature
|
|
8
|
+
|
|
9
|
+
* Allow reordering table fields via `Table.reorder_fields(...)` ([`79c2c3e`](https://github.com/trialandsuccess/TypeDAL/commit/79c2c3eaf8b44919800e4c12026ab54a2678d141))
|
|
10
|
+
|
|
5
11
|
## v3.15.5 (2025-08-29)
|
|
6
12
|
|
|
7
13
|
### Fix
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Core functionality of TypeDAL.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
5
7
|
import contextlib
|
|
6
8
|
import csv
|
|
7
9
|
import datetime as dt
|
|
@@ -826,6 +828,31 @@ P = typing.ParamSpec("P")
|
|
|
826
828
|
R = typing.TypeVar("R")
|
|
827
829
|
|
|
828
830
|
|
|
831
|
+
def reorder_fields(
|
|
832
|
+
table: pydal.objects.Table, fields: list[str | Field | TypedField], keep_others: bool = True
|
|
833
|
+
) -> None:
|
|
834
|
+
"""
|
|
835
|
+
Reorder fields of a pydal table.
|
|
836
|
+
|
|
837
|
+
Args:
|
|
838
|
+
table: The pydal table object (e.g., db.mytable).
|
|
839
|
+
fields: List of field names (str) or Field objects in desired order.
|
|
840
|
+
keep_others (bool):
|
|
841
|
+
- True (default): keep other fields at the end, in their original order.
|
|
842
|
+
- False: remove other fields (only keep what's specified).
|
|
843
|
+
"""
|
|
844
|
+
# Normalize input to field names
|
|
845
|
+
desired = [f.name if isinstance(f, (TypedField, Field, pydal.objects.Field)) else str(f) for f in fields]
|
|
846
|
+
|
|
847
|
+
new_order = [f for f in desired if f in table._fields]
|
|
848
|
+
|
|
849
|
+
if keep_others:
|
|
850
|
+
# Start with desired fields, then append the rest
|
|
851
|
+
new_order.extend(f for f in table._fields if f not in desired)
|
|
852
|
+
|
|
853
|
+
table._fields = new_order
|
|
854
|
+
|
|
855
|
+
|
|
829
856
|
class TableMeta(type):
|
|
830
857
|
"""
|
|
831
858
|
This metaclass contains functionality on table classes, that doesn't exist on its instances.
|
|
@@ -1367,6 +1394,19 @@ class TableMeta(type):
|
|
|
1367
1394
|
"""
|
|
1368
1395
|
return cls._hook_once(cls._after_delete, fn)
|
|
1369
1396
|
|
|
1397
|
+
def reorder_fields(cls, fields: list[str | Field | TypedField], keep_others: bool = True):
|
|
1398
|
+
"""
|
|
1399
|
+
Reorder fields of a typedal table.
|
|
1400
|
+
|
|
1401
|
+
Args:
|
|
1402
|
+
fields: List of field names (str) or Field objects in desired order.
|
|
1403
|
+
keep_others (bool):
|
|
1404
|
+
- True (default): keep other fields at the end, in their original order.
|
|
1405
|
+
- False: remove other fields (only keep what's specified).
|
|
1406
|
+
"""
|
|
1407
|
+
|
|
1408
|
+
return reorder_fields(cls._table, fields, keep_others=keep_others)
|
|
1409
|
+
|
|
1370
1410
|
|
|
1371
1411
|
class TypedField(Expression, typing.Generic[T_Value]): # pragma: no cover
|
|
1372
1412
|
"""
|
|
@@ -115,11 +115,19 @@ def test_mixed_defines(capsys):
|
|
|
115
115
|
## insert normal
|
|
116
116
|
db.old_syntax.insert(name="First", age=99, location="Norway", relation=db.relation(id=1))
|
|
117
117
|
db.first_new_syntax.insert(
|
|
118
|
-
name="First",
|
|
118
|
+
name="First",
|
|
119
|
+
age=99,
|
|
120
|
+
location="Norway",
|
|
121
|
+
old_relation=db.relation(id=1),
|
|
122
|
+
tags=["first", "second"],
|
|
119
123
|
)
|
|
120
124
|
# equals
|
|
121
125
|
FirstNewSyntax.insert(
|
|
122
|
-
name="First",
|
|
126
|
+
name="First",
|
|
127
|
+
age=99,
|
|
128
|
+
location="Norway",
|
|
129
|
+
old_relation=db.relation(id=1),
|
|
130
|
+
tags=["first", "second"],
|
|
123
131
|
)
|
|
124
132
|
# similar
|
|
125
133
|
SecondNewSyntax.insert(
|
|
@@ -570,3 +578,24 @@ def test_try():
|
|
|
570
578
|
|
|
571
579
|
with pytest.warns(RuntimeWarning):
|
|
572
580
|
assert db.try_define(SomeTableToRetry, verbose=True)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
def test_reorder_fields():
|
|
584
|
+
@db.define()
|
|
585
|
+
class Base(TypedTable):
|
|
586
|
+
gid: str
|
|
587
|
+
|
|
588
|
+
@db.define()
|
|
589
|
+
class Sub(Base):
|
|
590
|
+
name: str
|
|
591
|
+
|
|
592
|
+
# default order is kinda cursed due to MRO:
|
|
593
|
+
assert list(Sub) == [Sub.id, Sub.name, Sub.gid]
|
|
594
|
+
|
|
595
|
+
# 'name' should come last:
|
|
596
|
+
Sub.reorder_fields([Sub.id, Sub.gid])
|
|
597
|
+
assert list(Sub) == [Sub.id, Sub.gid, Sub.name]
|
|
598
|
+
|
|
599
|
+
# 'name' should be dropped:
|
|
600
|
+
Sub.reorder_fields([Sub.id, Sub.gid], keep_others=False)
|
|
601
|
+
assert list(Sub) == [Sub.id, Sub.gid]
|
|
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
|
|
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
|