def total_for_district(self, form): loc = get_location_by_type(form=form, type=u'district') count = Location.filter_by_type_count(form.domain, 'PPS', loc) yield { 'date': form_date(form), 'value': count }
def main_context(self): try: facilities = Location.filter_by_type_count(self.domain, 'FACILITY') except TypeError: facilities = 0 contacts = CommCareUser.by_domain(self.domain, reduce=True) web_users = WebUser.by_domain(self.domain, reduce=True) try: products = len(Product.by_domain(self.domain)) except ResourceNotFound: products = 0 main_context = super(GlobalStats, self).main_context context = { 'supply_points': len(list(Location.by_domain(self.domain))), 'facilities': facilities, 'contacts': contacts[0]['value'] if contacts else 0, 'web_users': web_users[0]['value'] if web_users else 0, 'products': products, #TODO add next after the enlargement ILS migration 'product_stocks': 0, 'stock_transactions': 0, 'inbound_messages': 0, 'outbound_messages': 0 } main_context.update(context) return main_context
def main_context(self): try: facilities = Location.filter_by_type_count(self.domain, 'FACILITY') except TypeError: facilities = 0 contacts = CommCareUser.by_domain(self.domain, reduce=True) web_users = WebUser.by_domain(self.domain, reduce=True) try: products = len(Product.by_domain(self.domain)) except ResourceNotFound: products = 0 main_context = super(GlobalStats, self).main_context context = { 'supply_points': len(list(Location.by_domain(self.domain))), 'facilities': facilities, 'contacts': contacts[0]['value'] if contacts else 0, 'web_users': web_users[0]['value'] if web_users else 0, 'products': products, #TODO add next after the enlargement ILS migration 'product_stocks': 0, 'stock_transactions': 0, 'inbound_messages': 0, 'outbound_messages': 0 } main_context.update(context) return main_context
def total_for_district(self, form): loc = get_location_by_type(form=form, type=u'district') count = Location.filter_by_type_count(form.domain, 'PPS', loc) yield { 'date': form_date(form), 'value': count }
def test_location_queries(self): test_state1 = make_loc( 'teststate1', type='state', parent=self.user.locations[0] ) test_state2 = make_loc( 'teststate2', type='state', parent=self.user.locations[0] ) test_village1 = make_loc( 'testvillage1', type='village', parent=test_state1 ) test_village1.site_code = 'tv1' test_village1.save() test_village2 = make_loc( 'testvillage2', type='village', parent=test_state2 ) def compare(list1, list2): self.assertEqual( set([l._id for l in list1]), set([l._id for l in list2]) ) # descendants compare( [test_state1, test_state2, test_village1, test_village2], self.user.locations[0].descendants ) # children compare( [test_state1, test_state2], self.user.locations[0].children ) # siblings compare( [test_state2], test_state1.siblings() ) # parent and parent_id self.assertEqual( self.user.locations[0]._id, test_state1.parent_id ) self.assertEqual( self.user.locations[0]._id, test_state1.parent._id ) # is_root self.assertTrue(self.user.locations[0].is_root) self.assertFalse(test_state1.is_root) # Location.root_locations compare( [self.user.locations[0]], Location.root_locations(self.domain.name) ) # Location.filter_by_type compare( [test_village1, test_village2], Location.filter_by_type(self.domain.name, 'village') ) compare( [test_village1], Location.filter_by_type(self.domain.name, 'village', test_state1) ) # Location.filter_by_type_count self.assertEqual( 2, Location.filter_by_type_count(self.domain.name, 'village') ) self.assertEqual( 1, Location.filter_by_type_count(self.domain.name, 'village', test_state1) ) # Location.get_in_domain test_village2.domain = 'rejected' test_village2.save() self.assertEqual( Location.get_in_domain(self.domain.name, test_village1._id)._id, test_village1._id ) self.assertIsNone( Location.get_in_domain(self.domain.name, test_village2._id), ) self.assertIsNone( Location.get_in_domain(self.domain.name, 'not-a-real-id'), ) # Location.all_locations compare( [self.user.locations[0], test_state1, test_state2, test_village1], Location.all_locations(self.domain.name) ) # Location.by_site_code self.assertEqual( test_village1._id, Location.by_site_code(self.domain.name, 'tv1')._id ) self.assertIsNone( None, Location.by_site_code(self.domain.name, 'notreal') ) # Location.by_domain compare( [self.user.locations[0], test_state1, test_state2, test_village1], Location.by_domain(self.domain.name) )