def bundles(page): ds = Datastore() limit = PAGE_LIMIT skip = limit * (abs(page) - 1) cwr_results, count = ds.distinct(key='bundle_name', limit=limit, skip=skip) bundle_title = 'List of all bundles' pagination = Pagination( page=page, total_count=count, limit_per_page=limit, request=request) return render_template( 'bundles.html', cwr_results=cwr_results, bundle_title=bundle_title, pagination=pagination)
def test_distinct(self): doc = make_doc() doc['bundle_name'] = 'foo' update_data(self.ds, doc) doc = make_doc(2) doc['bundle_name'] = 'foo' update_data(self.ds, doc) doc = make_doc(3) update_data(self.ds, doc) ds = Datastore() distinct, count = ds.distinct() distinct = list(distinct) expected = [{'count': 2, '_id': 'foo'}, {'count': 1, '_id': 'openstack3'}] self.assertItemsEqual(distinct, expected) self.assertEqual(count, 2)