当前位置: 首页>>代码示例>>Python>>正文


Python rb_reservation.ReservationBase类代码示例

本文整理汇总了Python中MaKaC.rb_reservation.ReservationBase的典型用法代码示例。如果您正苦于以下问题:Python ReservationBase类的具体用法?Python ReservationBase怎么用?Python ReservationBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ReservationBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

 def update( self, udpateReservationIndex=True ):
     """ Documentation in base class. """
     ReservationBase.update( self )
     if udpateReservationIndex:
         self._removeFromDayReservationsIndex()
         self._addToDayReservationsIndex()
         self._p_changed = True
开发者ID:davidmorrison,项目名称:indico,代码行数:7,代码来源:reservation.py

示例2: rebuildRoomReservationsIndex

    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()
开发者ID:davidmorrison,项目名称:indico,代码行数:35,代码来源:reservation.py

示例3: insert

    def insert( self ):
        """ Documentation in base class. """
        ReservationBase.insert( self )

        resvBTree = Reservation.getReservationsRoot()
        # Ensure ID
        if self.id == None:
            # Maximum ID + 1
            if len( resvBTree ) > 0:
                self.id = resvBTree.maxKey() + 1
            else:
                self.id = 1 # Can not use maxKey for 1st record in a tree
        # Add self to the BTree
        resvBTree[self.id] = self
        
        # Update room => room reservations index
        roomReservationsIndexBTree = Reservation.getRoomReservationsIndexRoot()
        resvs = roomReservationsIndexBTree.get( self.room.id )
        if resvs == None:
            resvs = [] # New list of reservations for this room
            roomReservationsIndexBTree.insert( self.room.id, resvs )
        resvs.append( self )
        roomReservationsIndexBTree[self.room.id] = resvs

        # Update user => user reservations index
        userReservationsIndexBTree = Reservation.getUserReservationsIndexRoot()
        resvs = userReservationsIndexBTree.get( self.createdBy )
        if resvs == None:
            resvs = [] # New list of reservations for this room
            userReservationsIndexBTree.insert( self.createdBy, resvs )
        resvs.append( self )
        userReservationsIndexBTree[self.createdBy] = resvs
        
        # Update day => reservations index
        self._addToDayReservationsIndex()
开发者ID:davidmorrison,项目名称:indico,代码行数:35,代码来源:reservation.py

示例4: getExcludedDays

    def getExcludedDays(self):
        ReservationBase.getExcludedDays(self)
        from copy import copy

        lst = copy(self._excludedDays)
        lst.sort()
        return lst
开发者ID:arescope,项目名称:indico,代码行数:7,代码来源:reservation.py

示例5: includeDay

 def includeDay( self, dayD ):
     """
     Inserts dayD into list of excluded days.
     dayD should be of date type (not datetime).
     """
     ReservationBase.includeDay( self, dayD )
     lst = self._excludedDays 
     lst.remove( dayD )
     self._excludedDays = lst  # Force update
开发者ID:davidmorrison,项目名称:indico,代码行数:9,代码来源:reservation.py

示例6: _getAnswer

    def _getAnswer(self):
        p = ReservationBase()
        p.startDT = self._startDT
        p.endDT = self._endDT
        p.repeatability = self._repeatability

        rooms = CrossLocationQueries.getRooms(location=self._location, resvExample=p, available=True)

        return [room.id for room in rooms]
开发者ID:aninhalacerda,项目名称:indico,代码行数:9,代码来源:roomBooking.py

示例7: excludeDay

 def excludeDay( self, dayD ):
     """
     Inserts dayD into list of excluded days.
     dayD should be of date type (NOT datetime).
     """
     ReservationBase.excludeDay( self, dayD )
     lst = self._excludedDays 
     if not dayD in lst:
         lst.append( dayD )
     self._excludedDays = lst  # Force update
开发者ID:davidmorrison,项目名称:indico,代码行数:10,代码来源:reservation.py

示例8: changeCreator

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)
开发者ID:Ictp,项目名称:indico,代码行数:54,代码来源:changeCreatorToReservation.py

示例9: _postprocess

    def _postprocess(self, obj, fossil, iface):

        if iface is IRoomMetadataWithReservationsFossil:
            (startDT, endDT) = (self._fromDT or MIN_DATETIME,
                                self._toDT or MAX_DATETIME)

            if self._fromDT or self._toDT:
                toDate = self._toDT.date() if self._toDT else None
                fromDate = self._fromDT.date() if self._fromDT else None

                resvEx = ReservationBase()
                resvEx.startDT = startDT
                resvEx.endDT = endDT
                resvEx.room = obj
                resvEx.isRejected = False
                resvEx.isCancelled = False

                if fromDate != toDate:
                    resvEx.repeatability = RepeatabilityEnum.daily

                resvs = set(c.withReservation for c in resvEx.getCollisions())
            else:
                resvs = obj.getReservations()

            iresvs1, iresvs2 = itertools.tee(itertools.ifilter(self._resvFilter, resvs), 2)
            fresvs = fossilize(iresvs1, IRoomReservationMetadataFossil, tz=self._tz, naiveTZ=self._serverTZ)

            for fresv, resv in itertools.izip(iter(fresvs), iresvs2):
                self._addOccurrences(fresv, resv, startDT, endDT)

            fossil['reservations'] = fresvs

        return fossil
开发者ID:VishrutMehta,项目名称:indico,代码行数:33,代码来源:http_api.py

示例10: listResv4User

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()
开发者ID:Ictp,项目名称:indico,代码行数:14,代码来源:changeCreatorToReservation.py

