def register_for_competition(cid): """ Called when a user wants to register for a competition. All the user has to do is submit a post to this url with no form data. From their logged-in status, we'll go ahead and add them to the competiton as an individual (team name is default their display name). A 400 error will be returned if the user is already registered for the competition. If the user that is submitting this is an admin, they can optionally supply a json array of usernames to register for the competition. Specifying this will not register the admin, but it will register all users that are listed. A 400 error will be returned if any of the users are already registered for the competition. """ if database.session.query(Competition).filter( Competition.cid == cid).first() is None: return serve_error('Competition does not exist', response_code=404) if current_user.admin == 1 and 'users' in request.form: try: registrants = loads(request.form['users']) except ValueError: return serve_error( 'JSON data for \'users\' not properly formatted', response_code=400) else: registrants = [current_user.username] for user in registrants: if database.session.query(CompUser).filter( CompUser.cid == cid, CompUser.username == user ).first() is not None: return serve_error('User ' + user + ' already registered for ' 'competition', response_code=400) for username in registrants: user = database.session.query(User).filter( User.username == user).first() database.session.add( CompUser( cid=cid, username=user.username, team=user.display ) ) Flasknado.emit('new_user', { 'cid': cid, 'user': { 'display': user.display, 'username': user.username } }) database.session.flush() database.session.commit() return serve_response({})
def update_status(status, test_number): """Updates the status of the submission and notifies the clients that the submission has a new status. """ attempt.update_status(status) Flasknado.emit('status', { 'submissionId': attempt.job, 'problemId': attempt.pid, 'username': attempt.username, 'submitTime': attempt.submit_time, 'testNum': test_number, 'status': judge.EVENT_STATUS[status] })
def _update_status(self, status, test_number): """Updates the status of the submission and notifies the clients that the submission has a new status. """ self.submission.update_status(DB_STATUS[status]) Flasknado.emit('status', { 'submissionId': self.submission.job, 'problemId': self.submission.pid, 'username': self.submission.username, 'submitTime': self.submission.submit_time, 'testNum': test_number, 'status': EVENT_STATUS[status] })
def send_system_time(connection): Flasknado.send(connection, 'system_time', {'milliseconds': int(time() * 1000)})