Ejemplo n.º 1
0
    def removeEquipment( equipmentName, *args, **kwargs ):
        from MaKaC.rb_location import Location
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        lst = EquipmentManager.getRoot()
        lst[location].remove( equipmentName )
        Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
Ejemplo n.º 2
0
 def getNumberOfReservableRooms( *args, **kwargs ):
     """ Documentation in base class. """
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     room = Factory.newRoom()
     room.isReservable = True
     room.isActive = True
     return Room.countRooms( roomExample = room, location = location )
Ejemplo n.º 3
0
 def setPossibleEquipment( equipmentList, *args, **kwargs ):
     from MaKaC.rb_location import Location
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     
     lst = EquipmentManager.getRoot()
     lst[location] = equipmentList
     Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst     # Force update
Ejemplo n.º 4
0
    def testReservationSpecificBlockingMethods(self):
        block = self._createTestBlocking()
        candResv = Location.getDefaultLocation().factory.newReservation()
        candResv.startDT = datetime.combine(block.startDate - timedelta(days=1), time())
        candResv.endDT = datetime.combine(block.endDate + timedelta(days=1), time(23, 59))
        candResv.repeatability = RepeatabilityEnum.daily
        candResv.isConfirmed = None

        candResv.room = self._room7
        self.assertTrue(candResv.getBlockingConflictState() is None) # No blocking
        self.assertEqual(candResv.getBlockedDates(), [])
        br = self._blockRoom(block, self._room7, False)
        block.update()
        self.assertEqual(candResv.getBlockingConflictState(), 'pending') # Pending blocking
        self.assertEqual(candResv.getBlockedDates(), [])
        br.approve(sendNotification=False)
        self.assertEqual(candResv.getBlockingConflictState(), 'active') # Active blocking
        blockingDays = frozenset((date(2010, 12, 31), date(2011, 1, 1)))
        self.assertEqual(frozenset(candResv.getBlockedDates()), blockingDays)
        # Test with various users set. This basically tests if all people who are allowed to override can actually override
        self.assertTrue(candResv.getBlockingConflictState(self._avatar1) is None) # room owner
        self.assertEqual(candResv.getBlockedDates(self._avatar1), [])
        self.assertTrue(candResv.getBlockingConflictState(self._avatar2) is None) # blocking owner
        self.assertEqual(candResv.getBlockedDates(self._avatar2), [])
        self.assertEqual(candResv.getBlockingConflictState(self._avatar3), 'active') # not permitted to override
        self.assertEqual(frozenset(candResv.getBlockedDates(self._avatar3)), blockingDays)
        self.assertTrue(candResv.getBlockingConflictState(self._avatar4) is None) # on blocking ACL
        self.assertEqual(candResv.getBlockedDates(self._avatar4), [])
        # Rejecting an existing blocking is not possible via the UI, but we can test it anyway
        br.reject(sendNotification=False)
        self.assertTrue(candResv.getBlockingConflictState() is None) # No blocking
        self.assertEqual(candResv.getBlockedDates(), [])
Ejemplo n.º 5
0
 def getNumberOfReservableRooms( *args, **kwargs ):
     """ Documentation in base class. """
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     room = Factory.newRoom()
     room.isReservable = True
     room.isActive = True
     return Room.countRooms( roomExample = room, location = location )
Ejemplo n.º 6
0
    def setPossibleEquipment(equipmentList, *args, **kwargs):
        from MaKaC.rb_location import Location
        location = kwargs.get('location',
                              Location.getDefaultLocation().friendlyName)

        lst = EquipmentManager.getRoot()
        lst[location] = equipmentList
        Factory.getDALManager().root[_EQUIPMENT_LIST] = lst  # Force update
Ejemplo n.º 7
0
 def getNumberOfRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns total number of rooms in database.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfRooms(location=name)
Ejemplo n.º 8
0
 def getNumberOfRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns total number of rooms in database.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfRooms(location=name)
Ejemplo n.º 9
0
 def getNumberOfActiveRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns number of rooms that are active (not logicaly deleted).
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfActiveRooms(location=name)
Ejemplo n.º 10
0
 def getNumberOfReservableRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns number of rooms which can be reserved.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfReservableRooms(location=name)
Ejemplo n.º 11
0
 def getNumberOfReservableRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns number of rooms which can be reserved.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfReservableRooms(location=name)
