f3-data-models 0.1.8__py3-none-any.whl → 0.1.11__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 CHANGED
@@ -6,11 +6,9 @@ from sqlalchemy import (
6
6
  TIME,
7
7
  VARCHAR,
8
8
  Boolean,
9
- Column,
10
9
  DateTime,
11
10
  ForeignKey,
12
11
  Integer,
13
- Table,
14
12
  func,
15
13
  UniqueConstraint,
16
14
  )
@@ -259,30 +257,6 @@ class Role_x_User_x_Org(Base):
259
257
  org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
260
258
 
261
259
 
262
- event_type_x_org_table = Table(
263
- "event_types_x_org",
264
- Base.metadata,
265
- Column("event_type_id", Integer, ForeignKey("event_types.id"), primary_key=True),
266
- Column("org_id", Integer, ForeignKey("orgs.id"), primary_key=True),
267
- Column("is_default", Boolean, default=False, nullable=False),
268
- )
269
-
270
- event_tag_x_org_table = Table(
271
- "event_tags_x_org",
272
- Base.metadata,
273
- Column("event_tag_id", Integer, ForeignKey("event_tags.id"), primary_key=True),
274
- Column("org_id", Integer, ForeignKey("orgs.id"), primary_key=True),
275
- Column("color_override", VARCHAR),
276
- )
277
-
278
- achievement_x_org_table = Table(
279
- "achievements_x_org",
280
- Base.metadata,
281
- Column("achievement_id", Integer, ForeignKey("achievements.id"), primary_key=True),
282
- Column("org_id", Integer, ForeignKey("orgs.id"), primary_key=True),
283
- )
284
-
285
-
286
260
  class Org(Base):
287
261
  """
288
262
  Model representing an organization. The same model is used for all levels of organization (AOs, Regions, etc.).
@@ -305,6 +279,11 @@ class Org(Base):
305
279
  meta (Optional[Dict[str, Any]]): Additional metadata for the organization.
306
280
  created (datetime): The timestamp when the record was created.
307
281
  updated (datetime): The timestamp when the record was last updated.
282
+
283
+ event_types (Optional[List[EventType]]): The event types associated with the organization. Used to control which event types are available for selection at the region level.
284
+ event_tags (Optional[List[EventTag]]): The event tags associated with the organization. Used to control which event tags are available for selection at the region level.
285
+ achievements (Optional[List[Achievement]]): The achievements available within the organization.
286
+ parent_org (Optional[Org]): The parent organization.
308
287
  """
309
288
 
310
289
  __tablename__ = "orgs"
@@ -328,13 +307,13 @@ class Org(Base):
328
307
  updated: Mapped[dt_update]
329
308
 
330
309
  event_types: Mapped[Optional[List["EventType"]]] = relationship(
331
- "EventType", secondary=event_type_x_org_table, cascade="expunge"
310
+ "EventType", secondary="event_types_x_org", cascade="expunge"
332
311
  )
333
312
  event_tags: Mapped[Optional[List["EventTag"]]] = relationship(
334
- "EventTag", secondary=event_tag_x_org_table, cascade="expunge"
313
+ "EventTag", secondary="event_tags_x_org", cascade="expunge"
335
314
  )
336
315
  achievements: Mapped[Optional[List["Achievement"]]] = relationship(
337
- "Achievement", secondary=achievement_x_org_table, cascade="expunge"
316
+ "Achievement", secondary="achievements_x_org", cascade="expunge"
338
317
  )
