diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-02-24 12:26:40 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-02-24 12:26:40 +0000 |
commit | a00fe4ed498b617c4cc4c0874a5ab58600ae3ae5 (patch) | |
tree | d9db0763ff8be3816d82da8b93ffd74f5ff9ce03 | |
parent | 87d12b5c07e3174345d11b082604cab0f6164f44 (diff) | |
download | lorry-controller-a00fe4ed498b617c4cc4c0874a5ab58600ae3ae5.tar.gz |
Change get_lorries to return list of dicts
There's too many fields now, so returning a dict, instead of a tuple,
for each list items reduces coupling with caller, and makes it easier
to deal with changes in the future.
-rwxr-xr-x | lorry-controller-webapp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp index cfc5534..c01bf37 100755 --- a/lorry-controller-webapp +++ b/lorry-controller-webapp @@ -128,12 +128,23 @@ class StateDB(object): 'interval': row[4], } - def get_lorries(self): - logging.debug('StateDB.get_lorries called') + def get_all_lorries_info(self): + logging.debug('StateDB.get_all_lorries_info called') self._open() c = self._conn.cursor() - return c.execute( - 'SELECT path, text, generated, due FROM lorries ORDER BY due') + c.execute( + 'SELECT path, text, generated, due, interval FROM lorries ' + 'ORDER BY due') + return [ + { + 'path': row[0], + 'text': row[1], + 'generated': row[2], + 'due': row[3], + 'interval': row[4], + } + for row in c.fetchall() + ] def get_lorries_paths(self): logging.debug('StateDB.get_lorries_paths called') @@ -371,7 +382,8 @@ class ListQueue(LorryControllerRoute): def run(self, **kwargs): logging.debug('%s %s called', self.http_method, self.path) return { - 'queue': [row[0] for row in self.statedb.get_lorries()], + 'queue': + [spec['path'] for spec in self.statedb.get_all_lorries_info()], } |