def get(self): teams = Team.query(Team.year == get_year()).fetch() individuals = Individual.query(Individual.year == get_year()).fetch() teamsDict = {} for team in teams: if team.assigned_id is not None and len(team.assigned_id) > 0: teamsDict[team.key.id()] = { 'id': team.assigned_id, 'name': team.name, 'team_scores': parse_or_none(team.team_scores), 'guts_scores': parse_or_none(team.guts_scores), 'members': [] } for individual in individuals: if individual.team > 0 and individual.team in teamsDict: teamsDict[individual.team]["members"].append({ 'name': individual.name, 'id': individual.assigned_id, 'speed_scores': json.loads(individual.speed_scores if (individual.speed_scores is not None) else 'null'), 'accuracy_scores': json.loads(individual.accuracy_scores if (individual.accuracy_scores is not None) else 'null') }) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(teamsDict))
def get(self): rnd = self.request.get('round') _id = self.request.get('id') name = '' ret = '[]' if rnd in ('speed', 'accuracy'): ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR) if ind.count() > 0: ind = ind.fetch()[0] name = ind.name + '|' + Team.get_by_id(ind.team).name if rnd == 'speed': ret = ind.speed_scores else: ret = ind.accuracy_scores else: team = Team.query(Team.assigned_id == _id) if team.count() > 0: team = team.fetch()[0] name = team.name if rnd == 'team': ret = team.team_scores else: if team.guts_scores is None: ret = [] else: ret = team.guts_scores self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'scores': ret, 'name': name }))
def get(self): teams = Team.query(Team.year == get_year()).fetch() individuals = Individual.query(Individual.year == get_year()).fetch() teamsDict = {} for team in teams: if team.assigned_id is not None and len(team.assigned_id) > 0: teamsDict[team.key.id()] = { 'id': team.assigned_id, 'name': team.name, 'team_scores': parse_or_none(team.team_scores), 'guts_scores': parse_or_none(team.guts_scores), 'members': [] } for individual in individuals: if individual.team > 0 and individual.team in teamsDict: teamsDict[individual.team]["members"].append({ 'name': individual.name, 'id': individual.assigned_id, 'speed_scores': json.loads(individual.speed_scores if ( individual.speed_scores is not None) else 'null'), 'accuracy_scores': json.loads(individual.accuracy_scores if ( individual.accuracy_scores is not None) else 'null') }) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(teamsDict))
def get(self): rnd = self.request.get('round') _id = self.request.get('id') name = '' ret = '[]' if rnd in ('speed', 'accuracy'): ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR) if ind.count() > 0: ind = ind.fetch()[0] name = ind.name + '|' + Team.get_by_id(ind.team).name if rnd == 'speed': ret = ind.speed_scores else: ret = ind.accuracy_scores else: team = Team.query(Team.assigned_id == _id) if team.count() > 0: team = team.fetch()[0] name = team.name if rnd == 'team': ret = team.team_scores else: if team.guts_scores is None: ret = [] else: ret = team.guts_scores self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'scores': ret, 'name': name}))
def get(self): teams = Team.query(Team.year == get_year()).fetch() ret = [] for team in teams: if team.name is not None and team.assigned_id is not None and len( team.assigned_id) > 0: ret.append({'name': team.name, 'scores': team.guts_scores}) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'teams': ret}))
def post(self): email = self.request.get('email') password = self.request.get('password') success = True problem = "" query = LegacyUser.query(LegacyUser.email == email) if query.count() == 0: try: u = self.auth.get_user_by_password(email, password, remember=True, save_session=True) print u except (InvalidAuthIdError, InvalidPasswordError) as e: success = False problem = str(type(e)) else: user = query.get() salt = user.salt _hash = user.hash hashfun = hashlib.sha512() hashfun.update(salt) hashfun.update(password.encode()) hashval = hashfun.hexdigest() if hashval == _hash: success = True user_data = self.user_model.create_user(email, password_raw=password, institution=user.institution) if not user_data[0]: success = False else: # Re-attribute any teams belonging to the legacy user # to the new user. query = Team.query(Team.user == user.key.id()) for team in query: print 'Reattributing ' + team.name team.user = user_data[1].key.id() team.put() query = Individual.query(Individual.user == user.key.id()) for individual in query: print 'Reattributing ' + individual.name individual.user = user_data[1].key.id() individual.put() self.auth.set_session(self.auth.store.user_to_dict(user_data[1]), remember=True) user.key.delete() else: success = False problem = 'InvalidPasswordError' self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'success': success, 'problem': problem }))
def get(self): teams = Team.query(Team.year == get_year()).fetch() ret = [] for team in teams: if team.name is not None and team.assigned_id is not None and len(team.assigned_id) > 0: ret.append({ 'name': team.name, 'scores': team.guts_scores }) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'teams': ret }))
def post(self): password = self.request.get('password') problem = '' success = True if password != 'adidasTwilight': success = False problem = 'password' else: rnd = self.request.get('round') _id = self.request.get('id') score = self.request.get('score') if rnd in ('speed', 'accuracy'): ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR) if ind.count() != 0: ind = ind.fetch()[0] if rnd == 'speed': ind.speed_scores = score else: ind.accuracy_scores = score ind.put() else: success = False problem = 'id' else: team = Team.query(Team.assigned_id == _id) if team.count() != 0: team = team.fetch()[0] if rnd == 'team': team.team_scores = score else: guts_round = int(self.request.get('guts_round')) if team.guts_scores is None: team.guts_scores = '[]' loaded = json.loads(team.guts_scores) loaded[guts_round * 3 - 3:guts_round * 3] = json.loads(score) team.guts_scores = json.dumps(loaded) team.put() else: success = False problem = 'id' self.response.headers['Content-Type'] = 'application/json' self.response.write( json.dumps({ 'success': success, 'problem': problem }))
def get(self): teams = Team.query(Team.year == get_year() - 1) teams_dict = {} for team in teams: team.year = get_year() individuals = Individual.query(Individual.team == team.key.id()) for individual in individuals: individual.year = team.year individual.put() teams_dict[team.key.id()] = team.year team.put() self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'teams': teams_dict}))
def post(self): password = self.request.get('password') problem = '' success = True if password != 'adidasTwilight': success = False problem = 'password' else: rnd = self.request.get('round') _id = self.request.get('id') score = self.request.get('score') if rnd in ('speed', 'accuracy'): ind = Individual.query(Individual.assigned_id == _id, Individual.year == YEAR) if ind.count() != 0: ind = ind.fetch()[0] if rnd == 'speed': ind.speed_scores = score else: ind.accuracy_scores = score ind.put() else: success = False problem = 'id' else: team = Team.query(Team.assigned_id == _id) if team.count() != 0: team = team.fetch()[0] if rnd == 'team': team.team_scores = score else: guts_round = int(self.request.get('guts_round')) if team.guts_scores is None: team.guts_scores = '[]' loaded = json.loads(team.guts_scores) loaded[guts_round*3-3:guts_round*3] = json.loads(score) team.guts_scores = json.dumps(loaded) team.put() else: success = False problem = 'id' self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'success': success, 'problem': problem }))
def get(self): teams = Team.query(Team.year == get_year() - 1) teams_dict = {} for team in teams: team.year = get_year() individuals = Individual.query(Individual.team == team.key.id()) for individual in individuals: individual.year = team.year individual.put() teams_dict[team.key.id()] = team.year team.put() self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({ 'teams': teams_dict }))
def post(self): email = self.request.get('email') password = self.request.get('password') success = True problem = "" query = LegacyUser.query(LegacyUser.email == email) if query.count() == 0: try: u = self.auth.get_user_by_password(email, password, remember=True, save_session=True) print u except (InvalidAuthIdError, InvalidPasswordError) as e: success = False problem = str(type(e)) else: user = query.get() salt = user.salt _hash = user.hash hashfun = hashlib.sha512() hashfun.update(salt) hashfun.update(password.encode()) hashval = hashfun.hexdigest() if hashval == _hash: success = True user_data = self.user_model.create_user( email, password_raw=password, institution=user.institution) if not user_data[0]: success = False else: # Re-attribute any teams belonging to the legacy user # to the new user. query = Team.query(Team.user == user.key.id()) for team in query: print 'Reattributing ' + team.name team.user = user_data[1].key.id() team.put() query = Individual.query(Individual.user == user.key.id()) for individual in query: print 'Reattributing ' + individual.name individual.user = user_data[1].key.id() individual.put() self.auth.set_session(self.auth.store.user_to_dict( user_data[1]), remember=True) user.key.delete() else: success = False problem = 'InvalidPasswordError' self.response.headers['Content-Type'] = 'application/json' self.response.write( json.dumps({ 'success': success, 'problem': problem }))