changeset 141:dafff6c3fa12

Add code to be able to sort the project list Currently it is possible to sort the projects in the project list by id, key and description.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 01 Nov 2012 11:29:35 +0100
parents 7413197aba45
children d88240a3a065
files getan/view.py
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/getan/view.py	Thu Nov 01 11:28:07 2012 +0100
+++ b/getan/view.py	Thu Nov 01 11:29:35 2012 +0100
@@ -203,12 +203,20 @@
 
 
 class ProjectList(ListWidget):
+
+    PROJECT_MODES = {
+            0: "id",
+            1: "key",
+            2: "desc"
+    }
+
     def __init__(self, controller, rows):
         self.selection    = []
         self.focused      = 0
         self.size         = ()
         self.top          = 0
         self.controller   = controller
+        self.project_mode = 0
 
         self.load_rows(rows)
         self.header    = urwid.LineBox(urwid.AttrWrap(urwid.Text("\n%s\n" %
@@ -223,9 +231,17 @@
 
     def load_rows(self, rows):
         self.raw_rows = rows
-        self.rows = [ProjectNode(x) for x in rows]
+        self.update_rows()
+
+    def update_rows(self):
+        rows = self.raw_rows
+        self.rows = [ProjectNode(x) for x in \
+                sorted(rows, key=lambda row: self._get_project_sort_key(row))]
         self.listbox = urwid.ListBox(urwid.SimpleListWalker(self.rows))
 
+    def _get_project_sort_key(self, proj):
+        return getattr(proj, self.PROJECT_MODES[self.project_mode])
+
     def _total_time(self):
         if not self.rows:
             return
@@ -281,6 +297,14 @@
                 self.select()
                 break
 
+    def switch_project_order(self):
+        self.project_mode += 1
+        if self.project_mode >= len(self.PROJECT_MODES):
+            self.project_mode = 0
+        self.update_rows()
+        self.controller.update_project_list()
+        self.update_focus(0)
+
 
 class EntryNode(urwid.WidgetWrap):
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)