Ejemplo n.º 12
0
 def getNumberOfActiveRooms( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns number of rooms that are active (not logicaly deleted).
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     return location.factory.newRoom().getNumberOfActiveRooms(location=name)
Ejemplo n.º 13
0
    def removeEquipment(equipmentName, *args, **kwargs):
        from MaKaC.rb_location import Location
        location = kwargs.get('location',
                              Location.getDefaultLocation().friendlyName)

        lst = EquipmentManager.getRoot()
        lst[location].remove(equipmentName)
        Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
Ejemplo n.º 14
0
    def getPossibleEquipment( *args, **kwargs ):
        from MaKaC.rb_location import Location
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        lst = EquipmentManager.getRoot()
        if lst.get( location ) == None:
            lst[location] = []
            Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
        return lst[location]
Ejemplo n.º 15
0
 def getAttributes( *args, **kwargs ):
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     
     root = CustomAttributesManager.getRoot()
     
     if not root.has_key( location ):
         CustomAttributesManager.setAttributes( [], location = location )
     
     return CustomAttributesManager.getRoot()[location]
Ejemplo n.º 16
0
    def insertEquipment( equipmentName, *args, **kwargs ):
        from MaKaC.rb_location import Location
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        lst = EquipmentManager.getRoot()
        if lst.get( location ) == None:
            lst[location] = []
        lst[location].append( equipmentName )
        Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
Ejemplo n.º 17
0
    def getPossibleEquipment(*args, **kwargs):
        from MaKaC.rb_location import Location
        location = kwargs.get('location',
                              Location.getDefaultLocation().friendlyName)

        lst = EquipmentManager.getRoot()
        if lst.get(location) == None:
            lst[location] = []
            Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
        return lst[location]
Ejemplo n.º 18
0
 def removeAttribute( customAttributeName, *args, **kwargs ):
     """ Deletes attribute from the list of custom attributes. """
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     
     attsList = CustomAttributesManager.getAttributes( location = location )
     for at in attsList:
         if at['name'] == customAttributeName:
             attsList.remove( at )
             break;
     CustomAttributesManager.setAttributes( attsList, location = location )
Ejemplo n.º 19
0
    def setHidden( customAttributeName, isHidden, *args, **kwargs ):
        """ Makes attribute hidden."""
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        attsList = CustomAttributesManager.getAttributes( location = location )
        for at in attsList:
            if at['name'] == customAttributeName:
                at['hidden'] = isHidden
                break;
        CustomAttributesManager.setAttributes( attsList, location = location )
Ejemplo n.º 20
0
    def setRequired( customAttributeName, isRequired, *args, **kwargs ):
        """ Makes attribute required."""
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        attsList = CustomAttributesManager.getAttributes( location = location )
        for at in attsList:
            if at['name'] == customAttributeName:
                at['required'] = isRequired
                break;
        CustomAttributesManager.setAttributes( attsList, location = location )
Ejemplo n.º 21
0
    def insertEquipment(equipmentName, *args, **kwargs):
        from MaKaC.rb_location import Location
        location = kwargs.get('location',
                              Location.getDefaultLocation().friendlyName)

        lst = EquipmentManager.getRoot()
        if lst.get(location) == None:
            lst[location] = []
        lst[location].append(equipmentName)
        Factory.getDALManager().getRoot()[_EQUIPMENT_LIST] = lst
Ejemplo n.º 22
0
    def setAttributes( attsList, *args, **kwargs  ):
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )

        for at in attsList:
            errors = CustomAttributesManagerBase.checkAttribute( at )
            if errors: raise str( errors )

        dic = CustomAttributesManager.getRoot()
        dic[location] = attsList
        root = Factory.getDALManager().root
        root[_CUSTOM_ATTRIBUTES_LIST] = dic
Ejemplo n.º 23
0
    def insertAttribute( customAttribute, *args, **kwargs ):
        """ Adds new attribute to the list of custom attributes."""
        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
        
        errors = []
        errors = CustomAttributesManagerBase.checkAttribute( customAttribute )
        if errors: raise str( errors )

        attsList = CustomAttributesManager.getAttributes( location = location )
        attsList.append( customAttribute )
        CustomAttributesManager.setAttributes( attsList, location = location )
