statikk 0.1.2__tar.gz → 0.1.3__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.
- {statikk-0.1.2 → statikk-0.1.3}/PKG-INFO +1 -1
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/models.py +12 -6
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/PKG-INFO +1 -1
- {statikk-0.1.2 → statikk-0.1.3}/tests/test_models.py +4 -4
- {statikk-0.1.2 → statikk-0.1.3}/.coveragerc +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/.gitignore +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/.readthedocs.yml +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/AUTHORS.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/CHANGELOG.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/CONTRIBUTING.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/LICENSE.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/README.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/assets/favicon.png +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/assets/logo.png +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/Makefile +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/_static/.gitignore +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/authors.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/changelog.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/conf.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/contributing.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/index.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/license.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/readme.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/requirements.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/docs/usage.rst +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/pyproject.toml +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/setup.cfg +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/setup.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/__init__.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/conditions.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/engine.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/expressions.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/fields.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk/typing.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/SOURCES.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/dependency_links.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/not-zip-safe +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/requires.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/src/statikk.egg-info/top_level.txt +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/tests/conftest.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/tests/test_engine.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/tests/test_expressions.py +0 -0
- {statikk-0.1.2 → statikk-0.1.3}/tox.ini +0 -0
@@ -56,11 +56,13 @@ class IndexFieldConfig(BaseModel):
|
|
56
56
|
class TrackingMixin:
|
57
57
|
_original_hash: int = Field(exclude=True)
|
58
58
|
|
59
|
-
@
|
60
|
-
def should_track(
|
61
|
-
|
59
|
+
@property
|
60
|
+
def should_track(self) -> bool:
|
61
|
+
if self._parent is not None:
|
62
|
+
return self._parent.should_track
|
63
|
+
return False
|
62
64
|
|
63
|
-
def
|
65
|
+
def init_tracking(self):
|
64
66
|
self._original_hash = self._recursive_hash()
|
65
67
|
|
66
68
|
def _recursive_hash(self) -> int:
|
@@ -72,6 +74,9 @@ class TrackingMixin:
|
|
72
74
|
Returns:
|
73
75
|
A hash value representing the model's non-model fields.
|
74
76
|
"""
|
77
|
+
if not self.should_track:
|
78
|
+
return 0
|
79
|
+
|
75
80
|
values = []
|
76
81
|
for field_name in self.model_fields:
|
77
82
|
if not hasattr(self, field_name):
|
@@ -131,7 +136,7 @@ class TrackingMixin:
|
|
131
136
|
|
132
137
|
@property
|
133
138
|
def was_modified(self) -> bool:
|
134
|
-
if self.should_track
|
139
|
+
if self.should_track:
|
135
140
|
return self._recursive_hash() != self._original_hash
|
136
141
|
|
137
142
|
return True
|
@@ -253,10 +258,10 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
|
|
253
258
|
|
254
259
|
@model_validator(mode="after")
|
255
260
|
def initialize_tracking(self):
|
256
|
-
self._original_hash = self._recursive_hash()
|
257
261
|
self._model_types_in_hierarchy[self.type()] = type(self)
|
258
262
|
if not self.is_nested():
|
259
263
|
self._set_parent_references(self)
|
264
|
+
self.init_tracking()
|
260
265
|
|
261
266
|
return self
|
262
267
|
|
@@ -351,6 +356,7 @@ class DatabaseModel(BaseModel, TrackingMixin, extra=Extra.allow):
|
|
351
356
|
field._parent = parent
|
352
357
|
root._model_types_in_hierarchy[field.type()] = type(field)
|
353
358
|
field._set_parent_references(root)
|
359
|
+
field.init_tracking()
|
354
360
|
|
355
361
|
def _set_parent_references(self, root: DatabaseModel):
|
356
362
|
for field_name, field_value in self:
|
@@ -28,6 +28,10 @@ class MyDatabaseModel(DatabaseModel):
|
|
28
28
|
foo: str
|
29
29
|
nested: MyNestedDatabaseModel
|
30
30
|
|
31
|
+
@property
|
32
|
+
def should_track(self) -> bool:
|
33
|
+
return True
|
34
|
+
|
31
35
|
|
32
36
|
class MyDatabaseModelWithList(DatabaseModel):
|
33
37
|
foo: str
|
@@ -98,10 +102,6 @@ def test_tracking_disabled():
|
|
98
102
|
foo: str = "foo"
|
99
103
|
bar: str = "bar"
|
100
104
|
|
101
|
-
@classmethod
|
102
|
-
def should_track(cls) -> bool:
|
103
|
-
return False
|
104
|
-
|
105
105
|
my_database_model = MyDatabaseModel(foo="foo", bar="bar")
|
106
106
|
assert my_database_model.was_modified is True # untracked models should always be marked as modified
|
107
107
|
my_database_model.foo = "bar"
|
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
|