def events(self, daterange=None, uuids=None): """ Returns the events for the overview. """ start, end = daterange or self.range if not all((start, end)): return [] events = [] uuids = uuids or self.uuids() queries = get_queries(uuids) days = queries.availability_by_day(start, end, uuids) for day, result in days.items(): event_start = datetime(day.year, day.month, day.day, 0, 0) event_end = event_start + timedelta(days=+1, microseconds=-1) availability, resources = result events.append(dict( start=event_start.isoformat(), end=event_end.isoformat(), title=u'', uuids=[utils.string_uuid(r) for r in resources], className=utils.event_class(availability) )) return events
def events(self, daterange=None, uuids=None): """ Returns the events for the overview. """ start, end = daterange or self.range if not all((start, end)): return [] events = [] uuids = uuids or self.uuids() queries = get_queries(uuids) days = queries.availability_by_day(start, end, uuids) for day, result in days.items(): event_start = datetime(day.year, day.month, day.day, 0, 0) event_end = event_start + timedelta(days=+1, microseconds=-1) availability, resources = result events.append( dict(start=event_start.isoformat(), end=event_end.isoformat(), title=u'', uuids=[utils.string_uuid(r) for r in resources], className=utils.event_class(availability))) return events
def events(self): """ Returns the events for the overview. """ start, end = self.range if not all((start, end)): return [] events = [] uuids = self.uuids() is_exposed = exposure.for_allocations(self.context, uuids) days = db.availability_by_day(start, end, uuids, is_exposed) for day, result in days.items(): event_start = datetime(day.year, day.month, day.day, 0, 0) event_end = event_start + timedelta(days=+1, microseconds=-1) availability, resources = result events.append( dict(start=event_start.isoformat(), end=event_end.isoformat(), title=u'', uuids=[utils.string_uuid(r) for r in resources], className=utils.event_class(availability))) return events
def events(self): """ Returns the events for the overview. """ start, end = self.range if not all((start, end)): return [] events = [] uuids = self.uuids() is_exposed = exposure.for_allocations(self.context, uuids) days = db.availability_by_day(start, end, uuids, is_exposed) for day, result in days.items(): event_start = datetime(day.year, day.month, day.day, 0, 0) event_end = event_start + timedelta(days=+1, microseconds=-1) availability, resources = result events.append(dict( start=event_start.isoformat(), end=event_end.isoformat(), title=u'', uuids=[utils.string_uuid(r) for r in resources], className=utils.event_class(availability) )) return events
def test_event_class(self): self.assertEqual(utils.event_class(100), 'event-available') self.assertEqual(utils.event_class(75), 'event-available') self.assertEqual(utils.event_class(1), 'event-partly-available') self.assertEqual(utils.event_class(0), 'event-unavailable') settings.set('available_threshold', 100) settings.set('partly_available_threshold', 1) self.assertEqual(utils.event_class(100), 'event-available') self.assertEqual(utils.event_class(99), 'event-partly-available') self.assertEqual(utils.event_class(1), 'event-partly-available') self.assertEqual(utils.event_class(0), 'event-unavailable')
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
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