コード例 #1
0
    def add_reservation(start, end, reservation):
        day = start.day

        used_days[day] = True

        end += timedelta(microseconds=1)

        start = sedate.to_timezone(start, timezone=timezone)
        end = sedate.to_timezone(end, timezone=timezone)

        start = utils.localize_date(start, time_only=True)
        end = utils.localize_date(end, time_only=True)

        context = resources[utils.string_uuid(reservation.resource)]

        reservation_lists = report[day][utils.string_uuid(
            reservation.resource
        )]
        reservation_lists[reservation.status].append(
            dict(
                start=start,
                end=end,
                email=reservation.email,
                data=reservation.data,
                timespans=json_timespans(start, end),
                id=reservation.id,
                token=reservation.token,
                quota=utils.get_reservation_quota_statement(reservation.quota),
                resource=context,
            )
        )
コード例 #2
0
    def add_reservation(start, end, reservation):
        day = start.day

        used_days[day] = True

        end += timedelta(microseconds=1)

        start = modules.calendar.to_timezone(start, timezone=timezone)
        end = modules.calendar.to_timezone(end, timezone=timezone)

        start = utils.localize_date(start, time_only=True)
        end = utils.localize_date(end, time_only=True)

        context = resources[utils.string_uuid(reservation.resource)]

        reservation_lists = report[day][utils.string_uuid(
            reservation.resource
        )]
        reservation_lists[reservation.status].append(
            dict(
                start=start,
                end=end,
                email=reservation.email,
                data=reservation.data,
                timespans=json_timespans(start, end),
                id=reservation.id,
                token=reservation.token,
                quota=utils.get_reservation_quota_statement(reservation.quota),
                resource=context,
            )
        )
コード例 #3
0
ファイル: macros.py プロジェクト: seantis/seantis.reservation
 def get_time_text(start, end):
     if utils.whole_day(start, end):
         return whole_day_text
     else:
         return ' - '.join((
             utils.localize_date(start, time_only=True),
             utils.localize_date(end, time_only=True),
         ))
コード例 #4
0
    def daterange_label(self):
        since, until = self.daterange

        if until.date() == utils.utcnow().date():
            return ' - '.join((utils.localize_date(since, long_format=False),
                               self.translate(_(u'Today'))))
        return ' - '.join((utils.localize_date(since, long_format=False),
                           utils.localize_date(until, long_format=False)))
コード例 #5
0
 def get_time_text(start, end):
     if utils.whole_day(start, end):
         return whole_day_text
     else:
         return ' - '.join((
             utils.localize_date(start, time_only=True),
             utils.localize_date(end, time_only=True),
         ))
コード例 #6
0
 def timestr(self):
     return ' - '.join((
         utils.localize_date(
             datetime(self.start.year, self.start.month, self.start.day),
             long_format=False
         ),
         utils.localize_date(
             datetime(self.end.year, self.end.month, self.end.day),
             long_format=False
         )
     ))
コード例 #7
0
    def daterange_label(self):
        since, until = self.daterange

        if until.date() == utils.utcnow().date():
            return ' - '.join((
                utils.localize_date(since, long_format=False),
                self.translate(_(u'Today'))
            ))
        return ' - '.join((
            utils.localize_date(since, long_format=False),
            utils.localize_date(until, long_format=False)
        ))
コード例 #8
0
def human_date(date):
    # timezones are currently naive and implicity the one used by
    # the users - we don't have international reservations yet
    now = utils.utcnow()

    this_morning = datetime(
        now.year, now.month, now.day
    ).replace(tzinfo=now.tzinfo)

    time = utils.localize_date(date, time_only=True)

    if date >= this_morning:
        return _(u'Today, at ${time}', mapping={'time': time})

    days = (now.date() - date.date()).days

    if days <= 1:
        return _(u'Yesterday, at ${time}', mapping={
            'time': time
        })
    else:
        return _(u'${days} days ago, at ${time}', mapping={
            'days': days,
            'time': time
        })
コード例 #9
0
    def format_day(self, day):
        daydate = datetime(self.year, self.month, day)
        weekday = utils.weekdayname_abbr(
            self.context, self.request, utils.shift_day(daydate.weekday())
        )

        return ', '.join((
            weekday,
            utils.localize_date(daydate, long_format=False)
        ))