Ejemplo n.º 24
0
 def supportsAttributeManagement( *args, **kwargs ):
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     
     # CERN uses generic ZODB-based plugin which DOES allow
     # dynamic room attributes management.
     # However, CERN-specific needs require to turn off this 
     # feature, because rooms are managed centrally, and we
     # just import them.
     #if location == "CERN":
     #    return False
     
     return True
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    def start(self, obj):
        super(RoomBooking_Feature, self).start(obj)

        with obj._context('database'):
            # Tell indico to use the current database for roombooking stuff
            minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
            cfg = Configuration.Config.getInstance()
            minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams())

            obj._ph.getById('RoomBooking').setActive(True)

            DALManagerCERN.connect()
            initializeRoomBookingDB("Universe", force=False)
            DALManagerCERN.disconnect()
            # do not use the method for it as it tries to re-create jsvars and fails
            minfo._roomBookingModuleActive = True
            DALManagerCERN.connect()

            # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...)
            location = Location.getDefaultLocation()
            obj._rooms = []
            for i in xrange(1, 8):
                room = location.newRoom()
                room.locationName = location.friendlyName
                room.name = 'DummyRoom%d' % i
                room.site = 'a'
                room.building = 1
                room.floor = 'b'
                room.roomNr = 'c'
                room.latitude = ''
                room.longitude = ''
                room.isActive = True
                room.isReservable = True
                room.resvsNeedConfirmation = False
                room.responsibleId = 'fake-%d' % (((i - 1) % 2) + 1)
                room.whereIsKey = 'Nowhere'
                room.telephone = '123456789'
                room.capacity = 10
                room.division = ''
                room.surfaceArea = 50
                room.comments = ''
                room.setEquipment([])
                room.setAvailableVC([])
                room.insert()
                obj._rooms.append(room)
                setattr(obj, '_room%d' % i, room)
Ejemplo n.º 28
0
    def testReservationSpecificBlockingMethods(self):
        block = self._createTestBlocking()
        candResv = Location.getDefaultLocation().factory.newReservation()
        candResv.startDT = datetime.combine(
            block.startDate - timedelta(days=1), time())
        candResv.endDT = datetime.combine(block.endDate + timedelta(days=1),
                                          time(23, 59))
        candResv.repeatability = RepeatabilityEnum.daily
        candResv.isConfirmed = None

        candResv.room = self._room7
        self.assertTrue(
            candResv.getBlockingConflictState() is None)  # No blocking
        self.assertEqual(candResv.getBlockedDates(), [])
        br = self._blockRoom(block, self._room7, False)
        block.update()
        self.assertEqual(candResv.getBlockingConflictState(),
                         'pending')  # Pending blocking
        self.assertEqual(candResv.getBlockedDates(), [])
        br.approve(sendNotification=False)
        self.assertEqual(candResv.getBlockingConflictState(),
                         'active')  # Active blocking
        blockingDays = frozenset((date(2010, 12, 31), date(2011, 1, 1)))
        self.assertEqual(frozenset(candResv.getBlockedDates()), blockingDays)
        # Test with various users set. This basically tests if all people who are allowed to override can actually override
        self.assertTrue(
            candResv.getBlockingConflictState(self._avatar1) is
            None)  # room owner
        self.assertEqual(candResv.getBlockedDates(self._avatar1), [])
        self.assertTrue(
            candResv.getBlockingConflictState(self._avatar2) is
            None)  # blocking owner
        self.assertEqual(candResv.getBlockedDates(self._avatar2), [])
        self.assertEqual(candResv.getBlockingConflictState(self._avatar3),
                         'active')  # not permitted to override
        self.assertEqual(frozenset(candResv.getBlockedDates(self._avatar3)),
                         blockingDays)
        self.assertTrue(
            candResv.getBlockingConflictState(self._avatar4) is
            None)  # on blocking ACL
        self.assertEqual(candResv.getBlockedDates(self._avatar4), [])
        # Rejecting an existing blocking is not possible via the UI, but we can test it anyway
        br.reject(sendNotification=False)
        self.assertTrue(
            candResv.getBlockingConflictState() is None)  # No blocking
        self.assertEqual(candResv.getBlockedDates(), [])
