:py:mod:`oioioi.rankings.controllers` ===================================== .. py:module:: oioioi.rankings.controllers Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.rankings.controllers.RankingMixinForContestController oioioi.rankings.controllers.RankingController oioioi.rankings.controllers.DefaultRankingController Functions ~~~~~~~~~ .. autoapisummary:: oioioi.rankings.controllers.update_rankings_with_user_callback Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.rankings.controllers.CONTEST_RANKING_KEY .. py:data:: CONTEST_RANKING_KEY :annotation: = c .. py:class:: RankingMixinForContestController Bases: :py:obj:`object` ContestController mixin that sets up rankings app. .. py:method:: ranking_controller() Return the actual :class:`RankingController` for the contest. .. py:method:: update_user_results(user, problem_instance, *args, **kwargs) .. py:class:: RankingController(contest) Bases: :py:obj:`oioioi.base.utils.RegisteredSubclassesBase`, :py:obj:`oioioi.base.utils.ObjectWithMixins` Ranking system uses two types of keys: "partial key"s and "full key"s. Please note that full keys are abbreviated in the code as "key"s. A pair (request, partial_key) should allow to build a full key, while a partial_key can always be extracted from the full key. partial keys identify the rounds to display and are used everywhere outside controllers and rankingsd (e.g. in views and urls). However, the actual ranking contents can depend on many other factors, like user permissions. This was the reason for introduction of full keys, which are always sufficient to choose the right data for serialization and display. .. py:attribute:: modules_with_subclasses :annotation: = ['controllers'] .. py:attribute:: abstract :annotation: = True .. py:attribute:: PERMISSION_CHECKERS .. py:method:: get_partial_key(key) Extracts partial key from a full key. .. py:method:: replace_partial_key(key, new_partial) Replaces partial key in a full key .. py:method:: get_full_key(request, partial_key) Returns a full key associated with request and partial_key .. py:method:: _key_permission(key) Returns a permission level associated with given full key .. py:method:: is_admin_key(key) Returns true if a given full key corresponds to users with administrative permissions. .. py:method:: available_rankings(request) :abstractmethod: Returns a list of available rankings. Each ranking is a pair ``(key, description)``. .. py:method:: can_search_for_users() Determines if in this ranking, searching for users is enabled. .. py:method:: find_user_position(request, partial_key, user) :abstractmethod: Returns user's position in the ranking. User should be an object of class User, not a string with username. If user is not in the ranking, None is returned. .. py:method:: get_rendered_ranking(request, partial_key) Retrieves ranking generated by rankingsd. You should never override this function. It will be responsible for communication with rankingsd and use render_ranking for actual HTML generation. Feel free to override render_ranking to customize its logic. If the ranking is still being generated, or the user requested an invalid page, displays an appropriate message. .. py:method:: get_serialized_ranking(key) .. py:method:: build_ranking(key) Serializes data and renders html for given key. Results are processed using serialize_ranking, and then as many pages as needed are rendered. Returns a tuple containing serialized data and a list of strings, that are html code of ranking pages. .. py:method:: _fake_request(page) Creates a fake request used to render ranking. Pagination engine requires access to request object, so it can extract page number from GET parameters. .. py:method:: _render_ranking_page(key, data, page) :abstractmethod: .. py:method:: render_ranking_to_csv(request, partial_key) :abstractmethod: .. py:method:: serialize_ranking(key) :abstractmethod: Returns some data (representing ranking). This data will be used by :meth:`render_ranking` to generate the html code. .. py:class:: DefaultRankingController(contest) Bases: :py:obj:`RankingController` Ranking system uses two types of keys: "partial key"s and "full key"s. Please note that full keys are abbreviated in the code as "key"s. A pair (request, partial_key) should allow to build a full key, while a partial_key can always be extracted from the full key. partial keys identify the rounds to display and are used everywhere outside controllers and rankingsd (e.g. in views and urls). However, the actual ranking contents can depend on many other factors, like user permissions. This was the reason for introduction of full keys, which are always sufficient to choose the right data for serialization and display. .. py:attribute:: description .. py:method:: _iter_rounds(can_see_all, timestamp, partial_key, request=None) .. py:method:: _rounds_for_ranking(request, partial_key=CONTEST_RANKING_KEY) .. py:method:: _rounds_for_key(key) .. py:method:: available_rankings(request) Returns a list of available rankings. Each ranking is a pair ``(key, description)``. .. py:method:: can_search_for_users() Determines if in this ranking, searching for users is enabled. .. py:method:: find_user_position(request, partial_key, user) Returns user's position in the ranking. User should be an object of class User, not a string with username. If user is not in the ranking, None is returned. .. py:method:: _render_ranking_page(key, data, page) .. py:method:: _get_csv_header(key, data) .. py:method:: _get_csv_row(key, row) .. py:method:: render_ranking_to_csv(request, partial_key) .. py:method:: filter_users_for_ranking(key, queryset) .. py:method:: _filter_pis_for_ranking(partial_key, queryset) .. py:method:: _allow_zero_score() .. py:method:: _get_users_results(pis, results, rounds, users) .. py:method:: _assign_places(data, extractor) Assigns places to the serialized ranking ``data``. Extractor should return values by which users should be ordered in the ranking. Users with the same place should have same value returned. .. py:method:: _is_problem_statement_visible(key, pi, timestamp) .. py:method:: _get_pis_with_visibility(key, pis) .. py:method:: serialize_ranking(key) Returns some data (representing ranking). This data will be used by :meth:`render_ranking` to generate the html code. .. py:function:: update_rankings_with_user_callback(sender, user, **kwargs)