コード例 #10
0
    def format_day(self, day):
        daydate = datetime(self.year, self.month, day)
        weekday = utils.weekdayname_abbr(
            self.context, self.request, utils.shift_day(daydate.weekday())
        )

        return ', '.join((
            weekday,
            utils.localize_date(daydate, long_format=False)
        ))
コード例 #11
0
def human_date(date):
    # timezones are currently naive and implicity the one used by
    # the users - we don't have international reservations yet
    now = utils.utcnow()

    this_morning = datetime(now.year, now.month,
                            now.day).replace(tzinfo=now.tzinfo)

    time = utils.localize_date(date, time_only=True)

    if date >= this_morning:
        return _(u'Today, at ${time}', mapping={'time': time})

    days = (now.date() - date.date()).days

    if days <= 1:
        return _(u'Yesterday, at ${time}', mapping={'time': time})
    else:
        return _(u'${days} days ago, at ${time}',
                 mapping={
                     'days': days,
                     'time': time
                 })
コード例 #12
0
ファイル: macros.py プロジェクト: seantis/seantis.reservation
    def build_allocations_table(
        self, allocations, start_time=None, end_time=None
    ):
        """ Prepares the given allocations for the found-allocations table.
        Only works on IResourceBase contexts.
        """

        if not allocations:
            return []

        scheduler = self.context.scheduler()
        whole_day_text = self.translate(_(u'Whole day'))

        def get_time_text(start, end):
            if utils.whole_day(start, end):
                return whole_day_text
            else:
                return ' - '.join((
                    utils.localize_date(start, time_only=True),
                    utils.localize_date(end, time_only=True),
                ))

        prev_date = None

        result = []

        tz = settings.timezone()

        for allocation in allocations:

            if start_time or end_time:
                s = start_time or allocation.display_start(tz).time()
                e = end_time or allocation.display_end(tz).time()

                s, e = allocation.limit_timespan(s, e)

                time_text = get_time_text(s, e)
            else:
                time_text = get_time_text(
                    allocation.display_start(tz), allocation.display_end(tz)
                )
                s, e = None, None

            availability, text, allocation_class = utils.event_availability(
                self.context, self.request, scheduler, allocation, s, e
            )

            date = ', '.join((
                self.translate(
                    self.short_days[allocation.display_start(tz).weekday()]
                ),
                utils.localize_date(
                    allocation.display_start(tz), long_format=False
                )
            ))

            result.append({
                'id': allocation.id,
                'group': allocation.group,
                'date': date,
                'time': time_text,
                'class': utils.event_class(availability),
                'is_first_of_date': prev_date != date,
                'text': ', '.join(text.split('\n')),
                'is_extra_result': getattr(
                    allocation, 'is_extra_result', False
                )
            })

            prev_date = date

        return result
コード例 #13
0
    def build_allocations_table(self,
                                allocations,
                                start_time=None,
                                end_time=None):
        """ Prepares the given allocations for the found-allocations table.
        Only works on IResourceBase contexts.
        """

        if not allocations:
            return []

        scheduler = self.context.scheduler()
        whole_day_text = self.translate(_(u'Whole day'))

        def get_time_text(start, end):
            if utils.whole_day(start, end):
                return whole_day_text
            else:
                return ' - '.join((
                    utils.localize_date(start, time_only=True),
                    utils.localize_date(end, time_only=True),
                ))

        prev_date = None

        result = []

        tz = settings.timezone()

        for allocation in allocations:

            if start_time or end_time:
                s = start_time or allocation.display_start(tz).time()
                e = end_time or allocation.display_end(tz).time()

                s, e = allocation.limit_timespan(s, e)

                time_text = get_time_text(s, e)
            else:
                time_text = get_time_text(allocation.display_start(tz),
                                          allocation.display_end(tz))
                s, e = None, None

            availability, text, allocation_class = utils.event_availability(
                self.context, self.request, scheduler, allocation, s, e)

            date = ', '.join((self.translate(
                self.short_days[allocation.display_start(tz).weekday()]),
                              utils.localize_date(allocation.display_start(tz),
                                                  long_format=False)))

            result.append({
                'id':
                allocation.id,
                'group':
                allocation.group,
                'date':
                date,
                'time':
                time_text,
                'class':
                utils.event_class(availability),
                'is_first_of_date':
                prev_date != date,
                'text':
                ', '.join(text.split('\n')),
                'is_extra_result':
                getattr(allocation, 'is_extra_result', False)
            })

            prev_date = date

        return result