Example #1
0
    def getReservations(*args, **kwargs):
        """ Documentation in base class. """

        resvID = kwargs.get("resvID")
        resvEx = kwargs.get("resvExample")
        rooms = kwargs.get("rooms")
        countOnly = kwargs.get("countOnly")
        archival = kwargs.get("archival")
        heavy = kwargs.get("heavy")
        location = kwargs.get("location")
        days = kwargs.get("days")

        ret_lst = []
        counter = 0
        root = Factory.getDALManager().getRoot()

        if resvID != None:
            return root[_RESERVATIONS].get(resvID)

        resvCandidates = None

        alreadyRoomFiltered = False
        # If we filter by room but not by day, we can use the RoomReservations index
        if rooms and not days and len(rooms) <= 10:
            # Use room => room reservations index
            resvCandidates = set()
            for room in rooms:
                if location != None and room.locationName != location:
                    continue  # Skip rooms from different locations
                roomResvs = Reservation.getRoomReservationsIndexRoot().get(room.id)
                if roomResvs != None:
                    resvCandidates.update(roomResvs)
            alreadyRoomFiltered = True

        # If we don't have reservations yet but filter by creator, use the UserReservations index
        if resvCandidates == None and resvEx != None and resvEx.createdBy != None:
            resvCandidates = set(Reservation.getUserReservationsIndexRoot().get(resvEx.createdBy, []))

        # If we want to filter by day, we can choose indexes.
        dayFilteredResvs = None
        if days and rooms:
            # If there's a room filter, too - use the RoomDayReservations index
            dayFilteredResvs = set()
            for key in ((room.id, day) for day in days for room in rooms):
                dayRoomResvs = Reservation.getRoomDayReservationsIndexRoot().get(key, [])
                dayFilteredResvs.update(dayRoomResvs)
            alreadyRoomFiltered = True
        elif days:
            # If we only filter by days, use the DayReservations index
            dayFilteredResvs = set()
            for day in days:
                dayResvs = Reservation.getDayReservationsIndexRoot().get(day, [])
                dayFilteredResvs.update(dayResvs)

        # If we have some day-filtered reservations, use that list or restrict the existing one
        if dayFilteredResvs is not None:
            if resvCandidates is None:
                resvCandidates = dayFilteredResvs
            else:
                # Intersection
                resvCandidates = dayFilteredResvs & resvCandidates

        # If we still have nothing, get all reservations and filter them later in the loop (slow!)
        if resvCandidates is None:
            resvCandidates = Reservation.getReservationsRoot().itervalues()

        for resvCandidate in resvCandidates:
            # Apply all conditions

            if archival != None:
                if resvCandidate.isArchival != archival:
                    continue

            if location != None:
                # If location is specified, use only rooms from this location
                if not resvCandidate.locationName == location:
                    continue

            if heavy != None:
                if resvCandidate.isHeavy != heavy:
                    continue

            # Does the reservation overlap on the specified period?
            if resvEx != None:
                if resvEx.startDT != None and resvEx.endDT != None:
                    if not resvCandidate.overlapsOn(resvEx.startDT, resvEx.endDT):
                        continue

                if rooms != None and not alreadyRoomFiltered:
                    if resvCandidate.room not in rooms:
                        continue

                if resvEx.createdDT != None:
                    if resvEx.createdDT != resvCandidate.createdDT:
                        continue

                if resvEx.bookedForName != None:
                    if resvCandidate.bookedForName == None:
                        continue
                    if not containsExactly_OR_containsAny(resvEx.bookedForName, resvCandidate.bookedForName):
                        continue

                if resvEx.bookedForId != None:
                    if resvCandidate.bookedForId == None:
                        continue
                    if resvEx.bookedForId != resvCandidate.bookedForId:
                        continue

                if resvEx.reason != None:
                    if resvCandidate.reason == None:
                        continue
                    if not containsExactly_OR_containsAny(resvEx.reason, resvCandidate.reason):
                        continue

                if resvEx.contactEmail != None:
                    if resvCandidate.contactEmail == None:
                        continue
                    if not resvEx.contactEmail in resvCandidate.contactEmail:
                        continue

                if resvEx.contactPhone != None:
                    if resvCandidate.contactPhone == None:
                        continue
                    if not resvEx.contactPhone in resvCandidate.contactPhone:
                        continue

                if resvEx.createdBy != None:
                    if resvCandidate.createdBy != resvEx.createdBy:
                        continue

                if resvEx.rejectionReason != None:
                    if resvCandidate.rejectionReason == None:
                        continue
                    if not resvEx.rejectionReason in resvCandidate.rejectionReason:
                        continue

                if resvEx.isConfirmed != None:
                    if not resvCandidate.isConfirmed == resvEx.isConfirmed:
                        continue

                if resvEx.isRejected != None:
                    if not resvCandidate.isRejected == resvEx.isRejected:
                        continue

                if resvEx.isCancelled != None:
                    if not resvCandidate.isCancelled == resvEx.isCancelled:
                        continue

                if resvEx.usesAVC != None:
                    if not resvCandidate.usesAVC == resvEx.usesAVC:
                        continue

                if resvEx.needsAVCSupport != None:
                    if not resvCandidate.needsAVCSupport == resvEx.needsAVCSupport:
                        continue

                if resvEx.needsAssistance != None:
                    if not resvCandidate.needsAssistance == resvEx.needsAssistance:
                        continue

            # META-PROGRAMMING STYLE OF CHECKING ATTRIBUTES EQUALITY
            # ABANDONED DUE TO PERFORMANCE PROBLEMS
            # Are standard conditions met? (other attributes equality)
            # if not qbeMatch( resvEx, resvCandidate, Reservation.__attrSpecialEqual ):
            #    continue

            # All conditions are met: add reservation to the results
            counter += 1
            if not countOnly:
                ret_lst.append(resvCandidate)

        # print "Found " + str( counter ) + " reservations."
        if not countOnly:
            return ret_lst
        else:
            return counter
