Пример #1
0
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
Пример #2
0
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