def save_profile(self, profile): # above we have user_required=True, so we know user is authorized if # we're in the body of this method; otherwise, endpoints_proto_datastore # will have thrown a 401 error user = get_current_user() # if user is None: # raise UnauthorizedException("Authorization required.") # see whether profile already exists and then update or insert new one query = Profile.query(Profile.userId == user.user_id()).get() if query: query.update(profile.displayName, profile.teeShirtSize) profile = query else: profile.userId = user.user_id() profile.mainEmail = user.email() profile.displayName = (profile.displayName or _extractDefaultDisplayNameFromEmail(user.email())) profile.teeShirtSize = profile.teeShirtSize or 'NOT_SPECIFIED' profile.put() # save to database return profile
def get_profile(self, query=None): # above we have user_required=True, so we know user is authorized if # we're in the body of this method; otherwise, endpoints_proto_datastore # will have thrown a 401 error user = get_current_user() return Profile.query(Profile.userId == user.user_id())