f3-data-models 0.3.4__py3-none-any.whl → 0.3.6__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.
- f3_data_models/models.py +8 -8
- f3_data_models/utils.py +56 -14
- {f3_data_models-0.3.4.dist-info → f3_data_models-0.3.6.dist-info}/METADATA +1 -1
- f3_data_models-0.3.6.dist-info/RECORD +6 -0
- {f3_data_models-0.3.4.dist-info → f3_data_models-0.3.6.dist-info}/WHEEL +1 -1
- f3_data_models-0.3.4.dist-info/RECORD +0 -6
f3_data_models/models.py
CHANGED
@@ -566,8 +566,8 @@ class Event(Base):
|
|
566
566
|
highlight (bool): Whether the event is highlighted. Default is False.
|
567
567
|
start_date (date): The start date of the event.
|
568
568
|
end_date (Optional[date]): The end date of the event.
|
569
|
-
start_time (Optional[
|
570
|
-
end_time (Optional[
|
569
|
+
start_time (Optional[str]): The start time of the event. Format is 'HHMM', 24-hour time, timezone naive.
|
570
|
+
end_time (Optional[str]): The end time of the event. Format is 'HHMM', 24-hour time, timezone naive.
|
571
571
|
day_of_week (Optional[Day_Of_Week]): The day of the week of the event.
|
572
572
|
name (str): The name of the event.
|
573
573
|
description (Optional[text]): A description of the event.
|
@@ -606,8 +606,8 @@ class Event(Base):
|
|
606
606
|
highlight: Mapped[bool] = mapped_column(Boolean, default=False)
|
607
607
|
start_date: Mapped[date]
|
608
608
|
end_date: Mapped[Optional[date]]
|
609
|
-
start_time: Mapped[Optional[
|
610
|
-
end_time: Mapped[Optional[
|
609
|
+
start_time: Mapped[Optional[str]]
|
610
|
+
end_time: Mapped[Optional[str]]
|
611
611
|
day_of_week: Mapped[Optional[Day_Of_Week]]
|
612
612
|
name: Mapped[str]
|
613
613
|
description: Mapped[Optional[text]]
|
@@ -1066,8 +1066,8 @@ class UpdateRequest(Base):
|
|
1066
1066
|
event_highlight (Optional[bool]): Whether the event is highlighted.
|
1067
1067
|
event_start_date (Optional[date]): The start date of the event.
|
1068
1068
|
event_end_date (Optional[date]): The end date of the event.
|
1069
|
-
event_start_time (Optional[
|
1070
|
-
event_end_time (Optional[
|
1069
|
+
event_start_time (Optional[str]): The start time of the event. Format is 'HHMM', 24-hour time, timezone naive.
|
1070
|
+
event_end_time (Optional[str]): The end time of the event. Format is 'HHMM', 24-hour time, timezone naive.
|
1071
1071
|
event_day_of_week (Optional[Day_Of_Week]): The day of the week of the event.
|
1072
1072
|
event_name (str): The name of the event.
|
1073
1073
|
event_description (Optional[text]): A description of the event.
|
@@ -1113,8 +1113,8 @@ class UpdateRequest(Base):
|
|
1113
1113
|
event_highlight: Mapped[Optional[bool]]
|
1114
1114
|
event_start_date: Mapped[Optional[date]]
|
1115
1115
|
event_end_date: Mapped[Optional[date]]
|
1116
|
-
event_start_time: Mapped[Optional[
|
1117
|
-
event_end_time: Mapped[Optional[
|
1116
|
+
event_start_time: Mapped[Optional[str]]
|
1117
|
+
event_end_time: Mapped[Optional[str]]
|
1118
1118
|
event_day_of_week: Mapped[Optional[Day_Of_Week]]
|
1119
1119
|
event_name: Mapped[str]
|
1120
1120
|
event_description: Mapped[Optional[text]]
|
f3_data_models/utils.py
CHANGED
@@ -3,11 +3,13 @@ from dataclasses import dataclass
|
|
3
3
|
from typing import List, Optional, Tuple, TypeVar
|
4
4
|
|
5
5
|
import sqlalchemy
|
6
|
-
from sqlalchemy import Select, and_, select
|
6
|
+
from sqlalchemy import Select, and_, select, inspect
|
7
7
|
|
8
8
|
from sqlalchemy.dialects.postgresql import insert
|
9
9
|
from sqlalchemy.engine import Engine
|
10
10
|
from sqlalchemy.orm import sessionmaker, joinedload
|
11
|
+
from sqlalchemy.orm.collections import InstrumentedList
|
12
|
+
from sqlalchemy.orm.attributes import flag_modified
|
11
13
|
|
12
14
|
from f3_data_models.models import Base
|
13
15
|
|
@@ -166,21 +168,61 @@ class DbManager:
|
|
166
168
|
|
167
169
|
def update_record(cls: T, id, fields):
|
168
170
|
session = get_session()
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
)
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
171
|
+
# Fetch the object to be updated
|
172
|
+
obj = session.query(cls).get(id)
|
173
|
+
if not obj:
|
174
|
+
raise ValueError(f"Object with id {id} not found")
|
175
|
+
|
176
|
+
# Get the list of valid attributes for the class
|
177
|
+
valid_attributes = {attr.key for attr in inspect(cls).mapper.column_attrs}
|
178
|
+
valid_relationships = {rel.key for rel in inspect(cls).mapper.relationships}
|
179
|
+
|
180
|
+
# Update simple fields
|
181
|
+
for key, value in fields.items():
|
182
|
+
if key in valid_attributes and not isinstance(value, InstrumentedList):
|
183
|
+
setattr(obj, key, value)
|
184
|
+
|
185
|
+
# Update relationships
|
186
|
+
for key, value in fields.items():
|
187
|
+
if key in valid_relationships and isinstance(value, InstrumentedList):
|
188
|
+
related_objects = getattr(obj, key)
|
189
|
+
related_objects.clear()
|
190
|
+
related_objects.extend(value)
|
191
|
+
|
192
|
+
# Flag the object as modified to ensure changes are detected
|
193
|
+
flag_modified(obj, key)
|
194
|
+
|
195
|
+
# Commit the changes
|
196
|
+
session.commit()
|
197
|
+
|
198
|
+
def update_records(cls, filters, fields):
|
179
199
|
session = get_session()
|
180
200
|
try:
|
181
|
-
|
182
|
-
|
183
|
-
|
201
|
+
# Fetch the objects to be updated
|
202
|
+
objects = session.query(cls).filter(and_(*filters)).all()
|
203
|
+
|
204
|
+
# Get the list of valid attributes for the class
|
205
|
+
valid_attributes = {attr.key for attr in inspect(cls).mapper.column_attrs}
|
206
|
+
valid_relationships = {rel.key for rel in inspect(cls).mapper.relationships}
|
207
|
+
|
208
|
+
for obj in objects:
|
209
|
+
# Update simple fields
|
210
|
+
for key, value in fields.items():
|
211
|
+
if key in valid_attributes and not isinstance(
|
212
|
+
value, InstrumentedList
|
213
|
+
):
|
214
|
+
setattr(obj, key, value)
|
215
|
+
|
216
|
+
# Update relationships
|
217
|
+
for key, value in fields.items():
|
218
|
+
if key in valid_relationships and isinstance(
|
219
|
+
value, InstrumentedList
|
220
|
+
):
|
221
|
+
related_objects = getattr(obj, key)
|
222
|
+
related_objects.clear()
|
223
|
+
related_objects.extend(value)
|
224
|
+
flag_modified(obj, key)
|
225
|
+
|
184
226
|
session.flush()
|
185
227
|
finally:
|
186
228
|
session.commit()
|
@@ -0,0 +1,6 @@
|
|
1
|
+
f3_data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
f3_data_models/models.py,sha256=SLOXwM2BMnlGTwkVZfG3fM9hoksvPkcFRqzpEI4bm2Y,44293
|
3
|
+
f3_data_models/utils.py,sha256=fGv-qHviSsUqHmYElBvYgWbqX5LAlTJCoKSMIqd8ioA,10738
|
4
|
+
f3_data_models-0.3.6.dist-info/METADATA,sha256=G6dtENVh5a3JKZ4NdCl3DVY6dTybhdEl5jLvQmKnFHY,2716
|
5
|
+
f3_data_models-0.3.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
6
|
+
f3_data_models-0.3.6.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
f3_data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
f3_data_models/models.py,sha256=D69gDYemd_FizWzsNIixbIi3GbynaOQNaFqnN528ewA,44155
|
3
|
-
f3_data_models/utils.py,sha256=1hdZ2tvMiNibNZvwt0dx4PhPCw_pJGg1mG2cCvwc6CI,8857
|
4
|
-
f3_data_models-0.3.4.dist-info/METADATA,sha256=1LRVeZ8juPzvBJ3VffsuD86h878FM4gi4FnDnTJpnJo,2716
|
5
|
-
f3_data_models-0.3.4.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
6
|
-
f3_data_models-0.3.4.dist-info/RECORD,,
|