oioioi.problems.utils

Module Contents

Classes

Functions

can_add_problems(request)

can_upload_problems(request)

can_admin_problem(request, problem)

Checks if the user can admin the given problem.

can_admin_instance_of_problem(request, problem)

Checks if the user has admin permission in a ProblemInstace

can_admin_problem_instance(request, pi)

can_add_to_problemset(request)

Returns True if request.user is authenticated and:

query_statement(problem_id)

query_zip(statement, path)

update_tests_from_main_pi(problem_instance[, ...])

Deletes all tests assigned to problem_instance

get_new_problem_instance(problem[, contest])

Returns a deep copy of problem.main_problem_instance,

copy_problem_instance(pi[, contest])

Returns a deep copy of pi,

generate_add_to_contest_metadata(request)

This generates all metadata needed for

generate_model_solutions_context(request, problem_instance)

Generates context dictionary for model solutions view

get_prefetched_value(problem, category)

Returns OriginInfoValue for the given Problem and OriginInfoCategory.

show_proposal_form(problem, user)

filter_my_all_visible_submissions(request, queryset)

Filters all solusion visible for the currently logged in user

oioioi.problems.utils.can_add_problems(request)[source]
oioioi.problems.utils.can_upload_problems(request)[source]
oioioi.problems.utils.can_admin_problem(request, problem)[source]

Checks if the user can admin the given problem.

The user can admin the given problem if at least one of the following is true: - the user can administer the problems database; - the user can administer the problem; - the user is the author of the problem; - the user can administer the contest where the problem was initially added.

The caller should guarantee that any of the given arguments is not None.

oioioi.problems.utils.can_admin_instance_of_problem(request, problem)[source]

Checks if the user has admin permission in a ProblemInstace of the given Problem. If request.contest is not None then ProblemInstaces from this contest are taken into account, problem.main_problem_instance otherwise.

If there is no ProblemInstace of problem in request.contest then the function returns False.

If the user has permission to admin problem then the function will always return True.

oioioi.problems.utils.can_admin_problem_instance(request, pi)[source]
oioioi.problems.utils.can_add_to_problemset(request)[source]

Returns True if request.user is authenticated and: EVERYBODY_CAN_ADD_TO_PROBLEMSET in settings.py is set on True or user is a teacher or user is a superuser or user is a database admin

oioioi.problems.utils.query_statement(problem_id)[source]
oioioi.problems.utils.query_zip(statement, path)[source]
oioioi.problems.utils.update_tests_from_main_pi(problem_instance, source_instance=None)[source]

Deletes all tests assigned to problem_instance and replaces them by new ones copied from source_instance, or - if not specified - main_problem_instance of appropiate Problem

oioioi.problems.utils.get_new_problem_instance(problem, contest=None)[source]

Returns a deep copy of problem.main_problem_instance, with an independent set of test. Returned ProblemInstance is already saved and contains model solutions.

oioioi.problems.utils.copy_problem_instance(pi, contest=None)[source]

Returns a deep copy of pi, with an independent set of test. Returned ProblemInstance is already saved and contains model solutions.

oioioi.problems.utils.generate_add_to_contest_metadata(request)[source]

This generates all metadata needed for “add to contest” functionality in problemset.

oioioi.problems.utils.generate_model_solutions_context(request, problem_instance)[source]

Generates context dictionary for model solutions view for “problem_instance“‘s package.

class oioioi.problems.utils.FakeOriginInfoValue(category)[source]

Bases: object

value[source]
order[source]
cat[source]
__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

oioioi.problems.utils.get_prefetched_value(problem, category)[source]

Returns OriginInfoValue for the given Problem and OriginInfoCategory.

You can’t filter the prefetched sets and since the OriginInfoValue set only has a few elements it should be faster to choose from all of them.

If there is no OriginInfoValue for this OriginInfoCategory and Problem, a fake object with .value == None and .order == infinity is returned.

Avoids database queries if and only if the problem was from a queryset on which prefetch_related(‘origininfovalue_set__category’) was called. If prefetching was impossible you should just filter instead.

oioioi.problems.utils.show_proposal_form(problem, user)[source]
oioioi.problems.utils.filter_my_all_visible_submissions(request, queryset)[source]

Filters all solusion visible for the currently logged in user from the given queryset. Returns the result as a queryset.

The filtering is not stable: the order of entries in the returned queryset may differ from the original.