Ejemplo n.º 29
0
    def start(self, obj):
        super(RoomBooking_Feature, self).start(obj)

        with obj._context('database'):
            # Tell indico to use the current database for roombooking stuff
            minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
            cfg = Configuration.Config.getInstance()
            minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams())

            obj._ph.getById('RoomBooking').setActive(True)

            DALManagerCERN.connect()
            initializeRoomBookingDB("Universe", force=False)
            DALManagerCERN.disconnect()
            # do not use the method for it as it tries to re-create jsvars and fails
            minfo._roomBookingModuleActive = True
            DALManagerCERN.connect()

            # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...)
            location = Location.getDefaultLocation()
            obj._rooms = []
            for i in xrange(1, 8):
                room = location.newRoom()
                room.locationName = location.friendlyName
                room.name = 'DummyRoom%d' % i
                room.site = 'a'
                room.building = 1
                room.floor = 'b'
                room.roomNr = 'c'
                room.latitude = ''
                room.longitude = ''
                room.isActive = True
                room.isReservable = True
                room.resvsNeedConfirmation = False
                room.responsibleId = 'fake-%d' % (((i - 1) % 2) + 1)
                room.whereIsKey = 'Nowhere'
                room.telephone = '123456789'
                room.capacity = 10
                room.division = ''
                room.surfaceArea = 50
                room.comments = ''
                room.setEquipment([])
                room.setAvailableVC([])
                room.insert()
                obj._rooms.append(room)
                setattr(obj, '_room%d' % i, room)
