def resolve_id_mismatch(klass, user, new_id): """Change all references to user's id to a new id. N.B. this is obviously brittle; when the relationship schema changes, this will also have to change. """ # The auth server has a different id for this user; defer to it. teams = Team.get(captain_id=user.uid) for t in teams: t.captain_id = new_id Team.put_multi(teams) classrooms = Classroom.get(contact_id=user.uid) for c in classrooms: c.contact_id = new_id Classroom.put_multi(classrooms) params = {'uid': new_id, 'short_uid': SqlModel.convert_uid(new_id)} with mysql_connection.connect() as sql: sql.update_row(klass.table, 'uid', user.uid, **params) for k, v in params.items(): setattr(user, k, v) return user
def post(self): team_key = self.request.get('team_key') team = Team.get(team_key) text = self.request.get('text') team.annotation = text team.put() self.redirect('/', {})
def test_task_data_too_large(self): user = User.create(name='foo', email='*****@*****.**') user.put() team_params = {'name': 'Team Foo', 'program_id': self.demo_program.uid} # A property is too long. self.testapp.post_json( '/api/teams', dict(team_params, task_data={'foo': 'x' * 10**5}), headers=self.login_headers(user), status=413, ) # Too many properties. self.testapp.post_json( '/api/teams', dict( team_params, task_data={'foo{}'.format(x): 'x' for x in range(10**3)}, ), headers=self.login_headers(user), status=413, ) # Both posts should have prevented teams from being stored. self.assertEqual(len(Team.get()), 0) # Successful POST response = self.testapp.post_json( '/api/teams', dict(team_params, task_data={'safe': 'data'}), headers=self.login_headers(user), ) response_dict = json.loads(response.body) put_url = '/api/teams/{}'.format(response_dict['uid']) # Same errors but for PUT # A property is too long. self.testapp.put_json( put_url, {'task_data': {'foo': 'x' * 10**5}}, headers=self.login_headers(user), status=413, ) # Too many properties. self.testapp.put_json( put_url, {'task_data': {'foo{}'.format(x): 'x' for x in range(10**3)}}, headers=self.login_headers(user), status=413, ) # Puts should have left body unchanged. self.assertEqual( Team.get_by_id(response_dict['uid']).task_data, {'safe': 'data'}, )
def deleteTeam(cityid, schoolid, teamid): # Удаление текущей записи в БД if session['demo']: pass else: # Ограничение по внешнему ключу FK_SAST_Team # не позволяет удалить команду при наличии связанных с ней игровых этапов. try: Team.get(school_ID = schoolid, team_ID = teamid).delete_instance() except IntegrityError: flash('Вы не можете удалить эту команду, пока она добавлена хотя бы в один игровой этап', 'danger') # Редирект на вид list return redirect( url_for('listTeam', cityid = cityid, schoolid = schoolid, teamid = teamid))
def post(self): team_key = self.request.get('team_key') team = Team.get(team_key) hidden = self.request.get('hidden') if hidden == 'true': team.hidden = True else: team.hidden = False team.put() self.redirect('/', {})
def get(self): # Launch a separate task to create emails for each team, to make sure # we can scale memory and cpu time easily. teams = Team.get() programs_by_id = {p.uid: p for p in Program.get()} for team in teams: if programs_by_id[team.program_id].send_cycle_email: taskqueue.add( url='/task/{}/cycle_emails'.format(team.uid), queue_name='default', ) team_ids = [t.uid for t in teams] logging.info(team_ids) self.response.write(json.dumps({'team_ids': team_ids}))
def get(self): team_key = self.request.get('team_key') team = Team.get(team_key) votes = Votes.for_user(users.get_current_user()) team.voted = (team.key() in votes.local_teams or team.key() in votes.teams) enable_commenting = False user_is_owner = users.get_current_user() == team.user if config["enable_owner_commenting"] and user_is_owner: enable_commenting = True if config['show_comments']: team.comments = list(Comment.get_team_comments(team)) for comment in team.comments: comment.author_name = generateCommentAuthorName(comment) self.render('team', { 'team': team, 'show_comments': config['show_comments'], 'enable_commenting': enable_commenting })
def get(self, date_str=None): try: # Make sure this is a valid date. datetime.datetime.strptime(date_str, config.iso_date_format) except: date_str = util.datelike_to_iso_string(datetime.date.today()) # Launch a separate task to get participation for each team, to make # sure we can scale memory and cpu time easily. teams = Team.get(n=float('inf')) for t in teams: taskqueue.add( url='/task/{}/team_participation/{}'.format(t.uid, date_str), queue_name='default', ) team_ids = [t.uid for t in teams] logging.info("Started tasks for {} teams".format(len(team_ids))) self.response.write(json.dumps({'team_ids': team_ids}))
def get_report_parents(program, week, should_force): # Look up teams and classrooms relevant to the requested script. orgs = Organization.get(program_id=program.uid, n=float('inf')) teams = Team.get(program_id=program.uid, n=float('inf')) classrooms = Classroom.get_by_program(program.uid) if should_force: # Don't skip any, re-request them all. skip_parent_ids = [] else: # Find all the reports for the current period that have already # been generated and don't re-request them. existing_reports = Report.get(issue_date=week, n=float('inf')) skip_parent_ids = [r.parent_id for r in existing_reports] return ( [o for o in orgs if o.uid not in skip_parent_ids], [t for t in teams if t.uid not in skip_parent_ids], [c for c in classrooms if c.uid not in skip_parent_ids], )
def get(self): team_key = self.request.get('team_key') team = Team.get(team_key) votes = Votes.for_user(users.get_current_user()) team.voted = (team.key() in votes.local_teams or team.key() in votes.teams) self.render('team', { 'team': team })