oioioi.contests.controllers

Module Contents

Classes

RegistrationController

A base class for classes which should have a list of subclasses

PublicContestRegistrationController

A base class for classes which should have a list of subclasses

ContestControllerContext

ContestController

Contains the contest logic and rules.

PastRoundsHiddenContestControllerMixin

ContestController mixin that hides past rounds

NotificationsMixinForContestController

Sets default contest notification settings.

ProblemUploadingContestControllerMixin

ContestController mixin that declares empty methods for extending

Functions

export_entries(registry, values)

submission_template_context(request, submission)

Attributes

oioioi.contests.controllers.logger[source]
oioioi.contests.controllers.export_entries(registry, values)[source]
oioioi.contests.controllers.submission_template_context(request, submission)[source]
class oioioi.contests.controllers.RegistrationController(contest)[source]

Bases: oioioi.base.utils.RegisteredSubclassesBase, oioioi.base.utils.ObjectWithMixins

A base class for classes which should have a list of subclasses available.

The list of subclasses is available in their subclasses class attributes. Classes which have explicitly set abstract class attribute to True are not added to subclasses.

If a class has modules_with_subclasses attribute (list or string), then specified modules for all installed applications can be loaded by calling load_subclasses().

can_enter_contest(request)[source]

Determines if the current user is allowed to enter the contest, i.e. see any page related to the contest.

The default implementation uses filter_visible_contests() with a single-element contest queryset.

Return type

bool

visible_contests_query(request)[source]

Provides a django.db.models.Q expression which can be used on oioioi.contests.models.Contest queryset already limited to contests using this controller to filter for contests the user can enter.

It must not make use of attribute contest of the controller, as it is not guaranteed to be set. It is called with None contest in :function:`oioioi.contests.utils.visible_contests`.

abstract user_contests_query(request)[source]

Provides a django.db.models.Q expression which can be used on oioioi.contests.models.Contest queryset already limited to contests using this controller to filter for contests the user has entered.

It must not make use of attribute contest of the controller, as it is not guaranteed to be set. It is called with None contest in :function:`oioioi.contests.utils.visible_contests`.

filter_visible_contests(request, contest_queryset)[source]

Filters a queryset of oioioi.contests.models.Contest leaving only contests that the user can enter.

contest_queryset should contain only contests that use a oioioi.contests.controllers.RegistrationController subclass which filter_visible_contests() is being called.

For non-anonymous users default implementation checks their permissions and returns a union with what is returned from filter_user_contests(). For anonymous, checks anonymous_can_enter_contest().

Return type

QuerySet

filter_user_contests(request, contest_queryset)[source]

Filters a queryset of oioioi.contests.models.Contest leaving only contests that the user has entered.

contest_queryset should contain only contests that use a oioioi.base.controllers.RegistractionController subclass which filter_user_contests() is being called.

Return type

QuerySet

abstract classmethod anonymous_can_enter_contest()[source]

Determines if an anonymous user can enter the contest.

Allowed anonymous users will have limited functionality, but they can see the problems, review questions etc. Modules should give them as much functionality as reasonably possible.

Return type

bool

abstract filter_participants(queryset)[source]

Filters the queryset of User to select only users which have access to the contest.

no_entry_view(request)[source]

View rendered when a user would like to perform an action not allowed by this registration controller.

This may be a good place to put a redirection to a registration page etc.

The default implementation just raises PermissionDenied.

mixins_for_admin()[source]

Returns an iterable of mixins to add to the default oioioi.contests.admin.ContestAdmin for the contest.

The default implementation returns an empty tuple.

get_contest_participant_info_list(request, user)[source]

Returns a list of tuples (priority, info). Each entry represents a fragment of HTML with information about the user’s participation in the contest. This information will be visible for contest admins. It can be any information an application wants to add.

The fragments are sorted by priority (descending) and rendered in that order.

The default implementation returns basic info about the contestant: his/her full name, e-mail, the user id, his/her submissions and round time extensions.

To add additional info from another application, override this method. For integrity, include the result of the parent implementation in your output.

abstract filter_users_with_accessible_personal_data(queryset)[source]

Filters the queryset of User to select only users whose personal data is accessible to the admins.

class oioioi.contests.controllers.PublicContestRegistrationController(contest)[source]

Bases: RegistrationController

A base class for classes which should have a list of subclasses available.

The list of subclasses is available in their subclasses class attributes. Classes which have explicitly set abstract class attribute to True are not added to subclasses.

If a class has modules_with_subclasses attribute (list or string), then specified modules for all installed applications can be loaded by calling load_subclasses().

description[source]
can_enter_contest(request)[source]

Determines if the current user is allowed to enter the contest, i.e. see any page related to the contest.

The default implementation uses filter_visible_contests() with a single-element contest queryset.

Return type

bool

classmethod anonymous_can_enter_contest()[source]

Determines if an anonymous user can enter the contest.

Allowed anonymous users will have limited functionality, but they can see the problems, review questions etc. Modules should give them as much functionality as reasonably possible.

Return type

bool

visible_contests_query(request)[source]

