當前位置: 首頁>>代碼示例>>Python>>正文


Python CommTrackUser.get_by_username方法代碼示例

本文整理匯總了Python中corehq.apps.commtrack.models.CommTrackUser.get_by_username方法的典型用法代碼示例。如果您正苦於以下問題:Python CommTrackUser.get_by_username方法的具體用法?Python CommTrackUser.get_by_username怎麽用?Python CommTrackUser.get_by_username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在corehq.apps.commtrack.models.CommTrackUser的用法示例。


在下文中一共展示了CommTrackUser.get_by_username方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save

# 需要導入模塊: from corehq.apps.commtrack.models import CommTrackUser [as 別名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import get_by_username [as 別名]
    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)
開發者ID:modonnell729,項目名稱:commcare-hq,代碼行數:24,代碼來源:bulkupload.py

示例2: save

# 需要導入模塊: from corehq.apps.commtrack.models import CommTrackUser [as 別名]
# 或者: from corehq.apps.commtrack.models.CommTrackUser import get_by_username [as 別名]
    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
開發者ID:NoahCarnahan,項目名稱:commcare-hq,代碼行數:39,代碼來源:bulkupload.py


注:本文中的corehq.apps.commtrack.models.CommTrackUser.get_by_username方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。