339
318
  parent_org: Mapped[Optional["Org"]] = relationship(
340
319
  "Org", remote_side=[id], cascade="expunge"
@@ -366,40 +345,44 @@ class EventType(Base):
366
345
  updated: Mapped[dt_update]
367
346
 
368
347
 
369
- # class EventType_x_Event(Base):
370
- # """
371
- # Model representing the association between events and event types. The intention is that a single event can be associated with multiple event types.
348
+ class EventType_x_Event(Base):
349
+ """
350
+ Model representing the association between events and event types. The intention is that a single event can be associated with multiple event types.
372
351
 
373
- # Attributes:
374
- # event_id (int): The ID of the associated event.
375
- # event_type_id (int): The ID of the associated event type.
376
- # """
352
+ Attributes:
353
+ event_id (int): The ID of the associated event.
354
+ event_type_id (int): The ID of the associated event type.
377
355
 
378
- # __tablename__ = "events_x_event_types"
356
+ event (Event): The associated event.
357
+ """
379
358
 
380
- # event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True)
381
- # event_type_id: Mapped[int] = mapped_column(
382
- # ForeignKey("event_types.id"), primary_key=True
383
- # )
359
+ __tablename__ = "events_x_event_types"
384
360
 
361
+ event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True)
362
+ event_type_id: Mapped[int] = mapped_column(
363
+ ForeignKey("event_types.id"), primary_key=True
364
+ )
385
365
 
386
- # class EventType_x_Org(Base):
387
- # """
388
- # Model representing the association between event types and organizations. This controls which event types are available for selection at the region level, as well as default types for each AO.
366
+ event: Mapped["Event"] = relationship(back_populates="event_x_event_types")
389
367
 
390
- # Attributes:
391
- # event_type_id (int): The ID of the associated event type.
392
- # org_id (int): The ID of the associated organization.
393
- # is_default (bool): Whether this is the default event type for the organization. Default is False.
394
- # """
395
368
 
396
- # __tablename__ = "event_types_x_org"
369
+ class EventType_x_Org(Base):
370
+ """
371
+ Model representing the association between event types and organizations. This controls which event types are available for selection at the region level, as well as default types for each AO.
397
372
 
398
- # event_type_id: Mapped[int] = mapped_column(
399
- # ForeignKey("event_types.id"), primary_key=True
400
- # )
401
- # org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
402
- # is_default: Mapped[bool] = mapped_column(Boolean, default=False)
373
+ Attributes:
374
+ event_type_id (int): The ID of the associated event type.
375
+ org_id (int): The ID of the associated organization.
376
+ is_default (bool): Whether this is the default event type for the organization. Default is False.
377
+ """
378
+
379
+ __tablename__ = "event_types_x_org"
380
+
381
+ event_type_id: Mapped[int] = mapped_column(
382
+ ForeignKey("event_types.id"), primary_key=True
383
+ )
384
+ org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
385
+ is_default: Mapped[bool] = mapped_column(Boolean, default=False)
403
386
 
404
387
 
405
388
  class EventTag(Base):
@@ -425,40 +408,44 @@ class EventTag(Base):
425
408
  updated: Mapped[dt_update]
426
409
 
427
410
 
428
- # class EventTag_x_Event(Base):
429
- # """
430
- # Model representing the association between event tags and events. The intention is that a single event can be associated with multiple event tags.
411
+ class EventTag_x_Event(Base):
412
+ """
413
+ Model representing the association between event tags and events. The intention is that a single event can be associated with multiple event tags.
431
414
 
432
- # Attributes:
433
- # event_id (int): The ID of the associated event.
434
- # event_tag_id (int): The ID of the associated event tag.
435
- # """
415
+ Attributes:
416
+ event_id (int): The ID of the associated event.
417
+ event_tag_id (int): The ID of the associated event tag.
436
418
 
437
- # __tablename__ = "event_tags_x_events"
419
+ event (Event): The associated event.
420
+ """
438
421
 
439
- # event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True)
440
- # event_tag_id: Mapped[int] = mapped_column(
441
- # ForeignKey("event_tags.id"), primary_key=True
442
- # )
422
+ __tablename__ = "event_tags_x_events"
443
423
 
424
+ event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True)
425
+ event_tag_id: Mapped[int] = mapped_column(
426
+ ForeignKey("event_tags.id"), primary_key=True
427
+ )
444
428
 
445
- # class EventTag_x_Org(Base):
446
- # """
447
- # Model representing the association between event tags and organizations. Controls which event tags are available for selection at the region level.
429
+ event: Mapped["Event"] = relationship(back_populates="event_x_event_tags")
448
430
 
449
- # Attributes:
450
- # event_tag_id (int): The ID of the associated event tag.
451
- # org_id (int): The ID of the associated organization.
452
- # color_override (Optional[str]): The calendar color override for the event tag (if the region wants to use something other than the default).
453
- # """
454
431
 
455
- # __tablename__ = "event_tags_x_org"
432
+ class EventTag_x_Org(Base):
433
+ """
434
+ Model representing the association between event tags and organizations. Controls which event tags are available for selection at the region level.
456
435
 
457
- # event_tag_id: Mapped[int] = mapped_column(
458
- # ForeignKey("event_tags.id"), primary_key=True
459
- # )
460
- # org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
461
- # color_override: Mapped[Optional[str]]
436
+ Attributes:
437
+ event_tag_id (int): The ID of the associated event tag.
438
+ org_id (int): The ID of the associated organization.
439
+ color_override (Optional[str]): The calendar color override for the event tag (if the region wants to use something other than the default).
440
+ """
441
+
442
+ __tablename__ = "event_tags_x_org"
443
+
444
+ event_tag_id: Mapped[int] = mapped_column(
445
+ ForeignKey("event_tags.id"), primary_key=True
446
+ )
447
+ org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
448
+ color_override: Mapped[Optional[str]]
462
449
 
463
450
 
464
451
  class Org_x_SlackSpace(Base):
@@ -519,21 +506,6 @@ class Location(Base):
519
506
  updated: Mapped[dt_update]
520
507
 
521
508
 
522
- event_x_event_type_table = Table(
523
- "events_x_event_types",
524
- Base.metadata,
525
- Column("event_id", Integer, ForeignKey("events.id"), primary_key=True),
526
- Column("event_type_id", Integer, ForeignKey("event_types.id"), primary_key=True),
527
- )
528
-
529
- event_x_event_tag_table = Table(
530
- "event_tags_x_events",
531
- Base.metadata,
532
- Column("event_id", Integer, ForeignKey("events.id"), primary_key=True),
533
- Column("event_tag_id", Integer, ForeignKey("event_tags.id"), primary_key=True),
534
- )
535
-
536
-
537
509
  class Event(Base):
538
510
  """
539
511
  Model representing an event or series; the same model is used for both with a self-referential relationship for series.
@@ -567,6 +539,13 @@ class Event(Base):
567
539
  meta (Optional[Dict[str, Any]]): Additional metadata for the event.
568
540
  created (datetime): The timestamp when the record was created.
569
541
  updated (datetime): The timestamp when the record was last updated.
542
+
543
+ org (Org): The associated organization.
544
+ location (Location): The associated location.
545
+ event_types (List[EventType]): The associated event types.
546
+ event_tags (Optional[List[EventTag]]): The associated event tags.
547
+ event_x_event_types (List[EventType_x_Event]): The association between the event and event types.
548
+ event_x_event_tags (Optional[List[EventTag_x_Event]]): The association between the event and event tags.
570
549
  """
571
550
 
572
551
  __tablename__ = "events"
@@ -600,13 +579,24 @@ class Event(Base):
600
579
  created: Mapped[dt_create]
601
580
  updated: Mapped[dt_update]
602
581
 
603
- org: Mapped[Org] = relationship(innerjoin=True, cascade="expunge")
604
- location: Mapped[Location] = relationship(innerjoin=True, cascade="expunge")
582
+ org: Mapped[Org] = relationship(innerjoin=True, cascade="expunge", viewonly=True)
583
+ location: Mapped[Location] = relationship(
584
+ innerjoin=True, cascade="expunge", viewonly=True
585
+ )
605
586
  event_types: Mapped[List[EventType]] = relationship(
606
- secondary=event_x_event_type_table, innerjoin=True, cascade="expunge"
587
+ secondary="events_x_event_types",
588
+ innerjoin=True,
589
+ cascade="expunge",
590
+ viewonly=True,
607
591
  )
608
592
  event_tags: Mapped[Optional[List[EventTag]]] = relationship(
609
- secondary=event_x_event_tag_table, cascade="expunge"
593
+ secondary="event_tags_x_events", cascade="expunge", viewonly=True
594
+ )
595
+ event_x_event_types: Mapped[List[EventType_x_Event]] = relationship(
596
+ back_populates="event"
597
+ )
598
+ event_x_event_tags: Mapped[Optional[List[EventTag_x_Event]]] = relationship(
599
+ back_populates="event"
610
600
  )
611
601
 
612
602
 
@@ -628,39 +618,15 @@ class AttendanceType(Base):
628
618
  updated: Mapped[dt_update]
629
619
 
630
620
 
631
- class Attendance(Base):
632
- """
633
- Model representing an attendance record.
634
-
635
- Attributes:
636
- id (int): Primary Key of the model.
637
- event_id (int): The ID of the associated event.
638
- user_id (Optional[int]): The ID of the associated user.
639
- is_planned (bool): Whether this is planned attendance (True) vs actual attendance (False).
640
- meta (Optional[Dict[str, Any]]): Additional metadata for the attendance.
641
- created (datetime): The timestamp when the record was created.
642
- updated (datetime): The timestamp when the record was last updated.
643
- """
644
-
645
- __tablename__ = "attendance"
646
- __table_args__ = (UniqueConstraint("event_id", "user_id", "is_planned"),)
647
-
648
- id: Mapped[intpk]
649
- event_id: Mapped[int] = mapped_column(ForeignKey("events.id"))
650
- user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
651
- is_planned: Mapped[bool]
652
- meta: Mapped[Optional[Dict[str, Any]]]
653
- created: Mapped[dt_create]
654
- updated: Mapped[dt_update]
655
-
656
-
657
- class Attendance_x_AttenanceType(Base):
621
+ class Attendance_x_AttendanceType(Base):
658
622
  """
659
623
  Model representing the association between attendance and attendance types.
660
624
 
661
625
  Attributes:
662
626
  attendance_id (int): The ID of the associated attendance.
663
627
  attendance_type_id (int): The ID of the associated attendance type.
628
+
629
+ attendance (Attendance): The associated attendance.
664
630
  """
665
631
 
666
632
  __tablename__ = "attendance_x_attendance_types"
@@ -672,6 +638,10 @@ class Attendance_x_AttenanceType(Base):
672
638
  ForeignKey("attendance_types.id"), primary_key=True
673
639
  )