Ejemplo n.º 30
0
 def getTotalSurfaceAndCapacity( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns (total_surface, total_capacity) of all Active rooms.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     roomEx = location.factory.newRoom()
     roomEx.isActive = True
     roomEx.isReservable = True
     rooms = CrossLocationQueries.getRooms( roomExample = roomEx, location = name )
     totalSurface, totalCapacity = 0, 0
     for r in rooms:
         if r.surfaceArea:
             totalSurface += r.surfaceArea
         if r.capacity:
             totalCapacity += r.capacity
     return ( totalSurface, totalCapacity )
Ejemplo n.º 31
0
 def getTotalSurfaceAndCapacity( **kwargs ):
     """
     FINAL (not intented to be overriden)
     Returns (total_surface, total_capacity) of all Active rooms.
     """
     name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     location = Location.parse(name)
     roomEx = location.factory.newRoom()
     roomEx.isActive = True
     roomEx.isReservable = True
     rooms = CrossLocationQueries.getRooms( roomExample = roomEx, location = name )
     totalSurface, totalCapacity = 0, 0
     for r in rooms:
         if r.surfaceArea:
             totalSurface += r.surfaceArea
         if r.capacity:
             totalCapacity += r.capacity
     return ( totalSurface, totalCapacity )
Ejemplo n.º 32
0
 def _createResv(self, room, user, startDate, endDate, pre=False):
     resv = Location.getDefaultLocation().factory.newReservation()
     resv.room = room
     resv.startDT = datetime.combine(startDate, time(8, 30))
     resv.endDT = datetime.combine(endDate, time(17, 30))
     if startDate != endDate:
         resv.repeatability = RepeatabilityEnum.daily
     resv.reason = ''
     resv.needsAVCSupport = False
     resv.usesAVC = False
     resv.createdDT = datetime.now()
     resv.createdBy = str(user.getId())
     resv.bookedForName = user.getFullName()
     resv.contactEmail = user.getEmail()
     resv.contactPhone = user.getTelephone()
     resv.isRejected = False
     resv.isCancelled = False
     resv.isConfirmed = True if not pre else None
     resv.insert()
     return resv
Ejemplo n.º 33
0
 def _createResv(self, room, user, startDate, endDate, pre=False):
     resv = Location.getDefaultLocation().factory.newReservation()
     resv.room = room
     resv.startDT = datetime.combine(startDate, time(8, 30))
     resv.endDT = datetime.combine(endDate, time(17, 30))
     if startDate != endDate:
         resv.repeatability = RepeatabilityEnum.daily
     resv.reason = ''
     resv.needsAVCSupport = False
     resv.usesAVC = False
     resv.createdDT = datetime.now()
     resv.createdBy = str(user.getId())
     resv.bookedForName = user.getFullName()
     resv.contactEmail = user.getEmail()
     resv.contactPhone = user.getTelephone()
     resv.isRejected = False
     resv.isCancelled = False
     resv.isConfirmed = True if not pre else None
     resv.insert()
     return resv
Ejemplo n.º 34
0
    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()
        resvEx.endDT = datetime.combine(date.today(), time(17, 30))
        resvEx.startDT = resvEx.endDT.replace(hour=8) - timedelta(days=30)
        resvEx.repeatability = RepeatabilityEnum.daily
        collisions = resvEx.getCollisions(rooms=rooms)

        totalWorkingDays = sum(1 for day in iterdays(resvEx.startDT, resvEx.endDT) if day.weekday() not in (5, 6))
        booked = timedelta()
        for c in collisions:
            if c.startDT.weekday() in (5, 6):  # skip Saturday and Sunday
                continue
            booked += c.endDT - c.startDT
        totalBookableTime = totalWorkingDays * 9 * len(rooms)  # Hours
        bookedTime = (booked.days * 86400 + booked.seconds) / 3600.0
        if totalBookableTime > 0:
            return bookedTime / totalBookableTime
        else:
            return 0
Ejemplo n.º 35
0
    def _getSideMenu(self):
        minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()

        self._leftMenu = wcomponents.BasicSideMenu(
            self._getAW().getUser() != None)

        self._showResponsible = False

        if minfo.getRoomBookingModuleActive() and CrossLocationDB.isConnected(
        ):
            self._showResponsible = \
                (self._getAW().getUser() != None) and \
                (Room.isAvatarResponsibleForRooms(self._getAW().getUser()) \
                 or self._getAW().getUser().isAdmin() \
                 or self._getAW().getUser().isRBAdmin())

        self._roomsOpt = wcomponents.SideMenuSection(_("View Rooms"), \
                                        urlHandlers.UHRoomBookingSearch4Rooms.getURL() )
        self._roomSearchOpt = wcomponents.SideMenuItem(
            _("Search rooms"),
            urlHandlers.UHRoomBookingSearch4Rooms.getURL(),
            enabled=True)
        self._roomMapOpt = wcomponents.SideMenuItem(
            _("Map of rooms"),
            urlHandlers.UHRoomBookingMapOfRooms.getURL(),
            enabled=True)
        self._myRoomListOpt = wcomponents.SideMenuItem(
            _("My rooms"),
            urlHandlers.UHRoomBookingRoomList.getURL(onlyMy=True),
            enabled=self._showResponsible)
        self._bookingsOpt = wcomponents.SideMenuSection(_("View Bookings"), \
                                        urlHandlers.UHRoomBookingSearch4Bookings.getURL())
        self._bookARoomOpt = wcomponents.SideMenuItem(_("Book a Room"), \
                                        urlHandlers.UHRoomBookingSearch4Rooms.getURL( forNewBooking = True ),
                                        enabled=True)
        self._bookingListSearchOpt = wcomponents.SideMenuItem(
            _("Search bookings"),
            urlHandlers.UHRoomBookingSearch4Bookings.getURL(),
            enabled=True)
        self._bookingListCalendarOpt = wcomponents.SideMenuItem(
            _("Calendar"),
            urlHandlers.UHRoomBookingBookingList.getURL(today=True,
                                                        allRooms=True),
            enabled=True)
        self._myBookingListOpt = wcomponents.SideMenuItem(
            _("My bookings"),
            urlHandlers.UHRoomBookingBookingList.getURL(onlyMy=True,
                                                        autoCriteria=True),
            enabled=True)
        self._myPreBookingListOpt = wcomponents.SideMenuItem(
            _("My PRE-bookings"),
            urlHandlers.UHRoomBookingBookingList.getURL(onlyMy=True,
                                                        onlyPrebookings=True,
                                                        autoCriteria=True),
            enabled=True)
        self._usersBookings = wcomponents.SideMenuItem(
            _("Bookings in my rooms"),
            urlHandlers.UHRoomBookingBookingList.getURL(ofMyRooms=True,
                                                        autoCriteria=True),
            enabled=self._showResponsible)
        self._usersPrebookings = wcomponents.SideMenuItem(
            _("PRE-bookings in my rooms"),
            urlHandlers.UHRoomBookingBookingList.getURL(ofMyRooms=True,
                                                        onlyPrebookings=True,
                                                        autoCriteria=True),
            enabled=self._showResponsible)

        self._blockingsOpt = wcomponents.SideMenuSection(_("Room Blocking"))
        self._usersBlockings = wcomponents.SideMenuItem(
            _("Blockings for my rooms"),
            urlHandlers.UHRoomBookingBlockingsMyRooms.getURL(
                filterState='pending'),
            enabled=self._showResponsible)
        if self._showResponsible:
            self._myBlockingListOpt = wcomponents.SideMenuItem(
                _("My blockings"),
                urlHandlers.UHRoomBookingBlockingList.getURL(onlyMine=True,
                                                             onlyRecent=True),
                enabled=True)
        else:
            self._myBlockingListOpt = wcomponents.SideMenuItem(
                _("Blockings"),
                urlHandlers.UHRoomBookingBlockingList.getURL(onlyRecent=True),
                enabled=True)
        self._blockRooms = wcomponents.SideMenuItem(
            _("Block rooms"),
            urlHandlers.UHRoomBookingBlockingForm.getURL(),
            enabled=self._showResponsible)

        if self._rh._getUser().isRBAdmin():
            self._adminSect = wcomponents.SideMenuSection(_("Administration"), \
                                            urlHandlers.UHRoomBookingAdmin.getURL() )
            self._adminOpt = wcomponents.SideMenuItem(_("Administration"), \
                                            urlHandlers.UHRoomBookingAdmin.getURL() )

        self._leftMenu.addSection(self._roomsOpt)
        self._roomsOpt.addItem(self._roomSearchOpt)
        if Location.getDefaultLocation() and Location.getDefaultLocation(
        ).isMapAvailable():
            self._roomsOpt.addItem(self._roomMapOpt)
        self._roomsOpt.addItem(self._myRoomListOpt)
        self._leftMenu.addSection(self._bookingsOpt)
        self._bookingsOpt.addItem(self._bookARoomOpt)
        self._bookingsOpt.addItem(self._bookingListSearchOpt)
        self._bookingsOpt.addItem(self._bookingListCalendarOpt)
        self._bookingsOpt.addItem(self._myBookingListOpt)
        self._bookingsOpt.addItem(self._myPreBookingListOpt)
        self._bookingsOpt.addItem(self._usersBookings)
        self._bookingsOpt.addItem(self._usersPrebookings)
        self._leftMenu.addSection(self._blockingsOpt)
        self._blockingsOpt.addItem(self._blockRooms)
        self._blockingsOpt.addItem(self._myBlockingListOpt)
        self._blockingsOpt.addItem(self._usersBlockings)
        if self._rh._getUser().isRBAdmin():
            self._leftMenu.addSection(self._adminSect)
            self._adminSect.addItem(self._adminOpt)
        return self._leftMenu
Ejemplo n.º 36
0
 def getLocationName(self):
     if self.__class__.__name__ == 'RoomBase':
         return Location.getDefaultLocation().friendlyName
         #raise 'This method is purely virtual. Call it only on derived objects.'
     return self.getLocationName()  # Subclass
Ejemplo n.º 37
0
 def getNumberOfRooms( *args, **kwargs ):
     """ Documentation in base class. """
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     return Room.countRooms( location = location )
Ejemplo n.º 38
0
    def start(self, obj):
        super(RoomBooking_Feature, self).start(obj)

        with obj._context('database'):
            # Tell indico to use the current database for roombooking stuff
            minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
            cfg = Configuration.Config.getInstance()
            minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams())

            obj._ph.getById('RoomBooking').setActive(True)

            DALManagerCERN.connect()
            initializeRoomBookingDB("Universe", force=False)
            DALManagerCERN.disconnect()
            # do not use the method for it as it tries to re-create jsvars and fails
            minfo._roomBookingModuleActive = True
            DALManagerCERN.connect()

            # Create dummy avatars in obj._avatarN
            ah = AvatarHolder()
            obj._avatars = []
            for i in xrange(1, 5):
                avatar = Avatar()
                avatar.setName("fake-%d" % i)
                avatar.setSurName("fake")
                avatar.setOrganisation("fake")
                avatar.setLang("en_GB")
                avatar.setEmail("*****@*****.**" % i)
                avatar.setId("rb-fake-%d" % i)

                # setting up the login info
                li = LoginInfo("fake-%d" % i, "fake-%d" % i)
                ih = AuthenticatorMgr()
                userid = ih.createIdentity(li, avatar, "Local")
                ih.add(userid)

                # activate the account
                avatar.activateAccount()

                ah.add(avatar)
                obj._avatars.append(avatar)
                setattr(obj, '_avatar%d' % i, avatar)

            # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...)
            location = Location.getDefaultLocation()
            obj._rooms = []
            for i in xrange(1, 8):
                room = location.newRoom()
                room.locationName = location.friendlyName
                room.name = 'DummyRoom%d' % i
                room.site = 'a'
                room.building = 1
                room.floor = 'b'
                room.roomNr = 'c'
                room.latitude = ''
                room.longitude = ''
                room.isActive = True
                room.isReservable = True
                room.resvsNeedConfirmation = False
                room.responsibleId = 'rb-fake-%d' % (((i - 1) % 2) + 1)
                room.whereIsKey = 'Nowhere'
                room.telephone = '123456789'
                room.capacity = 10
                room.division = ''
                room.surfaceArea = 50
                room.comments = ''
                room.setEquipment([])
                room.setAvailableVC([])
                room.insert()
                obj._rooms.append(room)
                setattr(obj, '_room%d' % i, room)
