本文整理汇总了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)
示例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