Пример #1
0
    def get_week_days_with_reservations(year, week, machine):
        """
        Creates a list of the week days with reservation for the given year, week and machine

        :param year: The year the week is in
        :param week: The week to retrieve reservations for
        :param machine: The machine to retrieve reservations for
        :return: A list of week days with reservations
        """
        first_date_of_week = local_to_date(year_and_week_to_monday(year, week))

        return [{
            "date":
            date,
            "reservations":
            list(
                map(
                    lambda x: ReservationCalendarComponentView.
                    format_reservation(x, date),
                    machine.reservations_in_period(date,
                                                   date + timedelta(days=1))))
        } for date in [
            first_date_of_week + timedelta(days=day_number)
            for day_number in range(7)
        ]]
Пример #2
0
    def get_context_data(self, year, week, machine):
        """
        Create the context required for the controls and the information to be displayed

        :param year: The year to show the calendar for
        :param week: The week to show the calendar for
        :param machine: The machine object to show the calendar for
        :return: context required to show the reservation calendar with controls
        """
        context = super().get_context_data()
        context.update({
            "can_make_reservations":
            False,
            "can_make_more_reservations":
            False,
            "can_ignore_rules":
            False,
            "other_machines":
            Machine.objects.exclude(pk=machine.pk).filter(
                machine_type=machine.machine_type),
            "machine":
            machine,
            "year":
            year,
            "week":
            week,
            "date":
            year_and_week_to_monday(year, week),
        })

        if self.request.user.is_authenticated:
            context.update({
                "can_make_reservations":
                machine.machine_type.can_user_use(self.request.user),
                "can_make_more_reservations":
                Quota.can_make_new_reservation(self.request.user,
                                               machine.machine_type),
                "can_ignore_rules":
                any(
                    quota.can_make_more_reservations(self.request.user)
                    for quota in Quota.get_user_quotas(
                        self.request.user, machine.machine_type).filter(
                            ignore_rules=True))
            })

        return context
Пример #3
0
 def test_year_and_week_to_monday(self):
     date = datetime(2017, 12, 18)
     self.assertEqual(date, year_and_week_to_monday(2017, 51))
Пример #4
0
 def test_year_and_week_to_monday_start_of_year(self):
     date = datetime(2018, 12, 31)
     self.assertEqual(date, year_and_week_to_monday(2019, 1))