Ejemplo n.º 39
0
    def _getSideMenu(self):
        minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()

        self._leftMenu = wcomponents.BasicSideMenu(self._getAW().getUser() != None)

        self._showResponsible = False


        if minfo.getRoomBookingModuleActive() and CrossLocationDB.isConnected():
            self._showResponsible = \
                (self._getAW().getUser() != None) and \
                (Room.isAvatarResponsibleForRooms(self._getAW().getUser()) \
                 or self._getAW().getUser().isAdmin() \
                 or self._getAW().getUser().isRBAdmin())

        self._roomsOpt = wcomponents.SideMenuSection(_("View Rooms"), \
                                        urlHandlers.UHRoomBookingSearch4Rooms.getURL() )
        self._roomSearchOpt = wcomponents.SideMenuItem(_("Search rooms"),
                                        urlHandlers.UHRoomBookingSearch4Rooms.getURL(),
                                        enabled=True)
        self._roomMapOpt = wcomponents.SideMenuItem(_("Map of rooms"),
                                        urlHandlers.UHRoomBookingMapOfRooms.getURL(),
                                        enabled=True)
        self._myRoomListOpt = wcomponents.SideMenuItem(_("My rooms"),
                                        urlHandlers.UHRoomBookingRoomList.getURL( onlyMy = True ),
                                        enabled=self._showResponsible)
        self._bookingsOpt = wcomponents.SideMenuSection(_("View Bookings"), \
                                        urlHandlers.UHRoomBookingSearch4Bookings.getURL())
        self._bookARoomOpt = wcomponents.SideMenuItem(_("Book a Room"), \
                                        urlHandlers.UHRoomBookingSearch4Rooms.getURL( forNewBooking = True ),
                                        enabled=True)
        self._bookingListSearchOpt = wcomponents.SideMenuItem(_("Search bookings"),
                                        urlHandlers.UHRoomBookingSearch4Bookings.getURL(),
                                        enabled=True)
        self._bookingListCalendarOpt = wcomponents.SideMenuItem(_("Calendar"),
                                        urlHandlers.UHRoomBookingBookingList.getURL( today = True, allRooms = True ),
                                        enabled=True)
        self._myBookingListOpt = wcomponents.SideMenuItem(_("My bookings"),
                                        urlHandlers.UHRoomBookingBookingList.getURL( onlyMy = True, autoCriteria = True ),
                                        enabled=True)
        self._myPreBookingListOpt = wcomponents.SideMenuItem(_("My PRE-bookings"),
                                        urlHandlers.UHRoomBookingBookingList.getURL( onlyMy = True, onlyPrebookings = True, autoCriteria = True ),
                                        enabled=True)
        self._usersBookings = wcomponents.SideMenuItem(_("Bookings in my rooms"),
                                        urlHandlers.UHRoomBookingBookingList.getURL( ofMyRooms = True, autoCriteria = True ),
                                        enabled=self._showResponsible)
        self._usersPrebookings = wcomponents.SideMenuItem(_("PRE-bookings in my rooms"),
                                        urlHandlers.UHRoomBookingBookingList.getURL( ofMyRooms = True, onlyPrebookings = True, autoCriteria = True ),
                                        enabled=self._showResponsible)

        self._blockingsOpt = wcomponents.SideMenuSection(_("Room Blocking"))
        self._usersBlockings = wcomponents.SideMenuItem(_("Blockings for my rooms"),
                                        urlHandlers.UHRoomBookingBlockingsMyRooms.getURL( filterState='pending' ),
                                        enabled=self._showResponsible)
        if self._showResponsible:
            self._myBlockingListOpt = wcomponents.SideMenuItem(_("My blockings"),
                                            urlHandlers.UHRoomBookingBlockingList.getURL( onlyMine = True, onlyRecent = True ),
                                            enabled=True)
        else:
            self._myBlockingListOpt = wcomponents.SideMenuItem(_("Blockings"),
                                            urlHandlers.UHRoomBookingBlockingList.getURL( onlyRecent = True ),
                                            enabled=True)
        self._blockRooms = wcomponents.SideMenuItem(_("Block rooms"),
                                        urlHandlers.UHRoomBookingBlockingForm.getURL(),
                                        enabled=self._showResponsible)


        if self._rh._getUser().isRBAdmin():
            self._adminSect = wcomponents.SideMenuSection(_("Administration"), \
                                            urlHandlers.UHRoomBookingAdmin.getURL() )
            self._adminOpt = wcomponents.SideMenuItem(_("Administration"), \
                                            urlHandlers.UHRoomBookingAdmin.getURL() )

        self._leftMenu.addSection( self._roomsOpt )
        self._roomsOpt.addItem( self._roomSearchOpt )
        if Location.getDefaultLocation() and Location.getDefaultLocation().isMapAvailable():
            self._roomsOpt.addItem( self._roomMapOpt )
        self._roomsOpt.addItem( self._myRoomListOpt )
        self._leftMenu.addSection( self._bookingsOpt )
        self._bookingsOpt.addItem( self._bookARoomOpt )
        self._bookingsOpt.addItem( self._bookingListSearchOpt )
        self._bookingsOpt.addItem( self._bookingListCalendarOpt )
        self._bookingsOpt.addItem( self._myBookingListOpt )
        self._bookingsOpt.addItem( self._myPreBookingListOpt )
        self._bookingsOpt.addItem( self._usersBookings )
        self._bookingsOpt.addItem( self._usersPrebookings )
        self._leftMenu.addSection( self._blockingsOpt )
        self._blockingsOpt.addItem( self._blockRooms )
        self._blockingsOpt.addItem( self._myBlockingListOpt )
        self._blockingsOpt.addItem( self._usersBlockings )
        if self._rh._getUser().isRBAdmin():
            self._leftMenu.addSection( self._adminSect )
            self._adminSect.addItem( self._adminOpt )
        return self._leftMenu
