oioioi.contests.current_contest

Module Contents

Functions

get_cc_id()

set_cc_id(val)

reverse(target, *args, **kwargs)

A modified URL reverser that takes into account the current contest

patch()

Attributes

oioioi.contests.current_contest.ContestMode[source]
oioioi.contests.current_contest.cc_id[source]
oioioi.contests.current_contest.get_cc_id()[source]
oioioi.contests.current_contest.set_cc_id(val)[source]
oioioi.contests.current_contest.contest_re[source]
oioioi.contests.current_contest.reverse(target, *args, **kwargs)[source]

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 make_patterns() function.

oioioi.contests.current_contest.django_reverse[source]
oioioi.contests.current_contest.patch()[source]