Provides a django.db.models.Q expression which can be used on oioioi.contests.models.Contest queryset already limited to contests using this controller to filter for contests the user can enter.

It must not make use of attribute contest of the controller, as it is not guaranteed to be set. It is called with None contest in :function:`oioioi.contests.utils.visible_contests`.

user_contests_query(request)[source]

Provides a django.db.models.Q expression which can be used on oioioi.contests.models.Contest queryset already limited to contests using this controller to filter for contests the user has entered.

It must not make use of attribute contest of the controller, as it is not guaranteed to be set. It is called with None contest in :function:`oioioi.contests.utils.visible_contests`.

filter_participants(queryset)[source]

Filters the queryset of User to select only users which have access to the contest.

filter_users_with_accessible_personal_data(queryset)[source]

Filters the queryset of User to select only users whose personal data is accessible to the admins.

class oioioi.contests.controllers.ContestControllerContext(contest, timestamp, is_admin)[source]

Bases: object

class oioioi.contests.controllers.ContestController(contest)[source]

Bases: oioioi.base.utils.RegisteredSubclassesBase, oioioi.base.utils.ObjectWithMixins

Contains the contest logic and rules.

This is the computerized implementation of the contest’s official rules.

modules_with_subclasses = ['controllers'][source]
abstract = True[source]
registration_controller()[source]
make_context(request_or_context)[source]
default_view(request)[source]

Determines the default landing page for the user from the passed request.

The default implementation returns the list of problems.

get_contest_participant_info_list(request, user)[source]

Returns a list of tuples (priority, info). Each entry represents a fragment of HTML with information about the user’s participation in the contest. This information will be visible for contest admins. It can be any information an application wants to add.

The fragments are sorted by priority (descending) and rendered in that order.

The default implementation returns basic info about the contestant: his/her full name, e-mail, the user id, his/her submissions and round time extensions.

To add additional info from another application, override this method. For integrity, include the result of the parent implementation in your output.

get_user_public_name(request, user)[source]

Returns the name of the user to be displayed in public contest views.

The default implementation returns the user’s full name or username if the former is not available.

get_round_times(request, round)[source]

Determines the times of the round for the user doing the request.

The default implementation returns an instance of RoundTimes cached by round_times() method.

Round must belong to request.contest. Request is optional (round extensions won’t be included if omitted).

Returns

an instance of RoundTimes

separate_public_results()[source]

Determines if there should be two separate dates for personal results (when participants can see their scores for a given round) and public results (when round ranking is published).

Depending on the value returned, contest admins can see and modify both Results date and Public results date or only the first one.

Return type

bool

order_rounds_by_focus(request, queryset=None)[source]

Sorts the rounds in the queryset according to probable user’s interest.

The algorithm works as follows (roughly):

  1. If a round starts or ends in 10 minutes or less or started less than a minute ago, it’s prioritized.

1. Then active rounds are appended. 1. If a round starts in less than 6 hours or has ended in less

than 1 hour, it’s appended.

1. Then come past rounds. 1. Then other future rounds.

See the implementation for corner cases.

Parameters
  • request – the Django request

  • queryset – the set of Round instances to sort or None to return all rounds of the controller’s contest

can_see_round(request_or_context, round)[source]

Determines if the current user is allowed to see the given round.

If not, everything connected with this round will be hidden.

The default implementation checks if the round is not in the future.

can_see_ranking(request_or_context)[source]

Determines if the current user is allowed to see the ranking.

The default implementation checks if there exists a ranking visibility config for current contest and checks if ranking visibility is enabled. If there is no ranking visibility config for current contest or option ‘AUTO’ is chosen, returns default value (calls default_can_see_ranking())

default_can_see_ranking(request_or_context)[source]
can_see_problem(request_or_context, problem_instance)[source]

Determines if the current user is allowed to see the given problem.

If not, the problem will be hidden from all lists, so that its name should not be visible either.

The default implementation checks if the user can see the given round (calls can_see_round()).

can_see_statement(request_or_context, problem_instance)[source]

Determines if the current user is allowed to see the statement for the given problem.

The default implementation checks if there exists a problem statement config for current contest and checks if statements’ visibility is enabled. If there is no problem statement config for current contest or option ‘AUTO’ is chosen, returns default value (calls default_can_see_statement())

default_can_see_statement(request_or_context, problem_instance)[source]
can_submit(request, problem_instance, check_round_times=True)[source]

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, and if the round is active for the given user. Subclasses should also call this default implementation.

get_default_submission_kind(request, **kwargs)[source]

Returns default kind of newly created submission by the current user.

The default implementation returns 'IGNORED' for non-contestants. In other cases it returns 'NORMAL'.

get_submissions_limit(request, problem_instance, kind='NORMAL')[source]
get_submissions_left(request, problem_instance, kind=None)[source]
is_submissions_limit_exceeded(request, problem_instance, kind=None)[source]
adjust_submission_form(request, form, problem_instance)[source]
validate_submission_form(request, problem_instance, form, cleaned_data)[source]
create_submission(request, problem_instance, form_data, **kwargs)[source]
judge(submission, extra_args=None, is_rejudge=False)[source]
fill_evaluation_environ(environ, submission)[source]
get_supported_extra_args(submission)[source]

