示例#1
0
 def event_availability(self, allocation):
     return utils.event_availability(
         self.context,
         self.request,
         self.context.scheduler(),
         allocation
     )
示例#2
0
    def events(self):
        resource = self.context
        scheduler = resource.scheduler()
        translate = utils.translator(self.context, self.request)

        is_exposed = exposure.for_allocations([resource])

        # get an event for each exposed allocation
        events = []
        for alloc in scheduler.allocations_in_range(*self.range):

            if not is_exposed(alloc):
                continue

            start = alloc.display_start(settings.timezone())
            end = alloc.display_end(settings.timezone())

            # get the urls
            urls = self.urls(alloc)

            # calculate the availability for title and class
            availability, title, klass = utils.event_availability(
                resource, self.request, scheduler, alloc
            )

            if alloc.partly_available:
                partitions = alloc.availability_partitions()
            else:
                # if the allocation is not partly available there can only
                # be one partition meant to be shown as empty unless the
                # availability is zero
                partitions = [(100, availability == 0.0)]

            event_header = alloc.whole_day and translate(_(u'Whole Day'))

            events.append(dict(
                title=title,
                start=start.isoformat(),
                end=end.isoformat(),
                className=klass,
                url=urls.default,
                menu=urls.menu,
                menuorder=urls.order,
                allocation=alloc.id,
                partitions=partitions,
                group=alloc.group,
                allDay=False,
                moveurl=urls.move,
                header=event_header
            ))

        return events
示例#3
0
    def events(self):
        resource = self.context
        scheduler = resource.scheduler()
        translate = utils.translator(self.context, self.request)

        is_exposed = exposure.for_allocations(resource, [resource])

        # get an event for each exposed allocation
        events = []
        for alloc in scheduler.allocations_in_range(*self.range):

            if not is_exposed(alloc):
                continue

            start, end = alloc.display_start, alloc.display_end

            # get the urls
            urls = self.urls(alloc)

            # calculate the availability for title and class
            availability, title, klass = utils.event_availability(
                resource, self.request, scheduler, alloc
            )

            if alloc.partly_available:
                partitions = alloc.availability_partitions(scheduler)
            else:
                # if the allocation is not partly available there can only
                # be one partition meant to be shown as empty unless the
                # availability is zero
                partitions = [(100, availability == 0.0)]

            event_header = alloc.whole_day and translate(_(u'Whole Day'))

            events.append(dict(
                title=title,
                start=start.isoformat(),
                end=end.isoformat(),
                className=klass,
                url=urls.default,
                menu=urls.menu,
                menuorder=urls.order,
                allocation=alloc.id,
                partitions=partitions,
                group=alloc.group,
                allDay=False,
                moveurl=urls.move,
                header=event_header
            ))

        return events
示例#4
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
示例#5
0
 def event_availability(self, allocation):
     return utils.event_availability(self.context, self.request,
                                     self.context.scheduler(), allocation)
示例#6
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