Beispiel #1
0
    def page_context(self):
        page_context = super(ScheduledRemindersCalendarView, self).page_context
        timezone = Domain.get_by_name(self.domain).get_default_timezone()
        reminders = CaseReminderHandler.get_all_reminders(self.domain)
        dates = []
        now = datetime.utcnow()
        timezone_now = datetime.now(timezone)
        today = timezone_now.date()

        def adjust_next_fire_to_timezone(reminder_utc):
            return ServerTime(
                reminder_utc.next_fire).user_time(timezone).done().replace(
                    tzinfo=None)

        if reminders:
            start_date = adjust_next_fire_to_timezone(reminders[0]).date()
            if today < start_date:
                start_date = today
            end_date = adjust_next_fire_to_timezone(reminders[-1]).date()
        else:
            start_date = end_date = today
        # make sure start date is a Monday and enddate is a Sunday
        start_date -= timedelta(days=start_date.weekday())
        end_date += timedelta(days=6 - end_date.weekday())
        while start_date <= end_date:
            dates.append(start_date)
            start_date += timedelta(days=1)

        reminder_data = []
        for reminder in reminders:
            handler = reminder.handler
            recipient = reminder.recipient
            recipient_desc = get_recipient_name(recipient)
            case = reminder.case

            reminder_data.append({
                "handler_name":
                handler.nickname,
                "next_fire":
                adjust_next_fire_to_timezone(reminder),
                "recipient_desc":
                recipient_desc,
                "recipient_type":
                handler.recipient,
                "case_id":
                case.case_id if case is not None else None,
                "case_name":
                case.name if case is not None else None,
            })
Beispiel #2
0
 def format_recipients(self, broadcast):
     reminders = broadcast.get_reminders()
     if len(reminders) == 0:
         return _('(none)')
     return get_recipient_name(reminders[0].recipient, include_desc=False)