def _process(self, room_ids, **kwargs): rooms = [self.room] if self.room else Room.query.filter(Room.id.in_(room_ids), ~Room.is_deleted).all() date_range, availability = get_rooms_availability(rooms, **kwargs) date_range = [dt.isoformat() for dt in date_range] for data in availability.viewvalues(): # add additional helpful attributes data.update({ 'num_days_available': len(date_range) - len(data['conflicts']), 'all_days_available': not data['conflicts'], 'num_conflicts': len(data['conflicts']) }) serialized = serialize_availability(availability) if self.room: availability = serialized[self.room.id] else: # keep order of original room id list availability = sorted(serialized.items(), key=lambda x: room_ids.index(x[0])) return jsonify(availability=availability, date_range=date_range)