Ejemplo n.º 40
0
    def start(self, obj):
        super(RoomBooking_Feature, self).start(obj)

        with obj._context('database'):
            # Tell indico to use the current database for roombooking stuff
            minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
            cfg = Configuration.Config.getInstance()
            minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams())

            obj._ph.getById('RoomBooking').setActive(True)

            DALManagerCERN.connect()
            initializeRoomBookingDB("Universe", force=False)
            DALManagerCERN.disconnect()
            # do not use the method for it as it tries to re-create jsvars and fails
            minfo._roomBookingModuleActive = True
            DALManagerCERN.connect()

            # Create dummy avatars in obj._avatarN
            ah = AvatarHolder()
            obj._avatars = []
            for i in xrange(1, 5):
                avatar = Avatar()
                avatar.setName("fake-%d" % i)
                avatar.setSurName("fake")
                avatar.setOrganisation("fake")
                avatar.setLang("en_GB")
                avatar.setEmail("*****@*****.**" % i)
                avatar.setId("rb-fake-%d" % i)

                # setting up the login info
                li = LoginInfo("fake-%d" % i, "fake-%d" % i)
                ih = AuthenticatorMgr()
                userid = ih.createIdentity(li, avatar, "Local")
                ih.add(userid)

                # activate the account
                avatar.activateAccount()

                ah.add(avatar)
                obj._avatars.append(avatar)
                setattr(obj, '_avatar%d' % i, avatar)

            # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...)
            location = Location.getDefaultLocation()
            obj._rooms = []
            for i in xrange(1, 8):
                room = location.newRoom()
                room.locationName = location.friendlyName
                room.name = 'DummyRoom%d' % i
                room.site = 'a'
                room.building = 1
                room.floor = 'b'
                room.roomNr = 'c'
                room.latitude = ''
                room.longitude = ''
                room.isActive = True
                room.isReservable = True
                room.resvsNeedConfirmation = False
                room.responsibleId = 'rb-fake-%d' % (((i - 1) % 2) + 1)
                room.whereIsKey = 'Nowhere'
                room.telephone = '123456789'
                room.capacity = 10
                room.division = ''
                room.surfaceArea = 50
                room.comments = ''
                room.setEquipment([])
                room.setAvailableVC([])
                room.insert()
                obj._rooms.append(room)
                setattr(obj, '_room%d' % i, room)
Ejemplo n.º 41
0
 def getNumberOfRooms( *args, **kwargs ):
     """ Documentation in base class. """
     location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName )
     return Room.countRooms( location = location )
Ejemplo n.º 42
0
 def getLocationName( self ):
     if self.__class__.__name__ == 'RoomBase':
         return Location.getDefaultLocation().friendlyName
         #raise 'This method is purely virtual. Call it only on derived objects.'
     return self.getLocationName() # Subclass