def get_serialized_point_ranks(): points = UserPoints.query().order(-UserPoints.all_time_total).fetch(10) user = users.get_current_user() user_id = "nope" if (user is not None): user_id = user.user_id() ranks = [] for point in points: profile = UserProfile.get_or_insert(point.user_id, user_id=point.user_id) result = { "p": point.all_time_total, "n": profile.sanitized_visible_name() } if (user_id == point.user_id): result["s"] = True ranks.append(result) return json.dumps({ "error": False, "ranks": ranks, "startRank": 1 })
def set_user_name(): try: new_name = request.forms.get('name') if (new_name is None): return {"error": True, "errorMessage": "'new_name' param must be set."} if (len(new_name) < min_visible_name_length): return { "error": True, "errorMessage": "Name can't be less than " + str(min_visible_name_length) + " characters."} if (len(new_name) > max_visible_name_length): return { "error": True, "errorMessage": "Name can't be more than " + str(max_visible_name_length) + " characters."} if (not visible_name_pattern.match(new_name)): return {"error": True, "errorMessage": "Name must be alphanumeric."} user = users.get_current_user() id_to_change = str(user.user_id()) # if we're an admin, allow changing anyone's name with the right id if (user and users.is_current_user_admin() and request.forms.get('id') is not None): id_to_change = request.forms.get('id') # get profile and set new name profile = UserProfile.get_or_insert(id_to_change, user_id=id_to_change, visible_name=new_name) profile.visible_name = new_name profile.put() return {"error": False } except Exception as e: return process_exception(e)