:py:mod:`oioioi.problems.utils` =============================== .. py:module:: oioioi.problems.utils Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.problems.utils.FakeOriginInfoValue Functions ~~~~~~~~~ .. autoapisummary:: oioioi.problems.utils.can_add_problems oioioi.problems.utils.can_upload_problems oioioi.problems.utils.can_admin_problem oioioi.problems.utils.can_admin_instance_of_problem oioioi.problems.utils.can_admin_problem_instance oioioi.problems.utils.can_add_to_problemset oioioi.problems.utils.query_statement oioioi.problems.utils.query_zip oioioi.problems.utils.update_tests_from_main_pi oioioi.problems.utils.get_new_problem_instance oioioi.problems.utils.copy_problem_instance oioioi.problems.utils.generate_add_to_contest_metadata oioioi.problems.utils.generate_model_solutions_context oioioi.problems.utils.get_prefetched_value oioioi.problems.utils.show_proposal_form oioioi.problems.utils.filter_my_all_visible_submissions .. py:function:: can_add_problems(request) .. py:function:: can_upload_problems(request) .. py:function:: can_admin_problem(request, problem) 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. .. py:function:: can_admin_instance_of_problem(request, problem) 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. .. py:function:: can_admin_problem_instance(request, pi) .. py:function:: can_add_to_problemset(request) 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 .. py:function:: query_statement(problem_id) .. py:function:: query_zip(statement, path) .. py:function:: update_tests_from_main_pi(problem_instance, source_instance=None) 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 .. py:function:: get_new_problem_instance(problem, contest=None) Returns a deep copy of problem.main_problem_instance, with an independent set of test. Returned ProblemInstance is already saved and contains model solutions. .. py:function:: copy_problem_instance(pi, contest=None) Returns a deep copy of pi, with an independent set of test. Returned ProblemInstance is already saved and contains model solutions. .. py:function:: generate_add_to_contest_metadata(request) This generates all metadata needed for "add to contest" functionality in problemset. .. py:function:: generate_model_solutions_context(request, problem_instance) Generates context dictionary for model solutions view for "problem_instance"'s package. .. py:class:: FakeOriginInfoValue(category) Bases: :py:obj:`object` .. py:attribute:: value .. py:attribute:: order .. py:attribute:: cat .. py:method:: __eq__(other) Return self==value. .. py:method:: __hash__() Return hash(self). .. py:function:: get_prefetched_value(problem, category) 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. .. py:function:: show_proposal_form(problem, user) .. py:function:: filter_my_all_visible_submissions(request, queryset) 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.