674
640
 
641
+ attendance: Mapped["Attendance"] = relationship(
642
+ back_populates="attendance_x_attendance_types"
643
+ )
644
+
675
645
 
676
646
  class User(Base):
677
647
  """
@@ -756,6 +726,55 @@ class SlackUser(Base):
756
726
  updated: Mapped[dt_update]
757
727
 
758
728
 
729
+ class Attendance(Base):
730
+ """
731
+ Model representing an attendance record.
732
+
733
+ Attributes:
734
+ id (int): Primary Key of the model.
735
+ event_id (int): The ID of the associated event.
736
+ user_id (Optional[int]): The ID of the associated user.
737
+ is_planned (bool): Whether this is planned attendance (True) vs actual attendance (False).
738
+ meta (Optional[Dict[str, Any]]): Additional metadata for the attendance.
739
+ created (datetime): The timestamp when the record was created.
740
+ updated (datetime): The timestamp when the record was last updated.
741
+
742
+ event (Event): The associated event.
743
+ user (User): The associated user.
744
+ slack_user (Optional[SlackUser]): The associated Slack user.
745
+ attendance_x_attendance_types (List[Attendance_x_AttendanceType]): The association between the attendance and attendance types.
746
+ attendance_types (List[AttendanceType]): The associated attendance types.
747
+ """
748
+
749
+ __tablename__ = "attendance"
750
+ __table_args__ = (UniqueConstraint("event_id", "user_id", "is_planned"),)
751
+
752
+ id: Mapped[intpk]
753
+ event_id: Mapped[int] = mapped_column(ForeignKey("events.id"))
754
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
755
+ is_planned: Mapped[bool]
756
+ meta: Mapped[Optional[Dict[str, Any]]]
757
+ created: Mapped[dt_create]
758
+ updated: Mapped[dt_update]
759
+
760
+ event: Mapped[Event] = relationship(
761
+ innerjoin=True, cascade="expunge", viewonly=True
762
+ )
763
+ user: Mapped[User] = relationship(innerjoin=True, cascade="expunge", viewonly=True)
764
+ slack_user: Mapped[Optional[SlackUser]] = relationship(
765
+ innerjoin=False, cascade="expunge", secondary="users", viewonly=True
766
+ )
767
+ attendance_x_attendance_types: Mapped[List[Attendance_x_AttendanceType]] = (
768
+ relationship(back_populates="attendance")
769
+ )
770
+ attendance_types: Mapped[List[AttendanceType]] = relationship(
771
+ secondary="attendance_x_attendance_types",
772
+ innerjoin=True,
773
+ cascade="expunge",
774
+ viewonly=True,
775
+ )
776
+
777
+
759
778
  class Achievement(Base):
760
779
  """
