Exemplo n.º 1
0
    def save(self):
        """
        Calculate which locations need added or removed, then submit
        one caseblock to handle this
        """
        user = CommCareUser.get_by_username(self.username)
        if not user:
            raise UserUploadError(_('no username with {} found!'.format(self.username)))

        current_locations = user.locations
        current_location_codes = [loc.site_code for loc in current_locations]

        commit_list = {}
        messages = []
        def _add_loc(loc, clear=False):
            sp = self.get_supply_point_from_location(loc)
            if sp is None:
                messages.append(_("No supply point found for location '{}'. "
                   "Make sure the location type is not set to administrative only "
                   "and that the location has a valid sms code."
                ).format(loc or ''))
            else:
                commit_list.update(user.supply_point_index_mapping(sp, clear))

        for loc in self.to_add:
            if loc not in current_location_codes:
                _add_loc(loc)
        for loc in self.to_remove:
            if loc in current_location_codes:
                _add_loc(loc, clear=True)

        if commit_list:
            submit_mapping_case_block(user, commit_list)

        return messages
Exemplo n.º 2
0
    def add_location(self, location, create_sp_if_missing=False):
        sp = location.linked_supply_point()

        # hack: if location was created before administrative flag was
        # removed there would be no SupplyPointCase already
        if not sp and create_sp_if_missing:
            sp = SupplyPointCase.create_from_location(
                self.domain,
                location
            )

        from corehq.apps.commtrack.util import submit_mapping_case_block
        submit_mapping_case_block(self, self.supply_point_index_mapping(sp))
Exemplo n.º 3
0
    def save(self):
        """
        Calculate which locations need added or removed, then submit
        one caseblock to handle this
        """
        user = CommTrackUser.get_by_username(self.username)
        if not user:
            raise UserUploadError(
                _('no username with {} found!'.format(self.username)))

        # have to rewrap since we need to force it to a commtrack user
        user = CommTrackUser.wrap(user.to_json())
        current_locations = user.locations
        current_location_codes = [loc.site_code for loc in current_locations]

        commit_list = {}
        messages = []

        def _add_loc(loc, clear=False):
            sp = self.get_supply_point_from_location(loc)
            if sp is None:
                messages.append(
                    _("No supply point found for location '{}'. "
                      "Make sure the location type is not set to administrative only "
                      "and that the location has a valid sms code.").format(
                          loc or ''))
            else:
                commit_list.update(user.supply_point_index_mapping(sp, clear))

        for loc in self.to_add:
            if loc not in current_location_codes:
                _add_loc(loc)
        for loc in self.to_remove:
            if loc in current_location_codes:
                _add_loc(loc, clear=True)

        if commit_list:
            submit_mapping_case_block(user, commit_list)

        return messages
Exemplo n.º 4
0
    def save(self):
        """
        Calculate which locations need added or removed, then submit
        one caseblock to handle this
        """
        user = CommTrackUser.wrap(CommTrackUser.get_by_username(self.username).to_json())
        current_locations = user.locations
        current_location_codes = [loc.site_code for loc in current_locations]

        commit_list = {}
        for loc in self.to_add:
            if loc not in current_location_codes:
                sp = self.get_supply_point_from_location(loc)
                commit_list.update(user.supply_point_index_mapping(sp))

        for loc in self.to_remove:
            if loc in current_location_codes:
                sp = self.get_supply_point_from_location(loc)
                commit_list.update(user.supply_point_index_mapping(sp, True))

        if commit_list:
            submit_mapping_case_block(user, commit_list)
Exemplo n.º 5
0
    def add_location(self, location):
        sp = location.linked_supply_point()

        from corehq.apps.commtrack.util import submit_mapping_case_block
        submit_mapping_case_block(self, self.supply_point_index_mapping(sp))
Exemplo n.º 6
0
    def add_location(self, location, create_sp_if_missing=False):
        sp = SupplyPointCase.get_or_create_by_location(location)

        from corehq.apps.commtrack.util import submit_mapping_case_block
        submit_mapping_case_block(self, self.supply_point_index_mapping(sp))