Example #2
0
    def getReservations( *args, **kwargs ):
        """ Documentation in base class. """

        resvID = kwargs.get( 'resvID' )
        resvEx = kwargs.get( 'resvExample' )
        rooms = kwargs.get( 'rooms' )
        countOnly = kwargs.get( 'countOnly' )
        archival = kwargs.get( 'archival' )
        heavy = kwargs.get( 'heavy' )
        location = kwargs.get( 'location' )
        days = kwargs.get( 'days' )
        
        ret_lst = []
        counter = 0
        root = Factory.getDALManager().root
        
        if resvID != None:
            return root[_RESERVATIONS].get( resvID )
        
        resvCandidates = None

        alreadyRoomFiltered = False
        if rooms and len( rooms ) <= 10:
            # Use room => room reservations index
            resvCandidates = []
            for room in rooms:
                if location != None and room.locationName != location:
                    continue # Skip rooms from different locations
                roomResvs = Reservation.getRoomReservationsIndexRoot().get( room.id )
                if roomResvs != None:
                    resvCandidates += roomResvs
            alreadyRoomFiltered = True
        
        if resvCandidates == None and resvEx != None and resvEx.createdBy != None:
            resvCandidates = Reservation.getUserReservationsIndexRoot().get( resvEx.createdBy )
            if resvCandidates == None:
                resvCandidates = []

        if days:
            resvsInDays = {}
            for day in days:
                dayResvs = Reservation.getDayReservationsIndexRoot().get( day )
                if dayResvs:
                    for resv in dayResvs:
                        resvsInDays[resv] = None
            if resvCandidates == None:
                resvCandidates = resvsInDays.iterkeys()
            else:
                # Intersection
                new = []
                for resv in resvCandidates:
                    if resvsInDays.has_key( resv ):
                        new.append( resv )
                resvCandidates = new
    
        if resvCandidates == None:
            resvCandidates = Reservation.getReservationsRoot().itervalues()

        for resvCandidate in resvCandidates:
            # Apply all conditions 

            if archival != None:
                if resvCandidate.isArchival != archival:
                    continue
            
            if location != None:
                # If location is specified, use only rooms from this location
                if not resvCandidate.locationName == location:
                    continue

            if heavy != None:
                if resvCandidate.isHeavy != heavy:
                    continue
                
            # Does the reservation overlap on the specified period?
            if resvEx != None:
                if resvEx.startDT != None and resvEx.endDT != None:
                    if not resvCandidate.overlapsOn( resvEx.startDT, resvEx.endDT ):
                        continue

                if rooms != None and not alreadyRoomFiltered:
                    if resvCandidate.room not in rooms:
                        continue
                
                if resvEx.createdDT != None:
                    if resvEx.createdDT != resvCandidate.createdDT:
                        continue
                
                if resvEx.bookedForName != None:
                    if resvCandidate.bookedForName == None: 
                        continue
                    if not containsExactly_OR_containsAny( resvEx.bookedForName, resvCandidate.bookedForName ):
                        continue
    
                if resvEx.reason != None:
                    if resvCandidate.reason == None: 
                        continue
                    if not containsExactly_OR_containsAny( resvEx.reason, resvCandidate.reason ):
                        continue

                if resvEx.contactEmail != None:
                    if resvCandidate.contactEmail == None:
                        continue
                    if not resvEx.contactEmail in resvCandidate.contactEmail:
                        continue

                if resvEx.contactPhone != None:
                    if resvCandidate.contactPhone == None:
                        continue
                    if not resvEx.contactPhone in resvCandidate.contactPhone:
                        continue

                if resvEx.createdBy != None:
                    if resvCandidate.createdBy != resvEx.createdBy:
                        continue

                if resvEx.rejectionReason != None:
                    if resvCandidate.rejectionReason == None:
                        continue
                    if not resvEx.rejectionReason in resvCandidate.rejectionReason:
                        continue

                if resvEx.isConfirmed != None:
                    if not resvCandidate.isConfirmed == resvEx.isConfirmed:
                        continue

                if resvEx.isRejected != None:
                    if not resvCandidate.isRejected == resvEx.isRejected:
                        continue

                if resvEx.isCancelled != None:
                    if not resvCandidate.isCancelled == resvEx.isCancelled:
                        continue

                if resvEx.usesAVC != None:
                    if not resvCandidate.usesAVC == resvEx.usesAVC:
                        continue

                if resvEx.needsAVCSupport != None:
                    if not resvCandidate.needsAVCSupport == resvEx.needsAVCSupport:
                        continue
                
            # META-PROGRAMMING STYLE OF CHECKING ATTRIBUTES EQUALITY
            # ABANDONED DUE TO PERFORMANCE PROBLEMS
            # Are standard conditions met? (other attributes equality)
            #if not qbeMatch( resvEx, resvCandidate, Reservation.__attrSpecialEqual ):
            #    continue

            
            # All conditions are met: add reservation to the results
            counter += 1
            if not countOnly:
                ret_lst.append( resvCandidate )
            
        #print "Found " + str( counter ) + " reservations."
        if not countOnly: return ret_lst
        else: return counter