761
780
  Model representing an achievement.
@@ -802,21 +821,21 @@ class Achievement_x_User(Base):
802
821
  )
803
822
 
804
823
 
805
- # class Achievement_x_Org(Base):
806
- # """
807
- # Model representing the association between achievements and organizations.
824
+ class Achievement_x_Org(Base):
825
+ """
826
+ Model representing the association between achievements and organizations.
808
827
 
809
- # Attributes:
810
- # achievement_id (int): The ID of the associated achievement.
811
- # org_id (int): The ID of the associated organization.
812
- # """
828
+ Attributes:
829
+ achievement_id (int): The ID of the associated achievement.
830
+ org_id (int): The ID of the associated organization.
831
+ """
813
832
 
814
- # __tablename__ = "achievements_x_org"
833
+ __tablename__ = "achievements_x_org"
815
834
 
816
- # achievement_id: Mapped[int] = mapped_column(
817
- # ForeignKey("achievements.id"), primary_key=True
818
- # )
819
- # org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
835
+ achievement_id: Mapped[int] = mapped_column(
836
+ ForeignKey("achievements.id"), primary_key=True
837
+ )
838
+ org_id: Mapped[int] = mapped_column(ForeignKey("orgs.id"), primary_key=True)
820
839
 
821
840
 
822
841
  class Position(Base):
f3_data_models/utils.py CHANGED
@@ -56,7 +56,7 @@ def get_engine(echo=False) -> Engine:
56
56
  return engine
57
57
 
58
58
 
59
- def get_session(echo=False):
59
+ def get_session(echo=True):
60
60
  if GLOBAL_SESSION:
61
61
  return GLOBAL_SESSION
62
62
 
@@ -99,7 +99,7 @@ class DbManager:
99
99
  def find_records(
100
100
  cls: T, filters: Optional[List], joinedloads: List | str = []
101
101
  ) -> List[T]:
102
- session = get_session(echo=True)
102
+ session = get_session()
103
103
  try:
104
104
  query = select(cls)
105
105
  query = _joinedloads(cls, query, joinedloads)
@@ -254,10 +254,16 @@ class DbManager:
254
254
  session.commit()
255
255
  close_session(session)
256
256
 
257
- def delete_records(cls: T, filters):
257
+ def delete_records(cls: T, filters, joinedloads: List | str = []):
258
258
  session = get_session()
259
259
  try:
260
- session.query(cls).filter(and_(*filters)).delete()
260
+ query = select(cls)
261
+ query = _joinedloads(cls, query, joinedloads)
262
+ query = query.filter(*filters)
263
+ records = session.scalars(query).unique().all()
264
+ for r in records:
265
+ session.delete(r)
266
+ # session.query(cls).filter(and_(*filters)).delete()
261
267
  session.flush()
262
268
  finally:
263
269
  session.commit()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: f3-data-models
3
- Version: 0.1.8
3
+ Version: 0.1.11
4
4
  Summary: The data schema and models for F3 Nation applications.
5
5
  Home-page: https://github.com/F3-Nation/f3-data-models
6
6
  License: MIT
@@ -0,0 +1,6 @@
1
+ f3_data_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ f3_data_models/models.py,sha256=UV-O8z6pciSD9ZmBv-X95p4We1RX0elRFlW2aenTt2s,36517
3
+ f3_data_models/utils.py,sha256=Ytyjn6DScRw0bxkEea_RfAgeUV3Q5I22FuT0O7aizCs,8764
4
+ f3_data_models-0.1.11.dist-info/METADATA,sha256=Zs1LWDl6jEuVFQt8a2IvzBsl0CVMKMMtkQ9vMzPqDc4,2714
5
+ f3_data_models-0.1.11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
6
+ f3_data_models-0.1.11.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=efp_EX23ccgYNNrLTESEGHOg526Al_4ypJ7rlPwQbiE,35195
3
- f3_data_models/utils.py,sha256=r67DFa18kdkugvGcc3gKwpYfGbcl-TPSQIpdfsdgm0Q,8485
4
- f3_data_models-0.1.8.dist-info/METADATA,sha256=_o7MBzD5LAf92bRMwosTPqbjRHKpC54S7-zQHYc4qr4,2713
5
- f3_data_models-0.1.8.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
6
- f3_data_models-0.1.8.dist-info/RECORD,,