diff --git a/enferno/admin/models/Bulletin.py b/enferno/admin/models/Bulletin.py index 296fe0334..3639ad9f1 100644 --- a/enferno/admin/models/Bulletin.py +++ b/enferno/admin/models/Bulletin.py @@ -484,7 +484,9 @@ def to_compact(self) -> dict[str, Any]: sources_json = [] if self.sources and len(self.sources): for source in self.sources: - sources_json.append({"id": source.id, "title": source.title}) + sources_json.append( + {"id": source.id, "title": source.title, "title_ar": source.title_ar} + ) return { "id": self.id, @@ -697,19 +699,37 @@ def to_dict(self, mode: Optional[str] = None) -> dict[str, Any]: sources_json = [] if self.sources and len(self.sources): for source in self.sources: - sources_json.append({"id": source.id, "title": source.title}) + sources_json.append( + {"id": source.id, "title": source.title, "title_ar": source.title_ar} + ) # labels json labels_json = [] if self.labels and len(self.labels): for label in self.labels: - labels_json.append({"id": label.id, "title": label.title}) + labels_json.append( + { + "id": label.id, + "title": label.title, + "title_ar": label.title_ar, + "path": label._build_path(), + "path_ar": label._build_path(translated=True), + } + ) # verified labels json ver_labels_json = [] if self.ver_labels and len(self.ver_labels): for vlabel in self.ver_labels: - ver_labels_json.append({"id": vlabel.id, "title": vlabel.title}) + ver_labels_json.append( + { + "id": vlabel.id, + "title": vlabel.title, + "title_ar": vlabel.title_ar, + "path": vlabel._build_path(), + "path_ar": vlabel._build_path(translated=True), + } + ) # events json events_json = [] @@ -806,7 +826,9 @@ def to_mode2(self) -> dict[str, Any]: sources_json = [] if self.sources and len(self.sources): for source in self.sources: - sources_json.append({"id": source.id, "title": source.title}) + sources_json.append( + {"id": source.id, "title": source.title, "title_ar": source.title_ar} + ) return { "class": "Bulletin", diff --git a/enferno/admin/models/Incident.py b/enferno/admin/models/Incident.py index aeba2732e..650cb89ca 100644 --- a/enferno/admin/models/Incident.py +++ b/enferno/admin/models/Incident.py @@ -488,7 +488,15 @@ def to_dict(self, mode: Optional[str] = None) -> dict[str, Any]: labels_json = [] if self.labels and len(self.labels): for label in self.labels: - labels_json.append({"id": label.id, "title": label.title}) + labels_json.append( + { + "id": label.id, + "title": label.title, + "title_ar": label.title_ar, + "path": label._build_path(), + "path_ar": label._build_path(translated=True), + } + ) # Locations json locations_json = [] @@ -577,7 +585,15 @@ def to_mode2(self) -> dict[str, Any]: labels_json = [] if self.labels and len(self.labels): for label in self.labels: - labels_json.append({"id": label.id, "title": label.title}) + labels_json.append( + { + "id": label.id, + "title": label.title, + "title_ar": label.title_ar, + "path": label._build_path(), + "path_ar": label._build_path(translated=True), + } + ) # Locations json locations_json = [] diff --git a/enferno/admin/models/Label.py b/enferno/admin/models/Label.py index 4419c34be..f0bb310a9 100644 --- a/enferno/admin/models/Label.py +++ b/enferno/admin/models/Label.py @@ -41,14 +41,19 @@ class Label(db.Model, BaseMixin): parent_label_id = db.Column(db.Integer, db.ForeignKey("label.id"), index=True, nullable=True) parent = db.relationship("Label", remote_side=id, backref="sub_label") - def _build_path(self) -> str: - """Walk up parent chain, return 'Grandparent > Parent' (excludes self).""" + def _build_path(self, translated: bool = False) -> str: + """Walk up parent chain, return 'Grandparent > Parent' (excludes self). + + With translated=True, use each ancestor's Arabic title, falling back to the + English title per level for ancestors that have no translation yet. + """ parts = [] current = self.parent seen = set() while current and current.id not in seen: seen.add(current.id) - parts.append(current.title) + title = (current.title_ar or current.title) if translated else current.title + parts.append(title) current = current.parent parts.reverse() return " > ".join(parts) if parts else "" @@ -77,7 +82,7 @@ def _is_valid_parent(self, parent_id) -> bool: @staticmethod def build_tree(verified=None): """Build nested tree structure using raw SQL for performance.""" - query = "SELECT id, title, parent_label_id, verified, for_bulletin, for_actor, for_incident, for_offline FROM label" + query = "SELECT id, title, parent_label_id, verified, for_bulletin, for_actor, for_incident, for_offline, title_ar, comments, comments_ar FROM label" conditions = [] if verified is True: conditions.append("verified = true") @@ -101,6 +106,9 @@ def build_tree(verified=None): "for_actor": r[5], "for_incident": r[6], "for_offline": r[7], + "title_ar": r[8], + "comments": r[9], + "comments_ar": r[10], "children": [], } @@ -151,6 +159,8 @@ def to_dict(self, mode: str = "1") -> dict[str, Any]: "id": self.id, "title": self.title, "title_ar": self.title_ar if self.title_ar else None, + "path": self._build_path(), + "path_ar": self._build_path(translated=True), "comments": self.comments if self.comments else None, "comments_ar": self.comments_ar if self.comments_ar else None, "order": self.order, @@ -181,7 +191,9 @@ def to_mode2(self) -> dict[str, Any]: return { "id": self.id, "title": self.title, + "title_ar": self.title_ar, "path": self._build_path(), + "path_ar": self._build_path(translated=True), "verified": self.verified, "for_bulletin": self.for_bulletin, "for_actor": self.for_actor, diff --git a/enferno/admin/models/Source.py b/enferno/admin/models/Source.py index bfab81d7e..cb210da60 100644 --- a/enferno/admin/models/Source.py +++ b/enferno/admin/models/Source.py @@ -61,6 +61,7 @@ def to_dict(self) -> dict[str, Any]: return { "id": self.id, "title": self.title, + "title_ar": self.title_ar, "etl_id": self.etl_id, "parent": {"id": self.parent.id, "title": self.parent.title} if self.parent else None, "comments": self.comments, diff --git a/enferno/admin/templates/admin/activity.html b/enferno/admin/templates/admin/activity.html index 57f63bfdc..12751a887 100644 --- a/enferno/admin/templates/admin/activity.html +++ b/enferno/admin/templates/admin/activity.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block css %} - + {% endblock %} {% block content %} @@ -146,74 +146,74 @@ {% block js %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% if config.GOOGLE_MAPS_API_KEY %} {{ ''|safe }} {% endif %} - + diff --git a/enferno/admin/templates/admin/actor-fields.html b/enferno/admin/templates/admin/actor-fields.html index efa3233c3..8647cf333 100644 --- a/enferno/admin/templates/admin/actor-fields.html +++ b/enferno/admin/templates/admin/actor-fields.html @@ -127,13 +127,13 @@ {% endblock %} {% block outside %} {% endblock %} {% block js %} - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% if config.GOOGLE_MAPS_API_KEY %} {{ ''|safe }} diff --git a/enferno/admin/templates/admin/bulletin-fields.html b/enferno/admin/templates/admin/bulletin-fields.html index f52e72316..a047aa5ec 100644 --- a/enferno/admin/templates/admin/bulletin-fields.html +++ b/enferno/admin/templates/admin/bulletin-fields.html @@ -133,13 +133,13 @@ {% endblock %} {% block outside %} {% endblock %} {% block js %} - - + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + {% if config.GOOGLE_MAPS_API_KEY %} {{ ''|safe }} diff --git a/enferno/admin/templates/admin/component-data.html b/enferno/admin/templates/admin/component-data.html index 9e8ef20cd..29424019b 100644 --- a/enferno/admin/templates/admin/component-data.html +++ b/enferno/admin/templates/admin/component-data.html @@ -273,10 +273,10 @@
diff --git a/enferno/templates/setup_wizard.html b/enferno/templates/setup_wizard.html
index c0cbddbd9..a1aea5287 100644
--- a/enferno/templates/setup_wizard.html
+++ b/enferno/templates/setup_wizard.html
@@ -6,28 +6,28 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -415,9 +415,9 @@