changeset 107:a23e8191c6bc

Update project list when a new project was created
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 12 Sep 2011 14:54:00 +0200 (2011-09-12)
parents a0779fb2ef4d
children e7548b8c6dcc
files getan.py getan/view.py
diffstat 2 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/getan.py	Mon Sep 12 14:53:28 2011 +0200
+++ b/getan.py	Mon Sep 12 14:54:00 2011 +0200
@@ -27,14 +27,11 @@
         self.ev_class = ev_class
         self.pv_class = pv_class
 
-        self.projects = backend.load_projects()
-        if self.projects:
-            entries = backend.load_entries(self.projects[0].id)
-        else:
-            entries = []
+        self.backend      = backend
+        projects, entries = self.load_projects()
+        self.projects = projects
         self.running  = []
 
-        self.backend      = backend
         self.project_view = pv_class(self, self.projects)
         self.entries_view = ev_class(entries)
 
@@ -54,6 +51,14 @@
         else:
             self.state = self.state.keypress(input)
 
+    def load_projects(self):
+        projects = self.backend.load_projects()
+        if projects:
+            entries = self.backend.load_entries(projects[0].id)
+        else:
+            entries = []
+        return (projects, entries)
+
     def update_entries(self, project):
         logger.debug("GetanController: update entries.")
         if project: entries = self.backend.load_entries(project.id)
@@ -139,6 +144,7 @@
         if not key or not description:
             return
         self.backend.insert_project(key, description)
+        self.update_projects()
         self.update_project_list()
 
     def update_entry(self, entry):
@@ -148,6 +154,11 @@
         for project in self.running:
             self.stop_project(display=False)
 
+    def update_projects(self):
+        projects, entries = self.load_projects()
+        self.projects = projects
+        self.project_view.load_rows(projects)
+
 
 def main():
 
--- a/getan/view.py	Mon Sep 12 14:53:28 2011 +0200
+++ b/getan/view.py	Mon Sep 12 14:54:00 2011 +0200
@@ -203,13 +203,11 @@
         self.size         = ()
         self.top          = 0
         self.controller   = controller
-        self.raw_rows     = rows
 
+        self.load_rows(rows)
         self.header    = urwid.LineBox(urwid.AttrWrap(urwid.Text("\n%s\n" %
             _('List of registered projects')),'project_header'))
         self.footer    = urwid.Edit()
-        self.rows      = [ProjectNode(x) for x in rows]
-        self.listbox   = urwid.ListBox(urwid.SimpleListWalker(self.rows))
         self.body      = urwid.LineBox(urwid.Padding(urwid.AttrWrap(
             self.listbox, 'entries'),('fixed left',1),('fixed right',1)))
         self.frame     = urwid.Frame(self.body, header=self.header,
@@ -217,6 +215,11 @@
         self.update_focus(self.focused)
         self._total_time()
 
+    def load_rows(self, rows):
+        self.raw_rows = rows
+        self.rows = [ProjectNode(x) for x in rows]
+        self.listbox = urwid.ListBox(urwid.SimpleListWalker(self.rows))
+
     def _total_time(self):
         if not self.rows: return
         logger.debug("ProjectList: update projects total time.")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)