:py:mod:`oioioi.contests.middleware` ==================================== .. py:module:: oioioi.contests.middleware Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.contests.middleware.CurrentContestMiddleware Functions ~~~~~~~~~ .. autoapisummary:: oioioi.contests.middleware.activate_contest .. py:function:: activate_contest(request, contest) .. py:class:: CurrentContestMiddleware(get_response) Bases: :py:obj:`object` Middleware which tracks the currently visited contest and stores it to be used in other parts of the current contest mechanism. It is assumed that all contest-specific url patterns are defined in the ``contest_patterns`` variable in each module's urlconf. These patterns are extended with non contest-specific patterns defined in the ``urlpatterns`` variable and then used to generate URLs prefixed with a contest ID (thus the non contest-specific URLs come in two versions, with and without a contest ID prefix). If a request matches a contest ID-prefixed URL and the ID is valid, the contest becomes the current contest. If the ID is not valid, a 404 Not Found is generated. After a contest becomes the current contest, the corresponding :class:`~oioioi.contests.models.Contest` instance is available in ``request.contest``. In addition to that, our custom :func:`~oioioi.contests.current_contest.reverse` function automatically prefixes generated URLs with the contest's ID if appropriate. Using ``settings.CONTEST_MODE``, the administrator may decide that users should, if possible, be forcibly put into a contest. Then, if there is no contest ID in a request's URL, but the URL also comes with a contest-specific version and a contest exists, a redirection is performed to one of the existing contests. Which one it is is determined by the following algorithm: #. If last contest is saved in session, this value is used. #. If the session value is not available or invalid, ``settings.DEFAULT_CONTEST`` is used. #. If not set, the most recently created contest will be chosen. URL patterns may be explicitly defined as requiring that no contest is given using the ``noncontest_patterns`` variable in each module's urlconf. Again, using ``settings.CONTEST_MODE``, the administrator may decide that if a contest is available, users cannot access those URLs. Trying to access them then generates a 403 Permission Denied unless one is a superuser. .. py:method:: __call__(request) .. py:method:: _get_contest(contest_id) .. py:method:: _process_request(request)