Esempio n. 1
0
    def test_validate_schedule(self):
        """Check the behaviour of validate schedule

           We also test check_schedule, since the logic of the two funcions
           is so similar it doesn't make sense to have a second test
           case for it."""
        day1 = ScheduleBlock.objects.create(
                start_time=D.datetime(2013, 9, 22, 9, 0, 0,
                                      tzinfo=timezone.utc),
                end_time=D.datetime(2013, 9, 22, 19, 0, 0,
                                    tzinfo=timezone.utc))
        venue1 = Venue.objects.create(order=1, name='Venue 1')
        venue1.blocks.add(day1)
        page = Page.objects.create(name="test page", slug="test")

        start1 = D.datetime(2013, 9, 22, 10, 0, 0, tzinfo=timezone.utc)
        start2 = D.datetime(2013, 9, 22, 11, 0, 0, tzinfo=timezone.utc)
        end = D.datetime(2013, 9, 22, 12, 0, 0, tzinfo=timezone.utc)

        slot1 = Slot.objects.create(start_time=start1, end_time=start2)
        slot2 = Slot.objects.create(start_time=start2, end_time=end)

        item1 = ScheduleItem.objects.create(venue=venue1,
                                            page_id=page.pk,
                                            details="Item 1")
        # Create an invalid item
        item2 = ScheduleItem.objects.create(venue=venue1, details="Item 2")
        # Create a simple venue/slot clash
        item1.slots.add(slot1)
        item2.slots.add(slot1)
        # Schedule shoudln't validate
        check_schedule.invalidate()
        self.assertFalse(check_schedule())
        # Invalid item & clash should be reported
        errors = validate_schedule()
        self.assertEqual(len(errors), 2)
        # Fix the invalid item
        item2.page_id = page.pk
        item2.save()
        # Schedule is still invalid, but only the clash remains
        check_schedule.invalidate()
        self.assertFalse(check_schedule())
        errors = validate_schedule()
        self.assertEqual(len(errors), 1)
        # Fix clashes
        item2.slots.remove(slot1)
        item2.slots.add(slot2)
        item2.save()
        # Schedule should now be valid
        check_schedule.invalidate()
        self.assertTrue(check_schedule())
        errors = validate_schedule()
        self.assertEqual(len(errors), 0)
Esempio n. 2
0
    def test_validate_schedule(self):
        """Check the behaviour of validate schedule

           We also test check_schedule, since the logic of the two funcions
           is so similar it doesn't make sense to have a second test
           case for it."""
        day1 = Day.objects.create(date=D.date(2013, 9, 22))
        venue1 = Venue.objects.create(order=1, name='Venue 1')
        venue1.days.add(day1)
        page = Page.objects.create(name="test page", slug="test")

        start1 = D.time(10, 0, 0)
        start2 = D.time(11, 0, 0)
        end = D.time(12, 0, 0)

        slot1 = Slot.objects.create(start_time=start1, end_time=start2,
                                    day=day1)
        slot2 = Slot.objects.create(start_time=start2, end_time=end,
                                    day=day1)

        item1 = ScheduleItem.objects.create(venue=venue1,
                                            page_id=page.pk,
                                            details="Item 1")
        # Create an invalid item
        item2 = ScheduleItem.objects.create(venue=venue1, details="Item 2")
        # Create a simple venue/slot clash
        item1.slots.add(slot1)
        item2.slots.add(slot1)
        # Schedule shoudln't validate
        check_schedule.invalidate()
        self.assertFalse(check_schedule())
        # Invalid item & clash should be reported
        errors = validate_schedule()
        self.assertEqual(len(errors), 2)
        # Fix the invalid item
        item2.page_id = page.pk
        item2.save()
        # Schedule is still invalid, but only the clash remains
        check_schedule.invalidate()
        self.assertFalse(check_schedule())
        errors = validate_schedule()
        self.assertEqual(len(errors), 1)
        # Fix clashes
        item2.slots.remove(slot1)
        item2.slots.add(slot2)
        item2.save()
        # Schedule should now be valid
        check_schedule.invalidate()
        self.assertTrue(check_schedule())
        errors = validate_schedule()
        self.assertEqual(len(errors), 0)
