Пример #1
0
    def testWorkalendarNames(self):
        class Woral:
            get_calendar_holidays = Mock(return_value=[(dt.date(1999, 4, 30),
                                                        "JOY JOY")])

        woral = Woral()
        hols = Holidays()
        hols.register(woral)
        self.assertEqual(hols.names(), ["JOY JOY"])
Пример #2
0
    def testWorkalendar(self):
        class Woral:
            get_holiday_label = Mock(return_value="JOY JOY")

        woral = Woral()
        hols = Holidays()
        hols.register(woral)
        self.assertEqual(hols.srcs, [{}, woral])
        self.assertEqual(hols.get(dt.date(1999, 4, 30)), "JOY JOY")
        woral.get_holiday_label.assert_called_with(dt.date(1999, 4, 30))
Пример #3
0
 def get_context(self, request, *args, **kwargs):
     self.holidays = Holidays()
     for absence in Absence.get_absence_queryset_by_user(request.user):
         if absence.deleted:
             continue
         self.holidays.add(
             absence.from_date,
             absence.child_link.first_name + ' ' + absence.remark)
     ctx = super().get_context(request, *args, **kwargs)
     return ctx
Пример #4
0
 def testNZNames(self):
     hols = Holidays()
     self.assertEqual(hols.names(), [
         "New Year's Day", "Day after New Year's Day",
         "New Year's Day (Observed)", "Day after New Year's Day (Observed)",
         'Wellington Anniversary Day', 'Auckland Anniversary Day',
         'Nelson Anniversary Day', 'Waitangi Day',
         'Waitangi Day (Observed)', 'Taranaki Anniversary Day',
         'Otago Anniversary Day', 'Good Friday', 'Easter Monday',
         'Southland Anniversary Day', 'Anzac Day', 'Anzac Day (Observed)',
         "Queen's Birthday", 'South Canterbury Anniversary Day',
         "Hawke's Bay Anniversary Day", 'Labour Day',
         'Marlborough Anniversary Day', 'Canterbury Anniversary Day',
         'Chatham Islands Anniversary Day', 'Westland Anniversary Day',
         'Christmas Day', 'Boxing Day', 'Christmas Day (Observed)',
         'Boxing Day (Observed)'
     ])
 def setUp(self):
     holidays = Holidays(holidaySetting=None)
     holidays.register(WeatherDays())
     self.home = Page.objects.get(slug='home')
     self.user = User.objects.create_user('i', '*****@*****.**', 's3(r3t')
     self.calendar = CalendarPage(owner=self.user,
                                  slug="events",
                                  title="Events")
     self.calendar.holidays = holidays
     self.home.add_child(instance=self.calendar)
     self.calendar.save_revision().publish()
     self.event = RecurringEventPage(slug="committee-meeting",
                                     title="Committee Meeting",
                                     repeat=Recurrence(
                                         dtstart=dt.date(2017, 1, 1),
                                         freq=MONTHLY,
                                         byweekday=[MO(1), MO(3)]),
                                     time_from=dt.time(13),
                                     time_to=dt.time(15, 30),
                                     holidays=holidays)
     self.calendar.add_child(instance=self.event)
Пример #6
0
class GirotondoCalendar(LoginRequiredMixin, CalendarPage):
    class Meta:
        verbose_name = "Girotondo Calendar"

    show_in_menus_default = True

    def get_context(self, request, *args, **kwargs):
        self.holidays = Holidays()
        for absence in Absence.get_absence_queryset_by_user(request.user):
            if absence.deleted:
                continue
            self.holidays.add(
                absence.from_date,
                absence.child_link.first_name + ' ' + absence.remark)
        ctx = super().get_context(request, *args, **kwargs)
        return ctx

    subpage_types = [
        RecurringEventPage, MultidayRecurringEventPage, MultidayEventPage,
        SimpleEventPage
    ]
