[Getan-commits] [PATCH 07 of 16] Add lazy loading of Project Entries

Wald Commits scm-commit at wald.intevation.org
Mon Mar 3 15:00:38 CET 2014


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1393853174 -3600
# Node ID 2e7885dc66695c69c9c71741f61921979b561375
# Parent  b5dc92631561298ef95842aef98b5ad7a1a8ecb8
Add lazy loading of Project Entries

Only load the Entries of a Project when they are required. This will allow to
load also only specific entries from a project.

diff -r b5dc92631561 -r 2e7885dc6669 getan/project.py
--- a/getan/project.py	Mon Mar 03 14:24:44 2014 +0100
+++ b/getan/project.py	Mon Mar 03 14:26:14 2014 +0100
@@ -15,11 +15,12 @@
 
 class Project(object):
 
-    def __init__(self, id, key, desc, total):
+    def __init__(self, backend, id, key, desc, total):
+        self.backend = backend
         self.id = id
         self.key = key
         self.desc = desc
-        self.entries = []
+        self._entries = None
         self.total = total
         self.start = None
         self.stop = None
@@ -62,6 +63,15 @@
                 total += (entry.end - start).seconds
         return total
 
+    def load_entries(self, year=None, week=None):
+        self._entries = self.backend.load_entries(self.id, year, week)
+
+    @property
+    def entries(self):
+        if self._entries is None:
+            self.load_entries()
+        return self._entries
+
 
 class Entry(object):
 


More information about the Getan-commits mailing list