Exemplo n.º 1
0
    def get_next_available_selection_time_for_judge(self, judge):
        # type: (User) -> datetime

        today = DateTimeService.today()  # date
        now = DateTimeService.now()  # datetime

        next_time_due_to_max_per_day = \
            DateTimeService.next_midnight() if \
                Iotd.objects.filter(
                    judge=judge,
                    date=today).count() >= settings.IOTD_JUDGEMENT_MAX_PER_DAY \
                else now  # datetime

        latest_scheduled = Iotd.objects.filter(
            judge=judge).order_by('-date').first()  # Iotd
        next_time_due_to_max_scheduled_per_judge = \
            DateTimeService.next_midnight(latest_scheduled.date) if \
                Iotd.objects.filter(
                    judge=judge,
                    date__gt=today).count() >= settings.IOTD_JUDGEMENT_MAX_FUTURE_PER_JUDGE \
                else now

        next_time_due_to_max_scheduled = \
            DateTimeService.next_midnight() if \
                Iotd.objects.filter(date__gte=today).count() >= settings.IOTD_JUDGEMENT_MAX_FUTURE_DAYS \
            else now

        return max(next_time_due_to_max_per_day,
                   next_time_due_to_max_scheduled_per_judge,
                   next_time_due_to_max_scheduled)
Exemplo n.º 2
0
 def test_judge_cannot_select_now_reason_already_selected_today(self, now):
     now.return_value = datetime.now()
     iotd = self._create_iotd(date=date.today())
     reason = IotdService().judge_cannot_select_now_reason(iotd.judge)
     self.assertIsNotNone(reason)
     self.assertTrue('you already selected 1 IOTD today' in reason)
     self.assertEquals(
         IotdService().get_next_available_selection_time_for_judge(
             iotd.judge), DateTimeService.next_midnight())
Exemplo n.º 3
0
 def test_judge_cannot_select_now_reason_already_2_scheduled(self, now):
     now.return_value = datetime.now()
     iotd = self._create_iotd(date=date.today() + timedelta(1))
     self._create_iotd(judge=iotd.judge, date=date.today() + timedelta(2))
     reason = IotdService().judge_cannot_select_now_reason(iotd.judge)
     self.assertIsNotNone(reason)
     self.assertTrue('there are already 2 scheduled IOTDs' in reason)
     self.assertEquals(
         IotdService().get_next_available_selection_time_for_judge(
             iotd.judge), DateTimeService.next_midnight())