コード例 #1
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(year, week, machine)
        context["next"] = get_next_week(context["year"], context["week"], 1)
        context["prev"] = get_next_week(context["year"], context["week"], -1)
        context["machine_types"] = Machine.__subclasses__()

        return context
コード例 #2
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
        }
コード例 #3
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(year, week, machine)
        context["next"] = get_next_week(context["year"], context["week"], 1)
        context["prev"] = get_next_week(context["year"], context["week"], -1)
        context["machine_types"] = Machine.__subclasses__()

        if self.request.user.is_authenticated:
            context["can_make_more_reservations"] = Quota.get_quota_by_machine(machine.literal, self.request.user) \
                .can_make_new_reservation()

        return context
コード例 #4
0
ファイル: calendar.py プロジェクト: mahoyen/web
    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(year, week, machine)
        context.update({
            "next":
            get_next_week(context["year"], context["week"], 1),
            "prev":
            get_next_week(context["year"], context["week"], -1),
            "other_machines":
            Machine.objects.exclude(pk=machine.pk).filter(
                machine_type=machine.machine_type),
        })

        return context
コード例 #5
0
ファイル: test_time.py プロジェクト: Marcusntnu/web
 def test_get_next_valid_week_year_shift(self):
     self.assertEqual((2018, 1), get_next_week(2017, 52, 1))
     self.assertEqual((2016, 52), get_next_week(2017, 1, -1))
コード例 #6
0
ファイル: test_time.py プロジェクト: Marcusntnu/web
 def test_get_next_valid_week_middle_of_year(self):
     self.assertEqual((2017, 30), get_next_week(2017, 29, 1))
     self.assertEqual((2017, 28), get_next_week(2017, 29, -1))
コード例 #7
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