示例11: getReservations2

    def getReservations2():
        from MaKaC.rb_room import RoomBase
        
        Test.dalManager.connect()
        
        resvEx = Factory.newReservation()
        resvEx.startDT = datetime( 2006, 12, 01, 10 )
        resvEx.endDT = datetime( 2006, 12, 14, 15 )
        resvEx.repeatability = 0 # Daily
        
        #ReservationBase.getReservations( \
        #    roomExample = roomEx, 
        #    resvExample = resvEx,
        #    available = True )

        resv = ReservationBase.getReservations( resvID = 363818 )
        print resv
        r = Reservation()
        r.room = resv.room
        r.startDT = datetime( 2006, 10, 13, 8, 30 )
        r.endDT = datetime( 2006, 10, 13, 17, 30 )
        col = r.getCollisions()
        print col

        Test.dalManager.disconnect()
开发者ID:davidmorrison,项目名称:indico,代码行数:25,代码来源:reservation.py

示例12: getAverageOccupation

    def getAverageOccupation( **kwargs ):
        """
        FINAL (not intented to be overriden)
        Returns float <0, 1> representing how often - on the avarage -
        the rooms are booked during the working hours. (1 == all the time, 0 == never).
        """

        name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        # Get active, publically reservable rooms
        from MaKaC.rb_factory import Factory
        roomEx = Factory.newRoom()
        roomEx.isActive = True
        roomEx.isReservable = True

        rooms = CrossLocationQueries.getRooms( roomExample = roomEx, location = name )

        # Find collisions with last month period
        from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum
        resvEx = ReservationBase()
        now = datetime.now()
        resvEx.endDT = datetime( now.year, now.month, now.day, 17, 30 )
        resvEx.startDT = resvEx.endDT - timedelta( 30, 9 * 3600 ) # - 30 days and 9 hours
        resvEx.repeatability = RepeatabilityEnum.daily
        collisions = resvEx.getCollisions( rooms = rooms )

        totalWorkingDays = 0
        weekends = 0
        for day in iterdays( resvEx.startDT, resvEx.endDT ):
            if day.weekday() in [5,6]: # Skip Saturday and Sunday
                weekends += 1
                continue
            # if c.startDT is CERN Holiday: continue
            totalWorkingDays += 1

        booked = timedelta( 0 )
        for c in collisions:
            if c.startDT.weekday() in [5,6]: # Skip Saturday and Sunday
                continue
            # if c.startDT is CERN Holiday: continue
            booked = booked + ( c.endDT - c.startDT )
        totalBookableTime = totalWorkingDays * 9 * len( rooms ) # Hours
        bookedTime = booked.days * 24 + 1.0 * booked.seconds / 3600 # Hours
        if totalBookableTime > 0:
            return bookedTime / totalBookableTime
        else:
            return 0 # Error (no rooms in db)
开发者ID:vstitches,项目名称:indico,代码行数:47,代码来源:rb_room.py

示例13: insert

    def insert(self):
        """ Documentation in base class. """
        ReservationBase.insert(self)

        resvBTree = Reservation.getReservationsRoot()
        # Ensure ID
        if self.id == None:
            #            # Maximum ID + 1
            #            if len( resvBTree ) > 0:
            #                self.id = resvBTree.maxKey() + 1
            #            else:
            #                self.id = 1 # Can not use maxKey for 1st record in a tree
            # Faster version of the code above
            try:
                self.id = resvBTree.maxKey() + 1
            except ValueError:
                self.id = 1
        # Add self to the BTree
        resvBTree[self.id] = self

        # Update room => room reservations index
        roomReservationsIndexBTree = Reservation.getRoomReservationsIndexRoot()
        resvs = roomReservationsIndexBTree.get(self.room.id)
        if resvs == None:
            resvs = []  # New list of reservations for this room
            roomReservationsIndexBTree.insert(self.room.id, resvs)
        resvs.append(self)
        roomReservationsIndexBTree[self.room.id] = resvs

        # Update user => user reservations index
        userReservationsIndexBTree = Reservation.getUserReservationsIndexRoot()
        resvs = userReservationsIndexBTree.get(self.createdBy)
        if resvs == None:
            resvs = []  # New list of reservations for this room
            userReservationsIndexBTree.insert(self.createdBy, resvs)
        resvs.append(self)
        userReservationsIndexBTree[self.createdBy] = resvs

        # Update day => reservations index
        self._addToDayReservationsIndex()

        # Update room+day => reservations index
        self._addToRoomDayReservationsIndex()

        self._notify("reservationCreated")
开发者ID:arescope,项目名称:indico,代码行数:45,代码来源:reservation.py

示例14: includeDay

    def includeDay(self, dayD):
        """
        Inserts dayD into list of excluded days.
        dayD should be of date type (not datetime).
        """
        ReservationBase.includeDay(self, dayD)
        lst = self._excludedDays
        lst.remove(dayD)
        self._excludedDays = lst  # Force update

        # Re-indexing that day
        dayReservationsIndexBTree = Reservation.getDayReservationsIndexRoot()
        resvs = dayReservationsIndexBTree.get(dayD)
        if resvs is None:
            resvs = []
            dayReservationsIndexBTree.insert(dayD, resvs)
        resvs.append(self)
        dayReservationsIndexBTree[dayD] = resvs
开发者ID:arescope,项目名称:indico,代码行数:18,代码来源:reservation.py

示例15: getReservations

    def getReservations( self, resvExample = None, archival = None ):
        """
        FINAL (not intented to be overriden)
        Returns reservations of this room, meeting specified criteria.
        Look ReservationBase.getReservations for details.
        """
        # Simply redirect to the plugin
        from MaKaC.rb_reservation import ReservationBase

        return ReservationBase.getReservations( resvExample = resvExample, rooms = [self], archival = archival )
开发者ID:iason-andr,项目名称:indico,代码行数:10,代码来源:rb_room.py


注:本文中的MaKaC.rb_reservation.ReservationBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。