def rebuildRoomReservationsIndex(): from MaKaC.common.db import DBMgr from MaKaC.rb_location import CrossLocationDB from MaKaC.rb_room import RoomBase from MaKaC.plugins.RoomBooking.default.dalManager import DALManager from BTrees.OOBTree import OOBTree DBMgr.getInstance().startRequest() CrossLocationDB.connect() root = DALManager.root resvEx = ReservationBase() resvEx.isConfirmed = None allResvs = CrossLocationQueries.getReservations( resvExample = resvEx ) print "There are " + str( len( allResvs ) ) + " resvs and pre-resvs to index..." c = 0 root[_ROOM_RESERVATIONS_INDEX] = OOBTree() print "Room => Reservations Index branch created" for resv in allResvs: roomReservationsIndexBTree = root[_ROOM_RESERVATIONS_INDEX] resvs = roomReservationsIndexBTree.get( resv.room.id ) if resvs == None: resvs = [] # New list of reservations for this room roomReservationsIndexBTree.insert( resv.room.id, resvs ) resvs.append( resv ) roomReservationsIndexBTree[resv.room.id] = resvs c += 1 if c % 100 == 0: print c CrossLocationDB.commit() CrossLocationDB.disconnect() DBMgr.getInstance().endRequest()
def changeCreator(oldUser, newUser): dbi = DBMgr.getInstance() dbi.startRequest() Factory.getDALManager().connect() # check if the users exist if AvatarHolder().getById(oldUser) is None: print "There is no user with id %s" % oldUser return if AvatarHolder().getById(newUser) is None: print "There is no user with id %s" % newUser return resvEx = ReservationBase() resvEx.createdBy = oldUser allResv4OldUser = CrossLocationQueries.getReservations(resvExample=resvEx) if allResv4OldUser == []: print "No reservations for user %s" % oldUser return # resvs = ReservationBase.getReservations() # allResv4OldUser = [x for x in allResv if x.createdBy == oldUser] if type(allResv4OldUser) is not list: allResv4OldUser = [allResv4OldUser] # Modify reservations for r in allResv4OldUser: r.createdBy = newUser #print r.createdBy, r.id # Update index userReservationsIndexBTree = Reservation.getUserReservationsIndexRoot() newUserResvs = userReservationsIndexBTree.get(newUser) if newUserResvs == None: newUserResvs = [] # New list of reservations for this room userReservationsIndexBTree.insert(newUser, newUserResvs) newUserResvs.extend(allResv4OldUser) userReservationsIndexBTree[newUser] = newUserResvs[:] if userReservationsIndexBTree.has_key(oldUser): userReservationsIndexBTree.pop(oldUser) userReservationsIndexBTree._p_changed = 1 # close DB connection Factory.getDALManager().commit() Factory.getDALManager().disconnect() dbi.endRequest() print "%s reservations have moved from creator %s to creator %s" % ( len(allResv4OldUser), oldUser, newUser)
def changeCreator(oldUser, newUser): dbi = DBMgr.getInstance() dbi.startRequest() Factory.getDALManager().connect() # check if the users exist if AvatarHolder().getById(oldUser) is None: print "There is no user with id %s"%oldUser return if AvatarHolder().getById(newUser) is None: print "There is no user with id %s"%newUser return resvEx = ReservationBase() resvEx.createdBy = oldUser allResv4OldUser = CrossLocationQueries.getReservations( resvExample = resvEx) if allResv4OldUser == []: print "No reservations for user %s"%oldUser return # resvs = ReservationBase.getReservations() # allResv4OldUser = [x for x in allResv if x.createdBy == oldUser] if type(allResv4OldUser) is not list: allResv4OldUser = [allResv4OldUser] # Modify reservations for r in allResv4OldUser: r.createdBy = newUser #print r.createdBy, r.id # Update index userReservationsIndexBTree = Reservation.getUserReservationsIndexRoot() newUserResvs = userReservationsIndexBTree.get( newUser ) if newUserResvs == None: newUserResvs = [] # New list of reservations for this room userReservationsIndexBTree.insert( newUser, newUserResvs ) newUserResvs.extend( allResv4OldUser ) userReservationsIndexBTree[newUser] = newUserResvs[:] if userReservationsIndexBTree.has_key(oldUser): userReservationsIndexBTree.pop(oldUser) userReservationsIndexBTree._p_changed = 1 # close DB connection Factory.getDALManager().commit() Factory.getDALManager().disconnect() dbi.endRequest() print "%s reservations have moved from creator %s to creator %s" % (len(allResv4OldUser), oldUser, newUser)
def listResv4User(user): dbi = DBMgr.getInstance() dbi.startRequest() Factory.getDALManager().connect() resvEx = ReservationBase() resvEx.createdBy = user allResv = CrossLocationQueries.getReservations( resvExample = resvEx) print "User %s has %s resevations created by him/her"%(user, len(allResv)) Factory.getDALManager().disconnect() dbi.endRequest()
def runRoomDayIndexInit(dbi, withRBDB, prevVersion): """ Initializing room+day => reservation index. """ if not withRBDB: return root = DALManager().getRoot() if not root.has_key('RoomDayReservationsIndex'): root['RoomDayReservationsIndex'] = OOBTree() for i, resv in enumerate(CrossLocationQueries.getReservations()): resv._addToRoomDayReservationsIndex() if i % 1000 == 0: DALManager.commit() DALManager.commit()
def runReservationNotificationMigration(dbi, withRBDB, prevVersion): """ Migrate the reservation notification system. """ if not withRBDB: return # Delete old start end notification data for i, resv in enumerate(CrossLocationQueries.getReservations()): if hasattr(resv, '_startEndNotification'): resv._startEndNotification = None if i % 1000 == 0: DALManager.commit() # Create start notification task Client().enqueue(RoomReservationTask(rrule.HOURLY, byminute=0, bysecond=0)) DALManager.commit()
def reservation(self, locList): Factory.getDALManager().connect() resvEx = ReservationBase() resvEx.startDT = self._fromDT resvEx.endDT = self._toDT locList = filter(lambda loc: Location.parse(loc) is not None, locList) if self._fromDT or self._toDT: daysParam = (day.date() for day in rrule.rrule(rrule.DAILY, dtstart=self._fromDT, until=self._toDT)) else: # slow! daysParam = None for loc in sorted(locList): resvs = CrossLocationQueries.getReservations(location=loc, resvExample=resvEx, days=daysParam) for obj in self._process(resvs, filter=self._resvFilter): yield obj Factory.getDALManager().disconnect()
if len(roomIDs) > 10: return "One can only export 10 rooms at most" #################### process ################### rooms = [] for roomID in roomIDs: roomEx = Factory.newRoom() roomEx.id = roomID rooms.append(roomEx) resvEx = Factory.newReservation() resvEx.isCancelled = False resvEx.isRejected = False resvEx.startDT = datetime(sd.year, sd.month, sd.day, 0, 0) resvEx.endDT = datetime(ed.year, ed.month, ed.day, 23, 59) resvs = CrossLocationQueries.getReservations(location="CERN", resvExample=resvEx, rooms=rooms) collisions = [] for resv in resvs: for p in resv.splitToPeriods(endDT=resvEx.endDT, startDT=resvEx.startDT): collisions.append(Collision( ( p.startDT, p.endDT ), resv )) of = params.get("of", "csv") if of == "xml": result = createXML(collisions, req) else: result = createCSV(collisions, req) Factory.getDALManager().disconnect() DBMgr.getInstance().endRequest() return result
def getObject(self): """ """ if self.__resvID: from MaKaC.rb_location import CrossLocationQueries, Location obj = CrossLocationQueries.getReservations(resvID=self.__resvID, location=self.__location) return obj if self.__roomID: from MaKaC.rb_location import CrossLocationQueries, Location obj = CrossLocationQueries.getRooms(roomID=self.__roomID, location=self.__location) return obj if self.__categId: if not conference.CategoryManager().hasKey(self.__categId): raise errors.NoReportError( _("There is no category with id '%s', or it has been deleted") % self.__categId ) obj = conference.CategoryManager().getById(self.__categId) if self.__materialId: obj = obj.getMaterialById(self.__materialId) if self.__resId: obj = obj.getResourceById(self.__resId) return obj if not self.__confId: return None obj = conference.ConferenceHolder().getById(self.__confId) if obj == None: raise errors.NoReportError("The event you are trying to access does not exist or has been deleted") fr = materialFactories.ConfMFRegistry if self.__notifTplId: obj = obj.getAbstractMgr().getNotificationTplById(self.__notifTplId) return obj if self.__alarmId: obj = obj.getAlarmById(self.__alarmId) return obj if self.__trackId: obj = obj.getTrackById(self.__trackId) return obj if self.__menuLinkId: obj = obj.getDisplayMgr().getMenu().getLinkById(self.__menuLinkId) return obj if self.__contribTypeId: obj = obj.getContribTypeById(self.__contribTypeId) return obj if self.__abstractId: obj = obj.getAbstractMgr().getAbstractById(self.__abstractId) if obj == None: raise errors.NoReportError("The abstract you are trying to access does not exist or has been deleted") if self.__resId: return obj.getAttachmentById(self.__resId) if self.__registrantId: obj = obj.getRegistrantById(self.__registrantId) if obj == None: raise errors.NoReportError("The registrant you are trying to access does not exist or has been deleted") if self.__resId: return obj.getAttachmentById(self.__resId) if self.__sessionId: obj = obj.getSessionById(self.__sessionId) fr = materialFactories.SessionMFRegistry if obj == None: raise errors.NoReportError("The session you are trying to access does not exist or has been deleted") if self.__slotId: obj = obj.getSlotById(self.__slotId) if self.__contribId: obj = obj.getContributionById(self.__contribId) fr = materialFactories.ContribMFRegistry if obj == None: raise errors.NoReportError( "The contribution you are trying to access does not exist or has been deleted" ) if self.__reviewId: # obj must be a Contribution obj = obj.getReviewManager().getReviewById(self.__reviewId) if obj == None: raise errors.NoReportError("The review you are tring to access does not exist or has been deleted") if self.__subContribId and self.__contribId: obj = obj.getSubContributionById(self.__subContribId) fr = materialFactories.ContribMFRegistry if obj == None: raise errors.NoReportError( "The subcontribution you are trying to access does not exist or has been deleted" ) if not self.__materialId: return obj # first we check if it refers to a special type of material mat = None f = fr.getById(self.__materialId) if f: mat = f.get(obj) if not mat: mat = obj.getMaterialById(self.__materialId) if not self.__resId: return mat return mat.getResourceById(self.__resId)
def getObject(self): """ """ if self.__resvID: from MaKaC.rb_location import CrossLocationQueries, Location obj = CrossLocationQueries.getReservations( resvID=self.__resvID, location=self.__location) return obj if self.__roomID: from MaKaC.rb_location import CrossLocationQueries, Location obj = CrossLocationQueries.getRooms(roomID=self.__roomID, location=self.__location) return obj if self.__categId: if not conference.CategoryManager().hasKey(self.__categId): raise errors.NoReportError( _("There is no category with id '%s', or it has been deleted" ) % self.__categId) obj = conference.CategoryManager().getById(self.__categId) if self.__materialId: obj = obj.getMaterialById(self.__materialId) if self.__resId: obj = obj.getResourceById(self.__resId) return obj if not self.__confId: return None obj = conference.ConferenceHolder().getById(self.__confId) if obj == None: raise errors.NoReportError( "The event you are trying to access does not exist or has been deleted" ) fr = materialFactories.ConfMFRegistry if self.__notifTplId: obj = obj.getAbstractMgr().getNotificationTplById( self.__notifTplId) return obj if self.__alarmId: obj = obj.getAlarmById(self.__alarmId) return obj if self.__trackId: obj = obj.getTrackById(self.__trackId) return obj if self.__menuLinkId: obj = obj.getDisplayMgr().getMenu().getLinkById(self.__menuLinkId) return obj if self.__contribTypeId: obj = obj.getContribTypeById(self.__contribTypeId) return obj if self.__abstractId: obj = obj.getAbstractMgr().getAbstractById(self.__abstractId) if obj == None: raise errors.NoReportError( "The abstract you are trying to access does not exist or has been deleted" ) if self.__resId: return obj.getAttachmentById(self.__resId) if self.__registrantId: obj = obj.getRegistrantById(self.__registrantId) if obj == None: raise errors.NoReportError( "The registrant you are trying to access does not exist or has been deleted" ) if self.__resId: return obj.getAttachmentById(self.__resId) if self.__sessionId: obj = obj.getSessionById(self.__sessionId) fr = materialFactories.SessionMFRegistry if obj == None: raise errors.NoReportError( "The session you are trying to access does not exist or has been deleted" ) if self.__slotId: obj = obj.getSlotById(self.__slotId) if self.__contribId: obj = obj.getContributionById(self.__contribId) fr = materialFactories.ContribMFRegistry if obj == None: raise errors.NoReportError( "The contribution you are trying to access does not exist or has been deleted" ) if self.__reviewId: #obj must be a Contribution obj = obj.getReviewManager().getReviewById(self.__reviewId) if obj == None: raise errors.NoReportError( "The review you are tring to access does not exist or has been deleted" ) if self.__subContribId and self.__contribId: obj = obj.getSubContributionById(self.__subContribId) fr = materialFactories.ContribMFRegistry if obj == None: raise errors.NoReportError( "The subcontribution you are trying to access does not exist or has been deleted" ) if not self.__materialId: return obj #first we check if it refers to a special type of material mat = None f = fr.getById(self.__materialId) if f: mat = f.get(obj) if not mat: mat = obj.getMaterialById(self.__materialId) if not self.__resId: return mat return mat.getResourceById(self.__resId)