Browse Source

fix bugs: 在screen中修改graph排序后排序混乱的问题,
优化position相同的graph的排序规则: 由graph.id决定position相同的graph顺序

yul 6 years ago
parent
commit
7525f95bc4
2 changed files with 3 additions and 3 deletions
  1. 1 1
      rrd/model/graph.py
  2. 2 2
      rrd/view/dashboard/screen.py

+ 1 - 1
rrd/model/graph.py

@@ -30,7 +30,7 @@ class DashboardGraph(object):
         self.timespan = timespan
         self.graph_type = graph_type
         self.method = method.upper()  # method can be ["", "sum", "average", "max", "min", "last"]
-        self.position = position or self.id # init as self.id
+        self.position = position or int(self.id) # init as self.id
 
     def __repr__(self):
         return "<DashboardGraph id=%s, title=%s, screen_id=%s>" %(self.id, self.title, self.screen_id)

+ 2 - 2
rrd/view/dashboard/screen.py

@@ -117,7 +117,7 @@ def dash_screen(sid):
     for graph in graphs:
         all_graphs.extend(generate_graph_urls(graph, start, end) or [])
 
-    all_graphs = sorted(all_graphs, key=lambda x:x.position)
+    all_graphs = sorted(all_graphs, key=lambda x: (x.position, x.id))
 
     return render_template("screen/screen.html", **locals())
 
@@ -139,7 +139,7 @@ def dash_screen_embed(sid):
     for graph in graphs:
         all_graphs.extend(generate_graph_urls(graph, start, end) or [])
 
-    all_graphs = sorted(all_graphs, key=lambda x:x.position)
+    all_graphs = sorted(all_graphs, key=lambda x: (x.position, x.id))
 
     return render_template("screen/screen_embed.html", **locals())