oioioi.contests.urls
¶
Module Contents¶
Functions¶
|
Creates url patterns to be used in a custom urlconf. |
Attributes¶
- oioioi.contests.urls.make_patterns(neutrals=None, contests=None, noncontests=None, globs=None)[source]¶
Creates url patterns to be used in a custom urlconf.
Use this function when you create a custom urlconf, for example when writing tests. It will allow our
reverse()
function to run correctly when using this urlconf.DON’T use this function when defining patterns in your app’s urls.py file. Instead just define the following variables (though all of them are optional), and the file will be preprocessed by us:
contest_patterns
- these patterns will generate urls with prefix/c/<contest_id>/
and a request whose path matches such an url will have an attribute calledcontest
. For more information readCurrentContestMiddleware
’s documentation. Use this variable if your view needs needs a contest.urlpatterns
- these patterns will generate urls both with and without the prefix. If your view doesn’t depend on the contest or its behavior is conditional on the existence of a contest, you should use this variable (this should be the default choice).noncontest_patterns
- these patterns will generate urls without the prefix. Use this variable if you think that users accessing your views should not currently participate in any contest.
When creating a custom urlconf, you can use this function and each parameter (with one exception) represents one of the mentioned variables:
- Parameters
neutrals – represents
urlpatterns
contests – represents
contest_patterns
noncontests – represents
noncontest_patterns
globs – represents global url patterns - those defined in
oioioi.urls
. These urls won’t be prefixed by us with/c/<contest_id>/
, but they could already contain urls in this form. When you create your custom urlconf and you want to use all of the existing OIOIOI urls, you can use this param to pass them (e.g.:from oioioi import urls; make_patterns(..., globs=urls.urlpatterns)
)
Typically the function’s return value will be assigned to
urlpatterns
.