def import_contest(self, path): """Import a contest into the system, returning a dictionary that can be passed to Contest.import_from_dict(). """ params, tasks, users = self.get_params_for_contest(path) for i, task in enumerate(tasks): task_params = self.get_params_for_task(os.path.join(path, task), num=i) params["tasks"].append(task_params) if self.user_number is None: for user in users: user_params = self.get_params_for_user(user) params["users"].append(user_params) else: logger.info("Generating %s random users." % self.user_number) for i in xrange(self.user_number): user = User("User %d" % (i), "Last name %d" % (i), "user%03d" % (i)) if self.modif == 'test': user.password = '******' params["users"].append(user.export_to_dict()) return params
def add_user(contest_id, first_name, last_name, username, password, ip_address, email, hidden): with SessionGen(commit=True) as session: contest = Contest.get_from_id(contest_id, session) user = User(first_name=first_name, last_name=last_name, username=username, password=password, email=email, ip=ip_address, hidden=hidden, contest=contest) session.add(user)
def get_submissions(contest_id, submission_id=None, user_id=None, task_id=None): """Return a list of submission_ids restricted with the given information. We allow at most one of the parameters to be non-None. If all parameters are, we return all submissions for the given contest. contest_id (int): the id of the contest. submission_id (int): id of the submission to invalidate, or None. user_id (int): id of the user we want to invalidate, or None. task_id (int): id of the task we want to invalidate, or None. level (string): 'compilation' or 'evaluation' """ if [x is not None for x in [submission_id, user_id, task_id]].count(True) > 1: err_msg = "Too many arguments for invalidate_submission." logger.warning(err_msg) raise ValueError(err_msg) submission_ids = [] if submission_id is not None: submission_ids = [submission_id] elif user_id is not None: with SessionGen(commit=False) as session: user = User.get_from_id(user_id, session) submission_ids = [x.id for x in user.submissions] elif task_id is not None: with SessionGen(commit=False) as session: submissions = session.query(Submission)\ .join(Task).filter(Task.id == task_id) submission_ids = [x.id for x in submissions] else: with SessionGen(commit=False) as session: contest = session.query(Contest).\ filter_by(id=contest_id).first() submission_ids = [x.id for x in contest.get_submissions()] return submission_ids
def _on_auth(self, user_t): if not user_t: raise tornado.web.HTTPError(500, "Twitter auth failed") username = user_t["username"] user = self.sql_session.query(User)\ .filter(User.auth_type == "Twitter")\ .filter(User.contest == self.contest)\ .filter(User.username == username).first() if user is None: user = User(user_t["name"], "", username, auth_type="Twitter", contest=self.contest) self.sql_session.add(user) self.sql_session.commit() self.try_user_login(user)
def _on_login(self, user_t): if not user_t: raise tornado.web.HTTPError(500, "Facebook auth failed") username = user_t["id"] user = self.sql_session.query(User)\ .filter(User.auth_type == "Facebook")\ .filter(User.contest == self.contest)\ .filter(User.username == username).first() if user is None: user = User(user_t["first_name"], user_t["last_name"], username, auth_type="Facebook", contest=self.contest) self.sql_session.add(user) self.sql_session.commit() self.try_user_login(user)
def _on_auth(self, user_t): if not user_t: raise tornado.web.HTTPError(500, "Google auth failed") username = user_t["email"] user = self.sql_session.query(User)\ .filter(User.auth_type == "Google")\ .filter(User.contest == self.contest)\ .filter(User.username == username).first() filtered_user = filter_ascii(username) if user is None: user = User(user_t["first_name"], user_t["last_name"], username, email=user_t["email"], auth_type="Google", contest=self.contest) self.sql_session.add(user) self.sql_session.commit() self.try_user_login(user)