Returns dict of all values which can be provided in extra_args argument to the judge method.

finalize_evaluation_environment(environ)[source]

This method gets called right before the environ becomes scheduled in the queue.

This hook exists for inserting extra handlers to the recipe before judging the solution.

submission_judged(submission, rejudged=False)[source]
_activate_newest_report(submission, queryset, kind=None)[source]
update_report_statuses(submission, queryset)[source]
update_submission_score(submission)[source]

Updates status, score and comment in a submission.

Usually this involves looking at active reports and aggregating information from them.

update_user_result_for_problem(result)[source]
update_problem_statistics(problem_statistics, user_statistics, submission)[source]
_sum_scores(scores)[source]
update_user_result_for_round(result)[source]

Updates a UserResultForRound.

Usually this involves looking at user’s results for problems and aggregating scores from them. Default implementation sums the scores.

Saving the result is a responsibility of the caller.

update_user_result_for_contest(result)[source]

Updates a UserResultForContest.

Usually this involves looking at user’s results for rounds and aggregating scores from them. Default implementation sums the scores.

Saving the result is a responsibility of the caller.

update_user_results(user, problem_instance)[source]

Updates score for problem instance, round and contest.

Usually this method creates instances (if they don’t exist) of: * UserResultForProblem * UserResultForRound * UserResultForContest

and then calls proper methods of ContestController to update them.

filter_my_visible_submissions(request, queryset, filter_user=True)[source]

Returns the submissions which the user should see in the “My submissions” view.

The default implementation returns all submissions belonging to the user for the problems that are visible, except for admins, which get all their submissions.

Should return the updated queryset.

results_visible(request, submission)[source]

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 uses the round’s results_date. If it’s None, results are not available. Admins are always shown the results.

filter_visible_reports(request, submission, queryset)[source]

Determines which reports the user should be able to see.

It need not check whether the submission is visible to the user.

The default implementation uses results_visible().

Parameters
  • request – Django request

  • submission – instance of Submission

  • queryset – a queryset, initially filtered at least to select only given submission’s reports

Returns

updated queryset

can_see_submission_status(request, submission)[source]
can_see_submission_score(request, submission)[source]
can_see_submission_comment(request, submission)[source]
render_submission_date(submission, shortened=False)[source]
render_submission_score(submission)[source]
abstract render_submission(request, submission)[source]

Renders the given submission to HTML.

This is usually a table with some basic submission info, source code download etc., displayed on the top of the submission details view, above the reports.

render_report(request, report)[source]
render_my_submissions_header(request, submissions)[source]

Renders header on “My submissions” view.

Default implementation returns empty string.

adjust_contest()[source]

Called when a (usually new) contest has just got the controller attached or after the contest has been modified.

valid_kinds_for_submission(submission)[source]
change_submission_kind(submission, kind)[source]
mixins_for_admin()[source]

Returns an iterable of mixins to add to the default oioioi.contests.admin.ContestAdmin for this particular contest.

The default implementation returns an empty tuple.

is_onsite()[source]

Determines whether the contest is on-site.

send_email(subject, body, recipients, headers=None)[source]

Send an email about something related to this contest (e.g. a submission confirmation). From: is set to DEFAULT_FROM_EMAIL, Reply-To: is taken from the Contact email contest setting

and defaults to the value of From:.

_is_partial_score(test_report)[source]
show_default_fields(problem_instance)[source]
class oioioi.contests.controllers.PastRoundsHiddenContestControllerMixin[source]

Bases: object

ContestController mixin that hides past rounds if another round is starting soon.

The period when the past rounds are hidden is called round’s preparation time.

Do not use it with overlapping rounds.

can_see_round(request_or_context, round)[source]

Decides whether the given round should be shown for the given user. The algorithm is as follows:

1. Round is always visible for contest admins. 1. If any round is active, all active rounds are visible,

all other rounds are hidden.

  1. Let

    break_start = latest end_date of any past round break_end = closest start_date of any future round break_time = break_end - break_start

    then preparation_time is the last 30 minutes of the break, or if the break is shorter then just its second half.

1. During the preparation_time all rounds should be hidden. 1. Otherwise the decision is made by the superclass method.

class oioioi.contests.controllers.NotificationsMixinForContestController[source]

Bases: object

Sets default contest notification settings.

users_to_receive_public_message_notification()[source]

Decide if all users particiapting in a contest should be notified about a new global message.

This should be disabled for contest with many users because of performance reasons - for each user, a single query to database is executed while sending a notification.

get_notification_message_submission_judged(submission)[source]

Returns a message to show in a notification when a submission has been judged. It doesn’t validate any permissions.

class oioioi.contests.controllers.ProblemUploadingContestControllerMixin[source]

Bases: object

ContestController mixin that declares empty methods for extending problem uploading process.

adjust_upload_form(request, existing_problem, form)[source]

Adjusts the problem upload form created by some subclass of PackageSource.

Called from view().

fill_upload_environ(request, form, env)[source]

Extends the env dictionary used during problem uploading.

Called from view().