:py:mod:`oioioi.problems.controllers` ===================================== .. py:module:: oioioi.problems.controllers Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.problems.controllers.ProblemController Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.problems.controllers.logger .. py:data:: logger .. py:class:: ProblemController(problem) Bases: :py:obj:`oioioi.base.utils.RegisteredSubclassesBase`, :py:obj:`oioioi.base.utils.ObjectWithMixins` Defines rules for handling specific problem. Every method should: * be called from contest controller * or be specific for problems that this controller controls Please note that a global problem instance exists for each problem. That problem instance has no contest (``contest`` is ``None``), so methods can't be overridden by a contest controller which means they behave in a default way. .. py:attribute:: modules_with_subclasses :annotation: = ['controllers'] .. py:attribute:: abstract :annotation: = True .. py:method:: adjust_problem() Called whan a (usually new) problem has just got the controller attached or after the problem has been modified. .. py:method:: get_default_submission_kind(request, problem_instance) Returns default kind of newly created submission by the current user. The default implementation returns ``'IGNORED'`` for problem admins. In other cases it returns ``'NORMAL'``. .. py:method:: get_submissions_limit(request, problem_instance, kind='NORMAL') .. py:method:: can_submit(request, problem_instance, check_round_times=True) Determines if the current user is allowed to submit a solution for the given problem. The default implementation checks if the user is not anonymous. Subclasses should also call this default implementation. .. py:method:: is_submissions_limit_exceeded(request, problem_instance, kind) .. py:method:: get_submissions_left(request, problem_instance, kind='NORMAL') Returns number of submissions left until reaching problem limit .. py:method:: fill_evaluation_environ(environ, submission, **kwargs) :abstractmethod: Fills a minimal environment with evaluation receipt and other values required by the evaluation machinery. Passed ``environ`` should already contain entries for the actiual data to be judged (for example the source file to evaluate). Details on which keys need to be present should be specified by particular subclasses. As the result, ``environ`` will be filled at least with a suitable evaluation ``recipe``. .. py:method:: finalize_evaluation_environment(environ) This method gets called right before the environ becomes scheduled in the queue. It gets called only for submissions send without a contest This hook exists for inserting extra handlers to the recipe before judging the solution. .. py:method:: judge(submission, extra_args=None, is_rejudge=False) .. py:method:: mixins_for_admin() Returns an iterable of mixins to add to the default :class:`oioioi.problems.admin.ProblemAdmin` for this particular problem. The default implementation returns an empty tuple. .. py:method:: update_user_result_for_problem(result) Updates a :class:`~oioioi.contests.models.UserResultForProblem`. Usually this involves looking at submissions and aggregating scores from them. Default implementation takes the latest submission which has a score and copies it to the result. Saving the ``result`` is a responsibility of the caller. .. py:method:: update_problem_statistics(problem_statistics, user_statistics, submission) Updates :class:`~oioioi.problems.models.ProblemStatistics` and :class:`~oioioi.problems.models.UserStatistics` with data from a new :class:`~oioioi.contests.models.Submission`. This is called when a new submission is checked, and for performance reasons performs as few database queries as possible. The default implementation only checks the submission report kind, and retrieves the score report for the submission. By default, only ACTIVE and NORMAL submissions are counted for statistics. If you change this behaviour make sure to also update :func:`~oioioi.problems.controllers.ProblemController.change_submission_kind`. Saving both statistics objects is a responsibility of the caller. .. py:method:: recalculate_statistics_for_user(user) Recalculates user's statistics for this problem controller's problem Sometimes (for example when a submission's type changes) we can't update user statistics quickly, and need to recalculate them. This function by default erases the user statistics for the problem and recalculates them from all of this user's submissions to every probleminstance of the problem. .. py:method:: recalculate_statistics_on_submission_deleted(instance, **kwargs) :staticmethod: .. py:method:: _activate_newest_report(submission, queryset, kind=None) Activates the newest report. Previously active reports are set to ``SUPERSEDED``. Reports which are neither ``INACTIVE``, ``ACTIVE`` nor ``SUPERSEDED`` are not changed. :ptype kind: str, list, tuple or ``None`` :param kind: If specified, only reports of the given kind(s) will be considered. .. py:method:: update_report_statuses(submission, queryset) Updates statuses of reports for the newly judged submission. Usually this involves looking at reports and deciding which should be ``ACTIVE`` and which should be ``SUPERSEDED``. :param submission: an instance of :class:`oioioi.contests.models.Submission` :param queryset: a queryset returning reports for the submission .. py:method:: update_user_results(user, problem_instance) Updates score for problem instance. Usually this method creates instances (if they don't exist) of: * :class:`~oioioi.contests.models.UserResultForProblem` and then calls proper methods of ProblemController to update them. .. py:method:: validate_submission_form(request, problem_instance, form, cleaned_data) .. py:method:: adjust_submission_form(request, form, problem_instance) .. py:method:: create_submission(request, problem_instance, form_data, **kwargs) :abstractmethod: .. py:method:: render_submission_date(submission, shortened=False) Returns a human-readable representation of the submission date. In some contests it is more reasonable to show time elapsed since the contest start, in others it's better to just show the wall clock time. The default implementation returns the wall clock time. .. py:method:: render_submission_score(submission) Returns a human-readable representation of the submission score. The default implementation returns the Unicode representation of ``submission.score``. .. py:method:: get_supported_extra_args(submission) Returns dict of all values which can be provided in extra_args argument to the judge method. .. py:method:: render_submission_footer(request, submission) Renders the given submission footer to HTML. Footer is shown under the submission reports. The default implementation returns an empty string. .. py:method:: render_report(request, report) Renders the given report to HTML. Default implementation supports only rendering reports of kind ``FAILURE`` and raises :py:exc:`NotImplementedError` otherwise. .. py:method:: filter_visible_reports(request, submission, queryset) Determines which reports the user should be able to see. It needs to check whether the submission is visible to the user and submission is submitted without contest. :param request: Django request :param submission: instance of :class:`~oioioi.contests.models.Submission` :param queryset: a queryset, initially filtered at least to select only given submission's reports :returns: updated queryset .. py:method:: valid_kinds_for_submission(submission) Returns list of all valid kinds we can change to for the given submission. Default implementation supports only kinds ``NORMAL``, ``IGNORED``, ``SUSPECTED``, 'IGNORED_HIDDEN'. .. py:method:: results_visible(request, submission) Determines whether it is a good time to show the submission's results. This method is not used directly in any code outside of the controllers. It's a helper method used in a number of other controller methods, as described. The default implementations returns ``True``. .. py:method:: can_see_submission_status(request, submission) Determines whether a user can see one of his/her submissions' status. Default implementation delegates to :meth: :meth:`~ProblemInstanceController.results_visible`. :rtype: bool .. py:method:: can_see_submission_score(request, submission) Determines whether a user can see one of his/her submissions' score. Default implementation delegates to :meth: :meth:`~ProblemInstanceController.results_visible`. :rtype: bool .. py:method:: can_see_submission_comment(request, submission) Determines whether a user can see one of his/her submissions' comment. Default implementation delegates to :meth: :meth:`~ProblemInstanceController.results_visible`. :rtype: bool .. py:method:: change_submission_kind(submission, kind) Changes kind of the submission, updates user reports for problem, round and contest which may contain given submission, and updates statistics for the submission's user if necessary. .. py:method:: _is_partial_score(test_report) .. py:method:: filter_my_visible_submissions(request, queryset, filter_user=True) Returns the submissions which the user should see in the problemset in "My submissions" view. The default implementation returns all submissions belonging to the user for current problem except for author, who gets all his submissions. Should return the updated queryset. .. py:method:: get_extra_problem_site_actions(problem) Returns a list of tuples (url, name) that will be displayed under actions in ProblemSite. .. py:method:: supports_problem_statement() If the ProblemController supports problem statement, opening the problem in a contest shows the associated problem statement or an information that it doesn't have one. On the other hand, if it doesn't support the problem statement, opening the problem redirects to submit solution page. .. py:method:: get_notification_message_submission_judged(submission) Returns a message to show in a notification when a submission has been judged. It doesn't validate any permissions.