Esempio n. 1
0
 def can_see_round(self, request, round):
     if is_contest_admin(request):
         return True
     rtimes = self.get_round_times(request, round)
     if has_any_active_round(request):
         return rtimes.is_active(request.timestamp)
     return super(OIOnsiteContestController, self) \
             .can_see_round(request, round)
Esempio n. 2
0
    def can_see_round(self, request_or_context, round):
        """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.
        """
        context = self.make_context(request_or_context)
        if context.is_admin:
            return True

        rtimes = self.get_round_times(None, round)
        if has_any_active_round(context):
            return rtimes.is_active(context.timestamp)

        left, right = last_break_between_rounds(context)
        if left is not None and right is not None:
            last_break_time = right - left
            preparation_start = right - min(
                    timedelta(minutes=30),
                    last_break_time // 2
            )
            preparation_end = right
            if preparation_start < context.timestamp < preparation_end:
                return False

        return super(PastRoundsHiddenContestControllerMixin, self) \
                .can_see_round(request_or_context, round)
Esempio n. 3
0
    def can_see_round(self, request, round):
        """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.
        """

        if is_contest_admin(request):
            return True

        rtimes = self.get_round_times(request, round)
        if has_any_active_round(request):
            return rtimes.is_active(request.timestamp)

        left, right = last_break_between_rounds(request)
        if left is not None and right is not None:
            last_break_time = right - left
            preparation_start = right - min(
                    timedelta(minutes=30),
                    last_break_time // 2
            )
            preparation_end = right
            if preparation_start < request.timestamp < preparation_end:
                return False

        return super(PastRoundsHiddenContestControllerMixin, self) \
                .can_see_round(request, round)