示例#1
0
    def get_context_data(self, year, week, machine):
        """
        Create the context required for the given machine in the given week of the given year.
        The context also includes the year and week in case they changed.

        :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 for the reservation calendar
        """
        if not is_valid_week(year, week):
            year, week = get_next_week(year, week, 1)

        return {
            'week_days':
            self.get_week_days_with_reservations(year, week, machine),
            "week":
            week,
            "year":
            year,
            "machine":
            machine,
            "now":
            timezone.now(),
            "max_reservation_time":
            self.request.user.is_authenticated and Quota.get_quota_by_machine(
                machine.literal, self.request.user).max_time_reservation or 0
        }
示例#2
0
 def test_is_valid_week_with_to_high_week(self):
     self.assertFalse(is_valid_week(2017, 53))
示例#3
0
 def test_is_valid_week_with_valid_week(self):
     self.assertTrue(is_valid_week(2017, 51))
示例#4
0
 def test_is_valid_week_with_zero_week_number(self):
     self.assertFalse(is_valid_week(2017, 0))
示例#5
0
文件: calendar.py 项目: mahoyen/web
    def get_context_data(self, year, week, machine):
        """
        Create the context required for the given machine in the given week of the given year.
        The context also includes the year and week in case they changed.

        :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 for the reservation calendar
        """
        if not is_valid_week(year, week):
            year, week = get_next_week(year, week, 1)

        context = {
            'week_days':
            self.get_week_days_with_reservations(year, week, machine),
            "week":
            week,
            "year":
            year,
            "machine":
            machine,
            "now":
            timezone.now(),
            "max_reservation_time":
            1,
            "can_make_reservations":
            False,
            "can_make_more_reservations":
            False,
            "can_ignore_rules":
            "false",
            "rules": [{
                "periods": [[
                    day + rule.start_time.hour / 24 +
                    rule.start_time.minute / 1440,
                    (day + rule.days_changed + rule.end_time.hour / 24 +
                     rule.end_time.minute / 1440) % 7
                ] for day, _ in enumerate(bin(rule.start_days)[2:][::-1])
                            if _ == "1"],
                "max_hours":
                rule.max_hours,
                "max_hours_crossed":
                rule.max_inside_border_crossed,
            } for rule in ReservationRule.objects.filter(
                machine_type=machine.machine_type)]
        }

        if self.request.user.is_authenticated:
            context[
                "can_make_more_reservations"] = Quota.can_make_new_reservation(
                    self.request.user, machine.machine_type)
            context[
                "can_make_reservations"] = machine.machine_type.can_user_use(
                    self.request.user)
            context["can_ignore_rules"] = str(
                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))).lower()

        return context