diff --git a/models/policy.py b/models/policy.py
index dbfb357..09e16e7 100644
--- a/models/policy.py
+++ b/models/policy.py
@@ -13,33 +13,36 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-import json
"""
Policy model representing policy data and relationships.
"""
-class Policy:
- def __init__(self, groupid, hidden, name, parent):
- self.groupid = groupid
- self.hidden = hidden
- self.name = name
- self.parent = parent
+# policy.py
- def __repr__(self):
- # Show all current attributes, including dynamically added ones
+from dataclasses import asdict, dataclass, field
+import json
+from typing import Optional
+
+
+@dataclass(order=True)
+class Policy:
+ name: str
+ groupid: int = field(compare=False)
+ hidden: bool = field(compare=False)
+ parent: Optional[str] = field(default=None, compare=False)
+
+ def __repr__(self) -> str:
attrs = ", ".join(
f"{key}={repr(value)}" for key, value in self.__dict__.items()
)
return f""
- def to_dict(self):
- # Return all attributes as a dictionary
- return self.__dict__
+ def to_dict(self) -> dict:
+ return asdict(self)
- def to_json(self):
- # Convert to JSON string, handling non-serializable types gracefully
+ def to_json(self) -> str:
return json.dumps(self.to_dict(), default=str)
diff --git a/widgets/multiagentselector.py b/widgets/multiagentselector.py
index a6c97e0..92016b7 100644
--- a/widgets/multiagentselector.py
+++ b/widgets/multiagentselector.py
@@ -79,14 +79,14 @@ class MultiAgentSelector(Widget):
with Horizontal() as select_buttons:
select_buttons.styles.margin = (0, 0, 0, 0)
- select_all_button = Button("✅ Select All", id="select_all")
- select_all_button.styles.margin = (1, 1, 0, 1)
- yield select_all_button
-
select_none_button = Button("🚫 Select None", id="select_none")
select_none_button.styles.margin = (1, 0, 0, 1)
yield select_none_button
+ select_all_button = Button("✅ Select All", id="select_all")
+ select_all_button.styles.margin = (1, 1, 0, 1)
+ yield select_all_button
+
with Horizontal() as button_row:
button_row.styles.height = "auto"
button_row.styles.margin = (1, 0, 0, 0)
diff --git a/widgets/policyselector.py b/widgets/policyselector.py
index c5bc6f7..fb34218 100644
--- a/widgets/policyselector.py
+++ b/widgets/policyselector.py
@@ -108,6 +108,7 @@ class PolicySelector(Widget):
with Vertical() as left_side:
left_side.styles.width = "1fr"
left_side.styles.height = "auto"
+ left_side.styles.margin = (0, 1, 0, 1)
filter_label = Static("Filter Policies:")
filter_label.styles.margin = (0, 0, 0, 0)
@@ -130,7 +131,7 @@ class PolicySelector(Widget):
apply_button.styles.margin = (0, 0, 1, 0)
yield apply_button
- clear_button = Button("🗑️ Clear Filter", id="clear_filter_button")
+ clear_button = Button("Clear Filter", id="clear_filter_button")
clear_button.styles.width = "100%"
clear_button.styles.margin = (0, 0, 1, 0)
yield clear_button
@@ -190,6 +191,7 @@ class PolicySelector(Widget):
policies_list = self.policies.to_dict("records")
else:
policies_list = self.policies
+ policies_list = sorted(policies_list)
self._filtered_policies = []
self._displayed_policies = [] # Initialize displayed list