本文整理汇总了Python中user_models.UserData.get_from_username_or_email方法的典型用法代码示例。如果您正苦于以下问题:Python UserData.get_from_username_or_email方法的具体用法?Python UserData.get_from_username_or_email怎么用?Python UserData.get_from_username_or_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user_models.UserData
的用法示例。
在下文中一共展示了UserData.get_from_username_or_email方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_coaches
# 需要导入模块: from user_models import UserData [as 别名]
# 或者: from user_models.UserData import get_from_username_or_email [as 别名]
def update_coaches(user_data, coaches_json):
""" Add as coaches those in coaches_json with isCoachingLoggedInUser
value True, and remove any old coaches not in coaches_json.
Return a list of requesters' emails.
"""
updated_coach_key_emails = []
current_coaches_data = user_data.get_coaches_data()
outstanding_coaches_dict = dict([(coach.email, coach.key_email)
for coach in current_coaches_data])
requester_emails = []
for coach_json in coaches_json:
email = coach_json['email']
is_coaching_logged_in_user = coach_json['isCoachingLoggedInUser']
if is_coaching_logged_in_user:
if email in outstanding_coaches_dict:
# Email corresponds to a current coach
updated_coach_key_emails.append(outstanding_coaches_dict[email])
del outstanding_coaches_dict[email]
else:
# Look up this new coach's key_email
coach_user_data = UserData.get_from_username_or_email(email)
if coach_user_data is not None:
updated_coach_key_emails.append(coach_user_data.key_email)
else:
raise custom_exceptions.InvalidEmailException()
else:
requester_emails.append(email)
user_data.remove_student_lists(outstanding_coaches_dict.keys())
user_data.coaches = updated_coach_key_emails
user_data.put()
return requester_emails