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
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 )
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
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(), [])
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 )
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
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)
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)
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)
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)
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)
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)
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
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]
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]
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
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]
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 )
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 )
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 )
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
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
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 )
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
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)
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)
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)
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(), [])
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)
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 )
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 )
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
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
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
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
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
def getNumberOfRooms( *args, **kwargs ): """ Documentation in base class. """ location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) return Room.countRooms( location = location )
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)
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
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)
def getNumberOfRooms( *args, **kwargs ): """ Documentation in base class. """ location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) return Room.countRooms( location = location )
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