# HG changeset patch # User Daniele Nicolodi # Date 1314126249 -7200 # Node ID e2338b374af47323dcf377b173febb2a3376b37b # Parent 598f84f0db4e02c3b8f9b54070398a00a0dfe663 Small improvements to the Objs class and to its tests. diff -r 598f84f0db4e -r e2338b374af4 src/ltpdarepo/tests/test_objs.py --- a/src/ltpdarepo/tests/test_objs.py Tue Aug 23 21:03:50 2011 +0200 +++ b/src/ltpdarepo/tests/test_objs.py Tue Aug 23 21:04:09 2011 +0200 @@ -12,14 +12,16 @@ def test_simple(self): objs = Objs(database='db1') + self.assertEqual(len(objs), objs.count()) self.assertEqual(len(objs.all()), objs.count()) def test_limit(self): objs = Objs(database='db1').limit(20) + self.assertEqual(objs[0]['id'], 1) self.assertEqual(len(objs.all()), 20) objs = Objs(database='db1').limit(20, 2) - self.assertEqual(objs.all()[0]['id'], 21) + self.assertEqual(objs[0]['id'], 21) self.assertEqual(len(objs.all()), 2) def test_orderby(self): diff -r 598f84f0db4e -r e2338b374af4 src/ltpdarepo/views/browse.py --- a/src/ltpdarepo/views/browse.py Tue Aug 23 21:03:50 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Tue Aug 23 21:04:09 2011 +0200 @@ -74,8 +74,6 @@ query = "SELECT COUNT(*) FROM `%s`.objmeta" % self._database if self._where: query += " WHERE %s" % self._where - if self._limit: - query += " LIMIT %d,%d" % self._limit return query def filter(self, where, values): @@ -108,10 +106,15 @@ return self.count() def __getitem__(self, item): - self._limit = (item, 1) + obj = None + limit = self._limit + start = limit and limit[0] or 0 + self._limit = start, 1 objs = self.all() if objs is not None: - return objs[0] + obj = objs[0] + self._limit = limit + return obj class Timeseries(Objs): @@ -215,9 +218,6 @@ values = [v.strip("'") for v in values] return column, kind, values - def column(self, name): - return self[name].column - class datetimefield(datetime): """Timezone aware subclass of `datetime.datetime` with a new