:py:mod:`oioioi.contests.current_contest` ========================================= .. py:module:: oioioi.contests.current_contest Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: oioioi.contests.current_contest.get_cc_id oioioi.contests.current_contest.set_cc_id oioioi.contests.current_contest.reverse oioioi.contests.current_contest.patch Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.contests.current_contest.ContestMode oioioi.contests.current_contest.cc_id oioioi.contests.current_contest.contest_re oioioi.contests.current_contest.django_reverse .. py:data:: ContestMode .. py:data:: cc_id .. py:function:: get_cc_id() .. py:function:: set_cc_id(val) .. py:data:: contest_re .. py:function:: reverse(target, *args, **kwargs) A modified URL reverser that takes into account the current contest and generates URLs that are appropriately prefixed. With it we substitute the original ``urls.reverse`` function. The choice of prefixing the URL with a particular contest ID (or not prefixing at all) by the function is made as follows: * If a ``contest_id`` kwarg is given which is not None then the URL, if successfully reversed, is prefixed with it. * If a ``contest_id`` kwarg equal to None is given then the URL, if successfully reversed, will not be prefixed. * If the kwarg isn't given but a contest is active when calling the function then that contest is used for the generated URL. * If the above fails or there is no active contest then no contest will be used. Our reverser uses the special structure of each app's urls.py file: * Urls pointing to views that require a contest are defined in the ``contest_patterns`` pattern list. Those only have a contest-prefixed version. * Urls pointing to views that require no contest being active are defined in the ``noncontest_patterns`` pattern list. Those only have a non contest-prefixed version. * Urls pointing to views that can run both with and without current contest are defined in the ``urlpatterns`` pattern list. Those have both versions. These files are preprocessed to be used by the reverser. Urls defined in ``oioioi.urls`` are not preprocessed, so they only have a non-prefixed version, even though they could exist within a contest. Note that there is no point defining patterns that receive a ``contest_id`` kwarg. That particular kwarg is interpreted differently and will never be actually matched in the url pattern when reversing. You need to take into account the behavior of reverse when defining your own custom urlconf (that means patterns lying outside an app's urls.py file, e.g. for testing purposes), because it won't be preprocessed. For that we created the :func:`~oioioi.contests.urls.make_patterns` function. .. py:data:: django_reverse .. py:function:: patch()