def set_locations(self, locations): if set([loc._id for loc in locations]) == set([loc._id for loc in self.locations]): # don't do anything if the list passed is the same # as the users current locations. the check is a little messy # as we can't compare the location objects themself return self.clear_locations() if not locations: return index = {} for location in locations: sp = SupplyPointCase.get_by_location(location) index.update(self.supply_point_index_mapping(sp)) from corehq.apps.commtrack.util import location_map_case_id caseblock = CaseBlock( create=True, case_type=USER_LOCATION_OWNER_MAP_TYPE, case_id=location_map_case_id(self), version=V2, owner_id=self._id, index=index ) self.submit_location_block(caseblock)
def get_location_map_case(self): try: from corehq.apps.commtrack.util import location_map_case_id return CommCareCase.get(location_map_case_id(self)) except ResourceNotFound: return None