|
20 | 20 | from enferno.admin.models.Location import Location |
21 | 21 | from enferno.admin.models.GeoLocation import GeoLocation |
22 | 22 | from enferno.admin.models.Event import Event |
| 23 | +from enferno.admin.models.DynamicField import DynamicField |
23 | 24 |
|
24 | 25 |
|
25 | 26 | from enferno.admin.models.tables import ( |
@@ -690,7 +691,7 @@ def to_dict(self, mode: Optional[str] = None) -> dict[str, Any]: |
690 | 691 | if mode == "1": |
691 | 692 | return self.min_json() |
692 | 693 |
|
693 | | - # Get base dictionary with dynamic fields |
| 694 | + # Get base dictionary |
694 | 695 | data = super().to_dict() |
695 | 696 |
|
696 | 697 | # locations json |
@@ -753,7 +754,7 @@ def to_dict(self, mode: Optional[str] = None) -> dict[str, Any]: |
753 | 754 | for relation in self.incident_relations: |
754 | 755 | incident_relations_dict.append(relation.to_dict()) |
755 | 756 |
|
756 | | - # Update with bulletin-specific fields |
| 757 | + # Update with bulletin-specific core fields |
757 | 758 | data.update( |
758 | 759 | { |
759 | 760 | "class": self.__tablename__, |
@@ -794,6 +795,15 @@ def to_dict(self, mode: Optional[str] = None) -> dict[str, Any]: |
794 | 795 | } |
795 | 796 | ) |
796 | 797 |
|
| 798 | + # Merge dynamic fields (non-core) into the response |
| 799 | + try: |
| 800 | + dynamic_values = DynamicField.extract_values_for(self) |
| 801 | + if dynamic_values: |
| 802 | + data.update(dynamic_values) |
| 803 | + except Exception: |
| 804 | + # Fail-safe: never break serialization because of dynamic fields |
| 805 | + logger.error("Failed to merge dynamic fields for Bulletin %s", self.id, exc_info=True) |
| 806 | + |
797 | 807 | return data |
798 | 808 |
|
799 | 809 | # custom serialization mode |
|
0 commit comments