瀏覽代碼

cycle sort by creation_date (#1554)

fix filter contains on str
resolves #1546

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 10 月之前
父節點
當前提交
43081f71ff
共有 2 個文件被更改,包括 15 次插入9 次删除
  1. 13 7
      taipy/gui_core/_adapters.py
  2. 2 2
      taipy/gui_core/_context.py

+ 13 - 7
taipy/gui_core/_adapters.py

@@ -296,7 +296,7 @@ def _invoke_action(
         if op := _operators.get(action):
             cur_val = attrgetter(col_fn or col)(ent)
             cur_val = cur_val() if col_fn else cur_val
-            if isinstance(cur_val, Iterable):
+            if not isinstance(cur_val, str) and isinstance(cur_val, Iterable):
                 return _filter_iterable(cur_val, op, val)
             return _filter_value(cur_val, op, val, _adapt_type)
     except Exception as e:
@@ -306,11 +306,11 @@ def _invoke_action(
     return True
 
 
-def _get_entity_property(col: str, a_type: t.Type):
-    col_parts = col.split("(")  # handle the case where the col is a method (ie get_simple_label())
+def _get_entity_property(col: str, *types: t.Type):
+    col_parts = col.split("(", 2)  # handle the case where the col is a method (ie get_simple_label())
     col_fn = (
         next(
-            (col_parts[0] for i in inspect.getmembers(a_type, predicate=inspect.isfunction) if i[0] == col_parts[0]),
+            (col_parts[0] for i in inspect.getmembers(types[0], predicate=inspect.isfunction) if i[0] == col_parts[0]),
             None,
         )
         if len(col_parts) > 1
@@ -319,10 +319,16 @@ def _get_entity_property(col: str, a_type: t.Type):
 
     def sort_key(entity: t.Union[Scenario, Cycle, Sequence, DataNode]):
         # we compare only strings
-        if isinstance(entity, a_type):
+        if isinstance(entity, types):
+            if isinstance(entity, Cycle):
+                lcol = "creation_date"
+                lfn = None
+            else:
+                lcol = col
+                lfn = col_fn
             try:
-                val = attrgetter(col_fn or col)(entity)
-                if col_fn:
+                val = attrgetter(lfn or lcol)(entity)
+                if lfn:
                     val = val()
             except AttributeError as e:
                 if _is_debugging():

+ 2 - 2
taipy/gui_core/_context.py

@@ -288,9 +288,9 @@ class _GuiCoreContext(CoreEventConsumerBase):
                 col = sd.get("col", "")
                 col = _GuiCoreScenarioProperties.get_col_name(col)
                 order = sd.get("order", True)
-                sorted_list = sorted(sorted_list, key=_get_entity_property(col, Scenario), reverse=not order)
+                sorted_list = sorted(sorted_list, key=_get_entity_property(col, Scenario, Cycle), reverse=not order)
         else:
-            sorted_list = sorted(entities, key=_get_entity_property("creation_date", Scenario))
+            sorted_list = sorted(entities, key=_get_entity_property("creation_date", Scenario, Cycle))
         return [self.cycle_adapter(e, sorts) if isinstance(e, Cycle) else e for e in sorted_list]
 
     def get_filtered_scenario_list(