Пример #7
0
class GirotondoMonth:
    def __init__(self, year: int = None, month: int = None):
        if month is None:
            month = date.today().month
        self.month = month
        if year is None:
            year = date.today().year
        self.year = year
        self.next_month = self.month + 1
        self.next_month_year = self.year
        if self.next_month > 12:
            self.next_month_year = self.year + 1
            self.next_month = 1
        self.event_queryset = SimpleEventPage.objects.filter(
            date__gte=date(self.year, self.month, 1),
            date__lt=date(self.next_month_year, self.next_month, 1))

        # .union(MultidayEventPage.objects.filter(
        #    date_to__gte=date(self.year, self.month, 1),
        #    date_from__lt=date(self.next_month_year, self.next_month, 1))).order_by('owner_id')
        self.absences = Child.get_assignments_by_month(self.month, self.year)
        self.children = Child.get_children_per_care_group()
        self.holidays = Holidays()

    def is_girotondo_day(self, day: int) -> bool:
        test_date = date(self.year, self.month, day)
        if test_date.weekday() > 4:  # 5 = saturday, 6 = sunday
            return False
        if len(self.holidays.get(test_date)) > 0:
            return False
        for event in self.event_queryset:
            if event.date != test_date:
                continue
            if event.category is not None and event.category.name in (
                    'closed', 'Closed'):
                return False
        return True

    def get_children_in(self, day: int, group: str) -> List[str]:
        children_in = []
        if not self.is_girotondo_day(day):
            return []
        for child in self.children[group]:
            if child not in self.absences[day - 1][group]:
                children_in.append(child.first_name + ' ' + child.last_name)
        return children_in

    def get_children_out(self, day: int, group: str) -> List[str]:
        return [
            x.first_name + ' ' + x.last_name
            for x in self.absences[day - 1][group]
        ]
Пример #8
0
    def __init__(self, year: int = None, month: int = None):
        if month is None:
            month = date.today().month
        self.month = month
        if year is None:
            year = date.today().year
        self.year = year
        self.next_month = self.month + 1
        self.next_month_year = self.year
        if self.next_month > 12:
            self.next_month_year = self.year + 1
            self.next_month = 1
        self.event_queryset = SimpleEventPage.objects.filter(
            date__gte=date(self.year, self.month, 1),
            date__lt=date(self.next_month_year, self.next_month, 1))

        # .union(MultidayEventPage.objects.filter(
        #    date_to__gte=date(self.year, self.month, 1),
        #    date_from__lt=date(self.next_month_year, self.next_month, 1))).order_by('owner_id')
        self.absences = Child.get_assignments_by_month(self.month, self.year)
        self.children = Child.get_children_per_care_group()
        self.holidays = Holidays()
Пример #9
0
 def testAdd(self):
     ausHols = Holidays(None)
     ausHols.add(dt.date(2020, 10, 20), "Kangaroo Day")
     ausHols.register(AU())
     nzHols = Holidays(None)
     nzHols.add(dt.date(2020, 10, 20), "Kiwi Day")
     nzHols.register(NZ())
     tasHols = ausHols + nzHols
     self.assertEqual(tasHols.get(dt.date(2020, 10, 20)),
                      "Kangaroo Day, Kiwi Day")
     self.assertEqual(len(tasHols.srcs), 3)
     self.assertIs(type(tasHols.srcs[0]), dict)
     self.assertIs(type(tasHols.srcs[1]), AU)
     self.assertIs(type(tasHols.srcs[2]), NZ)
     self.assertEqual(tasHols.names(), [
         "New Year's Day", "Day after New Year's Day",
         "New Year's Day (Observed)", "Day after New Year's Day (Observed)",
         'Australia Day', 'Australia Day (Observed)', 'Waitangi Day',
         'Waitangi Day (Observed)', 'Good Friday', 'Easter Monday',
         'Anzac Day', 'Anzac Day (Observed)', "Queen's Birthday",
         'Kangaroo Day', 'Kiwi Day', 'Labour Day', 'Christmas Day',
         'Boxing Day', 'Christmas Day (Observed)', 'Boxing Day (Observed)'
     ])
Пример #10
0
 def testSimpleNames(self):
     hols = Holidays()
     hols.add(dt.date(2021, 4, 29), "HAPPY HAPPY")
     self.assertEqual(hols.names(), ["HAPPY HAPPY"])
Пример #11
0
 def testNoNames(self):
     hols = Holidays()
     self.assertEqual(hols.names(), [])
Пример #12
0
 def testMultiHolidays(self):
     hols = Holidays()
     hols.add(dt.date(1999, 1, 1), "Gliffy")
     hols.add(dt.date(1999, 1, 1), "Whatnot")
     self.assertEqual(hols.get(dt.date(1999, 1, 1)),
                      "Gliffy, Whatnot, New Year's Day")
Пример #13
0
 def testSimple(self):
     hols = Holidays()
     hols.add(dt.date(1999, 4, 29), "HAPPY HAPPY")
     self.assertEqual(hols.get(dt.date(1999, 4, 29)), "HAPPY HAPPY")
Пример #14
0
 def testNZSetting(self):
     hols = Holidays()
     self.assertEqual(hols.get(dt.date(1999, 4, 25)), "Anzac Day")
Пример #15
0
 def testNoSettings(self):
     del settings.JOYOUS_HOLIDAYS
     hols = Holidays()
     self.assertEqual(hols.simple, {})
     self.assertEqual(hols.srcs, [{}])
     self.assertEqual(hols.get(dt.date(1999, 4, 25)), "")