Example #3
0
    def getReservations(*args, **kwargs):
        """ Documentation in base class. """

        resvID = kwargs.get('resvID')
        resvEx = kwargs.get('resvExample')
        rooms = kwargs.get('rooms')
        countOnly = kwargs.get('countOnly')
        archival = kwargs.get('archival')
        heavy = kwargs.get('heavy')
        location = kwargs.get('location')
        days = kwargs.get('days')

        ret_lst = []
        counter = 0
        root = Factory.getDALManager().getRoot()

        if resvID != None:
            return root[_RESERVATIONS].get(resvID)

        resvCandidates = None

        alreadyRoomFiltered = False
        # If we filter by room but not by day, we can use the RoomReservations index
        if rooms and not days and len(rooms) <= 10:
            # Use room => room reservations index
            resvCandidates = set()
            for room in rooms:
                if location != None and room.locationName != location:
                    continue  # Skip rooms from different locations
                roomResvs = Reservation.getRoomReservationsIndexRoot().get(
                    room.id)
                if roomResvs != None:
                    resvCandidates.update(roomResvs)
            alreadyRoomFiltered = True

        # If we don't have reservations yet but filter by creator, use the UserReservations index
        if resvCandidates == None and resvEx != None and resvEx.createdBy != None:
            resvCandidates = set(
                Reservation.getUserReservationsIndexRoot().get(
                    resvEx.createdBy, []))

        # If we want to filter by day, we can choose indexes.
        dayFilteredResvs = None
        if days and rooms:
            # If there's a room filter, too - use the RoomDayReservations index
            dayFilteredResvs = set()
            for key in ((room.id, day) for day in days for room in rooms):
                dayRoomResvs = Reservation.getRoomDayReservationsIndexRoot(
                ).get(key, [])
                dayFilteredResvs.update(dayRoomResvs)
            alreadyRoomFiltered = True
        elif days:
            # If we only filter by days, use the DayReservations index
            dayFilteredResvs = set()
            for day in days:
                dayResvs = Reservation.getDayReservationsIndexRoot().get(
                    day, [])
                dayFilteredResvs.update(dayResvs)

        # If we have some day-filtered reservations, use that list or restrict the existing one
        if dayFilteredResvs is not None:
            if resvCandidates is None:
                resvCandidates = dayFilteredResvs
            else:
                # Intersection
                resvCandidates = dayFilteredResvs & resvCandidates

        # If we still have nothing, get all reservations and filter them later in the loop (slow!)
        if resvCandidates is None:
            resvCandidates = Reservation.getReservationsRoot().itervalues()

        for resvCandidate in resvCandidates:
            # Apply all conditions

            if archival != None:
                if resvCandidate.isArchival != archival:
                    continue

            if location != None:
                # If location is specified, use only rooms from this location
                if not resvCandidate.locationName == location:
                    continue

            if heavy != None:
                if resvCandidate.isHeavy != heavy:
                    continue

            # Does the reservation overlap on the specified period?
            if resvEx != None:
                if resvEx.startDT != None and resvEx.endDT != None:
                    if not resvCandidate.overlapsOn(resvEx.startDT,
                                                    resvEx.endDT):
                        continue

                if rooms != None and not alreadyRoomFiltered:
                    if resvCandidate.room not in rooms:
                        continue

                if resvEx.createdDT != None:
                    if resvEx.createdDT != resvCandidate.createdDT:
                        continue

                if resvEx.bookedForName != None:
                    if resvCandidate.bookedForName == None:
                        continue
                    if not containsExactly_OR_containsAny(
                            resvEx.bookedForName, resvCandidate.bookedForName):
                        continue

                if resvEx.reason != None:
                    if resvCandidate.reason == None:
                        continue
                    if not containsExactly_OR_containsAny(
                            resvEx.reason, resvCandidate.reason):
                        continue

                if resvEx.contactEmail != None:
                    if resvCandidate.contactEmail == None:
                        continue
                    if not resvEx.contactEmail in resvCandidate.contactEmail:
                        continue

                if resvEx.contactPhone != None:
                    if resvCandidate.contactPhone == None:
                        continue
                    if not resvEx.contactPhone in resvCandidate.contactPhone:
                        continue

                if resvEx.createdBy != None:
                    if resvCandidate.createdBy != resvEx.createdBy:
                        continue

                if resvEx.rejectionReason != None:
                    if resvCandidate.rejectionReason == None:
                        continue
                    if not resvEx.rejectionReason in resvCandidate.rejectionReason:
                        continue

                if resvEx.isConfirmed != None:
                    if not resvCandidate.isConfirmed == resvEx.isConfirmed:
                        continue

                if resvEx.isRejected != None:
                    if not resvCandidate.isRejected == resvEx.isRejected:
                        continue

                if resvEx.isCancelled != None:
                    if not resvCandidate.isCancelled == resvEx.isCancelled:
                        continue

                if resvEx.usesAVC != None:
                    if not resvCandidate.usesAVC == resvEx.usesAVC:
                        continue

                if resvEx.needsAVCSupport != None:
                    if not resvCandidate.needsAVCSupport == resvEx.needsAVCSupport:
                        continue

                if resvEx.needsAssistance != None:
                    if not resvCandidate.needsAssistance == resvEx.needsAssistance:
                        continue

            # META-PROGRAMMING STYLE OF CHECKING ATTRIBUTES EQUALITY
            # ABANDONED DUE TO PERFORMANCE PROBLEMS
            # Are standard conditions met? (other attributes equality)
            #if not qbeMatch( resvEx, resvCandidate, Reservation.__attrSpecialEqual ):
            #    continue

            # All conditions are met: add reservation to the results
            counter += 1
            if not countOnly:
                ret_lst.append(resvCandidate)

        #print "Found " + str( counter ) + " reservations."
        if not countOnly: return ret_lst
        else: return counter