Esempio n. 3
0
    def get_context_data(self, day_id=None, **kwargs):
        context = super(ScheduleEditView, self).get_context_data(**kwargs)

        days = Day.objects.all()
        if day_id:
            day = days.get(id=day_id)
        else:
            day = days.first()

        public_talks = Talk.objects.filter(
            Q(status=ACCEPTED) | Q(status=CANCELLED))
        venues = Venue.objects.filter(days__in=[day])
        slots = Slot.objects.all().select_related(
            'day', 'previous_slot').prefetch_related('scheduleitem_set',
                                                     'slot_set').order_by(
                                                         'end_time',
                                                         'start_time', 'day')
        aggregated_slots = []

        for slot in slots:
            if day != slot.get_day():
                continue
            aggregated_slots.append(self._slot_context(slot, venues))

        context['day'] = day
        context['venues'] = venues
        context['slots'] = aggregated_slots
        context['talks_all'] = public_talks
        context['talks_unassigned'] = public_talks.filter(scheduleitem=None)
        context['pages'] = Page.objects.all()
        context['days'] = days
        context['validation_errors'] = validate_schedule()
        return context
Esempio n. 4
0
    def get_context_data(self, day_id=None, **kwargs):
        context = super(ScheduleEditView, self).get_context_data(**kwargs)

        days = Day.objects.all()
        if day_id:
            day = days.get(id=day_id)
        else:
            day = days.first()

        accepted_talks = Talk.objects.filter(status=ACCEPTED)
        venues = Venue.objects.filter(days__in=[day])
        slots = Slot.objects.all().select_related(
            'day', 'previous_slot').prefetch_related(
            'scheduleitem_set', 'slot_set').order_by(
                'end_time', 'start_time', 'day')
        aggregated_slots = []

        for slot in slots:
            if day != slot.get_day():
                continue
            aggregated_slots.append(self._slot_context(slot, venues))

        context['day'] = day
        context['venues'] = venues
        context['slots'] = aggregated_slots
        context['talks_all'] = accepted_talks
        context['talks_unassigned'] = accepted_talks.filter(scheduleitem=None)
        context['pages'] = Page.objects.all()
        context['days'] = days
        context['validation_errors'] = validate_schedule()
        return context
Esempio n. 5
0
    def get_context_data(self, block_id=None, **kwargs):
        context = super(ScheduleEditView, self).get_context_data(**kwargs)

        blocks = ScheduleBlock.objects.all()
        if block_id:
            block = blocks.get(id=block_id)
        else:
            block = blocks.first()

        public_talks = Talk.objects.filter(
            Q(status=ACCEPTED) | Q(status=CANCELLED))
        public_talks = public_talks.order_by("talk_type", "talk_id")
        venues = Venue.objects.filter(blocks__in=[block])
        slots = Slot.objects.all().select_related(
            'previous_slot').prefetch_related('scheduleitem_set',
                                              'slot_set').order_by(
                                                  'end_time', 'start_time')
        aggregated_slots = []

        for slot in slots:
            if block != slot.get_block():
                continue
            aggregated_slots.append(self._slot_context(slot, venues))

        context['this_block'] = block
        context['venues'] = venues
        context['slots'] = aggregated_slots
        context['talks_all'] = public_talks
        context['talks_unassigned'] = public_talks.filter(scheduleitem=None)
        context['pages'] = Page.objects.all()
        context['all_blocks'] = blocks
        context['validation_errors'] = validate_schedule()
        return context
Esempio n. 6
0
File: views.py Progetto: CTPUG/wafer
    def get_context_data(self, day_id=None, **kwargs):
        context = super(ScheduleEditView, self).get_context_data(**kwargs)

        days = Day.objects.all()
        if day_id:
            day = days.get(id=day_id)
        else:
            day = days.first()

        public_talks = Talk.objects.filter(Q(status=ACCEPTED) | Q(status=CANCELLED))
        venues = Venue.objects.filter(days__in=[day])
        slots = (
            Slot.objects.all()
            .select_related("day", "previous_slot")
            .prefetch_related("scheduleitem_set", "slot_set")
            .order_by("end_time", "start_time", "day")
        )
        aggregated_slots = []

        for slot in slots:
            if day != slot.get_day():
                continue
            aggregated_slots.append(self._slot_context(slot, venues))

        context["day"] = day
        context["venues"] = venues
        context["slots"] = aggregated_slots
        context["talks_all"] = public_talks
        context["talks_unassigned"] = public_talks.filter(scheduleitem=None)
        context["pages"] = Page.objects.all()
        context["days"] = days
        context["validation_errors"] = validate_schedule()
        return context