Ejemplo n.º 1
0
    def _preload_opening_hours(self, times):
        # We have to evaluate the query here to make sure all the
        # resources are on the same timezone. In case of different
        # time zones, we skip this optimization.
        time_zone = None
        hours_by_resource = {}
        for resource in self._page:
            if time_zone:
                if resource.unit.time_zone != time_zone:
                    return None
            else:
                time_zone = resource.unit.time_zone
            hours_by_resource[resource.id] = []
        if not time_zone:
            return None

        begin, end = determine_hours_time_range(times.get('start'), times.get('end'), pytz.timezone(time_zone))
        hours = ResourceDailyOpeningHours.objects.filter(
            resource__in=self._page, open_between__overlap=(begin, end, '[)')
        )
        for obj in hours:
            hours_by_resource[obj.resource_id].append(obj)
        return hours_by_resource
Ejemplo n.º 2
0
    def _preload_opening_hours(self, times):
        # We have to evaluate the query here to make sure all the
        # resources are on the same timezone. In case of different
        # time zones, we skip this optimization.
        time_zone = None
        hours_by_resource = {}
        for resource in self._page:
            if time_zone:
                if resource.unit.time_zone != time_zone:
                    return None
            else:
                time_zone = resource.unit.time_zone
            hours_by_resource[resource.id] = []
        if not time_zone:
            return None

        begin, end = determine_hours_time_range(times.get('start'), times.get('end'), pytz.timezone(time_zone))
        hours = ResourceDailyOpeningHours.objects.filter(
            resource__in=self._page, open_between__overlap=(begin, end, '[)')
        )
        for obj in hours:
            hours_by_resource[obj.resource_id].append(obj)
        return hours_by_resource