Changeset dab490 in indico
- Timestamp:
- 02/08/10 20:39:17 (3 years ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, new-webex, prov-dual-interface, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, b8c30da8ebdbdcbd675a873997cc3e95f567de49, 4287315ec967a3da168d83963c14001db8487d53
- Children:
- 073081, 420560, f3d0f4
- Parents:
- 046026
- git-author:
- Jose Benito <jose.benito.gonzalez@…> (02/08/10 20:33:54)
- git-committer:
- Jose Benito <jose.benito.gonzalez@…> (02/08/10 20:39:17)
- Location:
- indico/MaKaC
- Files:
-
- 2 edited
-
plugins/RoomBooking/default/reservation.py (modified) (33 diffs)
-
webinterface/rh/roomBooking.py (modified) (101 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/plugins/RoomBooking/default/reservation.py
r9033fd rdab490 32 32 33 33 from datetime import datetime 34 from MaKaC.common.logger import Logger 34 35 35 36 # Branch name in ZODB root … … 40 41 41 42 class Reservation( Persistent, ReservationBase ): 42 """ 43 ZODB specific implementation. 44 43 """ 44 ZODB specific implementation. 45 45 46 For documentation of methods see base class. 46 47 """ 47 48 48 49 __dalManager = Factory.getDALManager() 49 50 … … 52 53 self._excludedDays = [] 53 54 self.useVC = [] 54 55 55 56 def getUseVC( self ): 56 57 try: … … 75 76 def getDayReservationsIndexRoot( ): 76 77 return Reservation.__dalManager.getRoot(_DAY_RESERVATIONS_INDEX) 77 78 78 79 def insert( self ): 79 80 """ Documentation in base class. """ … … 90 91 # Add self to the BTree 91 92 resvBTree[self.id] = self 92 93 93 94 # Update room => room reservations index 94 95 roomReservationsIndexBTree = Reservation.getRoomReservationsIndexRoot() … … 108 109 resvs.append( self ) 109 110 userReservationsIndexBTree[self.createdBy] = resvs 110 111 111 112 # Update day => reservations index 112 113 self._addToDayReservationsIndex() 113 114 114 115 def update( self, udpateReservationIndex=True ): 115 116 """ Documentation in base class. """ … … 120 121 self._p_changed = True 121 122 122 # Warning: 123 # Warning: 123 124 # createdBy, once assigned to rerservation, CAN NOT be changed later (index!) 124 125 # room, once assigned to reservation, CAN NOT be changed later (index!) 125 126 126 127 127 128 def remove( self ): 128 129 """ Documentation in base class. """ 129 130 resvBTree = Reservation.getReservationsRoot() 130 131 del resvBTree[self.id] 131 132 132 133 # Update room => room reservations index 133 134 roomReservationsIndexBTree = Reservation.getRoomReservationsIndexRoot() … … 140 141 resvs = userReservationsIndexBTree[self.createdBy] # must exist 141 142 resvs.remove( self ) 142 userReservationsIndexBTree[self.createdBy] = resvs 143 userReservationsIndexBTree[self.createdBy] = resvs 143 144 144 145 # Update day => reservations index … … 147 148 def _addToDayReservationsIndex( self ): 148 149 dayReservationsIndexBTree = Reservation.getDayReservationsIndexRoot() 149 150 150 151 for period in self.splitToPeriods(): 151 152 day = period.startDT.date() … … 160 161 dayReservationsIndexBTree = Reservation.getDayReservationsIndexRoot() 161 162 162 # Search for self in the whole index 163 # Search for self in the whole index 163 164 # (the key may have changed) 164 165 days = [] … … 166 167 if self in resvs: 167 168 days.append( day ) 168 169 169 170 for day in days: 170 171 resvs = dayReservationsIndexBTree[day] 171 172 resvs.remove( self ) 172 173 dayReservationsIndexBTree[day] = resvs 173 174 174 175 175 176 @staticmethod … … 185 186 location = kwargs.get( 'location' ) 186 187 days = kwargs.get( 'days' ) 187 188 188 189 ret_lst = [] 189 190 counter = 0 190 191 root = Factory.getDALManager().root 191 192 192 193 if resvID != None: 193 194 return root[_RESERVATIONS].get( resvID ) 194 195 195 196 resvCandidates = None 196 197 … … 206 207 resvCandidates += roomResvs 207 208 alreadyRoomFiltered = True 208 209 209 210 if resvCandidates == None and resvEx != None and resvEx.createdBy != None: 210 211 resvCandidates = Reservation.getUserReservationsIndexRoot().get( resvEx.createdBy ) … … 228 229 new.append( resv ) 229 230 resvCandidates = new 230 231 231 232 if resvCandidates == None: 232 233 resvCandidates = Reservation.getReservationsRoot().itervalues() 233 234 234 235 for resvCandidate in resvCandidates: 235 # Apply all conditions 236 # Apply all conditions 236 237 237 238 if archival != None: 238 239 if resvCandidate.isArchival != archival: 239 240 continue 240 241 241 242 if location != None: 242 243 # If location is specified, use only rooms from this location … … 247 248 if resvCandidate.isHeavy != heavy: 248 249 continue 249 250 250 251 # Does the reservation overlap on the specified period? 251 252 if resvEx != None: … … 257 258 if resvCandidate.room not in rooms: 258 259 continue 259 260 260 261 if resvEx.createdDT != None: 261 262 if resvEx.createdDT != resvCandidate.createdDT: 262 263 continue 263 264 264 265 if resvEx.bookedForName != None: 265 if resvCandidate.bookedForName == None: 266 if resvCandidate.bookedForName == None: 266 267 continue 267 268 if not containsExactly_OR_containsAny( resvEx.bookedForName, resvCandidate.bookedForName ): 268 269 continue 269 270 270 271 if resvEx.reason != None: 271 if resvCandidate.reason == None: 272 if resvCandidate.reason == None: 272 273 continue 273 274 if not containsExactly_OR_containsAny( resvEx.reason, resvCandidate.reason ): … … 315 316 if not resvCandidate.needsAVCSupport == resvEx.needsAVCSupport: 316 317 continue 317 318 318 319 # META-PROGRAMMING STYLE OF CHECKING ATTRIBUTES EQUALITY 319 320 # ABANDONED DUE TO PERFORMANCE PROBLEMS … … 322 323 # continue 323 324 324 325 325 326 # All conditions are met: add reservation to the results 326 327 counter += 1 327 328 if not countOnly: 328 329 ret_lst.append( resvCandidate ) 329 330 330 331 #print "Found " + str( counter ) + " reservations." 331 332 if not countOnly: return ret_lst … … 346 347 lst.sort() 347 348 return lst 348 349 349 350 def setExcludedDays( self, excludedDays ): 350 351 ReservationBase.setExcludedDays( self, excludedDays ) 351 352 self._excludedDays = excludedDays 352 353 def excludeDay( self, dayD ):353 354 def excludeDay( self, dayD, unindex = False ): 354 355 """ 355 356 Inserts dayD into list of excluded days. … … 357 358 """ 358 359 ReservationBase.excludeDay( self, dayD ) 359 lst = self._excludedDays 360 lst = self._excludedDays 360 361 if not dayD in lst: 361 362 lst.append( dayD ) 362 363 self._excludedDays = lst # Force update 363 364 365 if unindex: 366 dayReservationsIndexBTree = Reservation.getDayReservationsIndexRoot() 367 if dayReservationsIndexBTree.has_key(dayD): 368 try: 369 resvs = dayReservationsIndexBTree[dayD] 370 resvs.remove( self ) 371 dayReservationsIndexBTree[dayD] = resvs 372 except ValueError, e: 373 Logger.get('RoomBooking').debug("excludeDay: Unindexing a day (%s) which is not indexed"%dayD) 374 364 375 def includeDay( self, dayD ): 365 376 """ … … 368 379 """ 369 380 ReservationBase.includeDay( self, dayD ) 370 lst = self._excludedDays 381 lst = self._excludedDays 371 382 lst.remove( dayD ) 372 383 self._excludedDays = lst # Force update 373 384 385 # Re-indexing that day 386 dayReservationsIndexBTree = Reservation.getDayReservationsIndexRoot() 387 resvs = dayReservationsIndexBTree.get(dayD) 388 if resvs is None: 389 resvs = [] 390 dayReservationsIndexBTree.insert( dayD, resvs ) 391 resvs.append( self ) 392 dayReservationsIndexBTree[dayD] = resvs 393 374 394 def dayIsExcluded( self, dayD ): 375 395 ReservationBase.dayIsExcluded( self, dayD ) 376 396 return dayD in self.getExcludedDays() 377 397 378 # Statistical 398 # Statistical 379 399 380 400 @staticmethod … … 385 405 location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) 386 406 return Reservation.countReservations( location = location ) 387 407 388 408 @staticmethod 389 409 def getNumberOfLiveReservations( *args, **kwargs ): … … 405 425 406 426 # ==== Private =================================================== 407 427 408 428 @classmethod 409 429 def __attrSpecialEqual( cls, attrName, attrValExample, attrValCandidate ): … … 426 446 if word in attrValCandidate.lower(): 427 447 return True 428 448 429 449 return None 430 450 … … 439 459 440 460 class Test( object ): 441 461 442 462 dalManager = Factory.getDALManager() 443 463 … … 445 465 def getReservations(): 446 466 from MaKaC.rb_room import RoomBase 447 467 448 468 Test.dalManager.connect() 449 469 450 470 roomEx = Factory.newRoom() 451 471 roomEx.name = 'TH AMPHITHEATRE' 452 472 453 473 resvEx = Factory.newReservation() 454 474 resvEx.startDT = datetime( 2006, 12, 01, 10 ) … … 460 480 print "=============================" 461 481 print resv 462 482 463 483 Test.dalManager.disconnect() 464 484 … … 466 486 def getReservations2(): 467 487 from MaKaC.rb_room import RoomBase 468 488 469 489 Test.dalManager.connect() 470 490 471 491 resvEx = Factory.newReservation() 472 492 resvEx.startDT = datetime( 2006, 12, 01, 10 ) 473 493 resvEx.endDT = datetime( 2006, 12, 14, 15 ) 474 494 resvEx.repeatability = 0 # Daily 475 495 476 496 #ReservationBase.getReservations( \ 477 # roomExample = roomEx, 497 # roomExample = roomEx, 478 498 # resvExample = resvEx, 479 499 # available = True ) … … 502 522 dayReservationsIndexBTree = OOBTree() 503 523 raise str( dir( dayReservationsIndexBTree ) ) 504 524 505 525 Factory.getDALManager().disconnect() 506 526 DBMgr.getInstance().endRequest() … … 525 545 # if c % 100 == 0: 526 546 # print c 527 547 528 548 CrossLocationDB.commit() 529 549 CrossLocationDB.disconnect() … … 547 567 print "There are " + str( len( allResvs ) ) + " resvs and pre-resvs to index..." 548 568 c = 0 549 569 550 570 root[_ROOM_RESERVATIONS_INDEX] = OOBTree() 551 571 print "Room => Reservations Index branch created" 552 572 553 573 for resv in allResvs: 554 574 roomReservationsIndexBTree = root[_ROOM_RESERVATIONS_INDEX] … … 562 582 if c % 100 == 0: 563 583 print c 564 584 565 585 CrossLocationDB.commit() 566 586 CrossLocationDB.disconnect() … … 581 601 for r in rooms: 582 602 print r 583 603 584 604 CrossLocationDB.commit() 585 605 CrossLocationDB.disconnect() -
indico/MaKaC/webinterface/rh/roomBooking.py
r0c8aad rdab490 55 55 All room booking related hanlders are derived from this class. 56 56 This gives them: 57 - several general use methods 57 - several general use methods 58 58 - login-protection 59 59 - auto connecting/disconnecting from room booking db … … 69 69 session.setVar( "deletionFailed", None ) 70 70 session.setVar( "formMode", None ) 71 71 72 72 session.setVar( "candDataInSession", None ) 73 73 session.setVar( "candDataInParams", None ) … … 77 77 session.setVar( "errors", None ) 78 78 session.setVar( "thereAreConflicts", None ) 79 79 80 80 session.setVar( "roomID", None ) 81 81 session.setVar( "roomLocation", None ) 82 82 session.setVar( "resvID", None ) 83 83 84 84 def _checkParamsRepeatingPeriod( self, params ): 85 85 """ 86 86 Extracts startDT, endDT and repeatability 87 87 from the form, if present. 88 89 Assigns these values to self, or Nones if values 90 are not present. 88 89 Assigns these values to self, or Nones if values 90 are not present. 91 91 """ 92 92 sDay = params.get( "sDay" ) … … 121 121 if eTime and len( eTime.strip() ) > 0: 122 122 eTime = eTime.strip() 123 123 124 124 # process sTime and eTime 125 125 if sTime and eTime: … … 137 137 else: 138 138 repeatability = int( repeatability.strip() ) 139 139 140 140 self._startDT = None 141 141 self._endDT = None … … 158 158 self._startDT = datetime.today().replace(hour=0,minute=0,second=0) 159 159 self._endDT = self._startDT.replace(hour=23,minute=59,second=59) 160 # Room 161 160 # Room 161 162 162 def _saveRoomCandidateToSession( self, c ): 163 163 session = self._websession # Just an alias … … 171 171 session.setVar( "floor", c.floor ) 172 172 session.setVar( "roomNr", c.roomNr ) 173 173 174 174 session.setVar( "isActive", c.isActive ) 175 175 session.setVar( "isReservable", c.isReservable ) … … 220 220 def _loadRoomCandidateFromDefaults( self, candRoom ): 221 221 candRoom.isActive = True 222 222 223 223 candRoom.building = None 224 224 candRoom.floor = '' 225 225 candRoom.roomNr = '' 226 226 227 227 candRoom.capacity = 20 228 228 candRoom.site = '' … … 232 232 candRoom.photoId = None 233 233 candRoom.externalId = None 234 234 235 235 candRoom.telephone = '' # str 236 236 candRoom.surfaceArea = None … … 241 241 def _loadRoomCandidateFromSession( self, candRoom ): 242 242 session = self._websession # Just an alias 243 243 244 244 candRoom.name = session.getVar( "name" ) 245 245 candRoom.site = session.getVar( "site" ) … … 247 247 candRoom.floor = session.getVar( "floor" ) 248 248 candRoom.roomNr = session.getVar( "roomNr" ) 249 249 250 250 candRoom.isActive = bool( session.getVar( "isActive" ) ) 251 251 candRoom.isReservable = bool( session.getVar( "isReservable" ) ) 252 252 candRoom.resvsNeedConfirmation = bool( session.getVar( "resvsNeedConfirmation" ) ) 253 253 254 254 candRoom.responsibleId = session.getVar( "responsibleId" ) 255 255 candRoom.whereIsKey = session.getVar( "whereIsKey" ) … … 276 276 candRoom.floor = params.get( "floor" ) 277 277 candRoom.roomNr = params.get( "roomNr" ) 278 278 279 279 candRoom.isActive = bool( params.get( "isActive" ) ) # Safe 280 280 candRoom.isReservable = bool( params.get( "isReservable" ) ) # Safe 281 281 candRoom.resvsNeedConfirmation = bool( params.get( "resvsNeedConfirmation" ) ) # Safe 282 282 283 283 candRoom.responsibleId = params.get( "responsibleId" ) 284 284 if candRoom.responsibleId == "None": … … 286 286 candRoom.whereIsKey = params.get( "whereIsKey" ) 287 287 candRoom.telephone = params.get( "telephone" ) 288 288 289 289 candRoom.capacity = intd( params.get( "capacity" ) ) 290 290 candRoom.division = params.get( "division" ) … … 301 301 candRoom.setEquipment( eqList ) 302 302 candRoom.setAvailableVC(vcList) 303 303 304 304 for k, v in params.iteritems(): 305 305 if k.startswith( "cattr_" ): … … 324 324 session.setVar( "usesAVC", c.usesAVC ) 325 325 session.setVar( "needsAVCSupport", c.needsAVCSupport ) 326 326 327 327 if hasattr(self, '_skipConflicting'): 328 328 if self._skipConflicting: … … 331 331 skip = 'off' 332 332 session.setVar( "skipConflicting", skip ) 333 333 334 334 if hasattr(c, "useVC"): 335 335 session.setVar( "useVC", c.useVC) … … 352 352 self._thereAreConflicts = True 353 353 errors.append( "There are conflicts with other bookings" ) 354 354 355 355 return errors 356 356 … … 389 389 if useVC is not None: 390 390 candResv.useVC = useVC 391 391 392 392 return candResv 393 393 … … 495 495 class RHRoomBookingWelcome( RHRoomBookingBase ): 496 496 _uh = urlHandlers.UHRoomBookingWelcome 497 497 498 498 def _process( self ): 499 499 #if self._getUser().isResponsibleForRooms(): … … 519 519 def _setGeneralDefaultsInSession( self ): 520 520 now = datetime.now() 521 521 522 522 # if it's saturday or sunday, postpone for monday as a default 523 523 if now.weekday() in [5,6]: 524 524 now = now + timedelta( 7 - now.weekday() ) 525 525 526 526 websession = self._websession 527 527 websession.setVar( "defaultStartDT", datetime( now.year, now.month, now.day, 8, 30 ) ) 528 528 websession.setVar( "defaultEndDT", datetime( now.year, now.month, now.day, 17, 30 ) ) 529 529 530 530 def _checkParams( self, params ): 531 531 self._cleanDefaultsFromSession() … … 540 540 self._rooms.sort() 541 541 self._equipment = CrossLocationQueries.getPossibleEquipment() 542 542 543 543 def _process( self ): 544 544 self._businessLogic() … … 551 551 self._rooms = CrossLocationQueries.getRooms( allFast = True ) 552 552 self._rooms.sort() 553 553 554 554 def _process( self ): 555 555 self._businessLogic() … … 558 558 559 559 class RHRoomBookingSearch4Users( RHRoomBookingBase ): 560 560 561 561 def _checkParams( self, params ): 562 562 563 563 roomID = params.get( "roomID" ) 564 564 roomLocation = params.get( "roomLocation" ) … … 578 578 self._websession.setVar( "showErrors", False ) 579 579 self._websession.setVar( "candDataInSession", True ) 580 580 581 581 if params.has_key( 'largePhotoPath' ): del params['largePhotoPath'] 582 582 if params.has_key( 'smallPhotoPath' ): del params['smallPhotoPath'] … … 593 593 594 594 class RHRoomBookingRoomList( RHRoomBookingBase ): 595 595 596 596 def _checkParams( self, params ): 597 597 … … 607 607 for c in s: 608 608 if c != ',': self._freeSearch += c 609 609 610 610 self._capacity = None 611 611 if params.get("capacity") and len( params["capacity"].strip() ) > 0: 612 612 self._capacity = int( params["capacity"].strip() ) 613 613 614 614 self._availability = "Don't care" 615 615 if params.get("availability") and len( params["availability"].strip() ) > 0: … … 621 621 self._includePrebookings = False 622 622 if params.get( 'includePrebookings' ) == "on": self._includePrebookings = True 623 623 624 624 # The end of "avail/don't care" 625 625 626 626 # Equipment 627 627 self._equipment = [] … … 629 629 if k[0:4] == "equ_" and v == "on": 630 630 self._equipment.append( k[4:100] ) 631 631 632 632 # Special 633 633 self._isReservable = self._ownedBy = self._isAutoConfirmed = None 634 634 self._isActive = True 635 635 636 636 if params.get( 'isReservable' ) == "on": self._isReservable = True 637 637 if params.get( 'isAutoConfirmed' ) == "on": self._isAutoConfirmed = True … … 647 647 self._title = "My rooms" 648 648 self._ownedBy = self._getUser() 649 649 650 650 r = RoomBase() 651 651 r.capacity = self._capacity … … 671 671 if self._includePrebookings: 672 672 p.isConfirmed = None # because it defaults to True 673 673 674 674 # Set default values for later booking form 675 675 self._websession.setVar( "defaultStartDT", p.startDT ) … … 681 681 rooms = CrossLocationQueries.getRooms( \ 682 682 location = self._roomLocation, 683 freeText = self._freeSearch, 684 ownedBy = self._ownedBy, 685 roomExample = r, 686 resvExample = p, 683 freeText = self._freeSearch, 684 ownedBy = self._ownedBy, 685 roomExample = r, 686 resvExample = p, 687 687 available = available ) 688 688 # Special care for capacity (20% => greater than) 689 689 if len ( rooms ) == 0: 690 690 rooms = CrossLocationQueries.getRooms( \ 691 location = self._roomLocation, 692 freeText = self._freeSearch, 693 ownedBy = self._ownedBy, 694 roomExample = r, 695 resvExample = p, 691 location = self._roomLocation, 692 freeText = self._freeSearch, 693 ownedBy = self._ownedBy, 694 roomExample = r, 695 resvExample = p, 696 696 available = available, 697 697 minCapacity = True ) … … 700 700 701 701 self._rooms = rooms 702 702 703 703 def _process( self ): 704 704 self._businessLogic() … … 712 712 self._allRooms = False 713 713 roomGUIDs = params.get( "roomGUID" ) 714 if isinstance( roomGUIDs, str ): 714 if isinstance( roomGUIDs, str ): 715 715 if roomGUIDs == "allRooms": 716 716 self._allRooms = True … … 720 720 if isinstance( roomGUIDs, list ) and roomGUIDs != ['']: 721 721 self._roomGUIDs = roomGUIDs 722 722 723 723 resvEx = ReservationBase() 724 724 self._checkParamsRepeatingPeriod( params ) … … 732 732 resvEx.reason = reason.strip() 733 733 self._title = "Bookings" 734 735 onlyPrebookings = params.get( "onlyPrebookings" ) 734 735 onlyPrebookings = params.get( "onlyPrebookings" ) 736 736 self._onlyPrebookings = False 737 738 onlyBookings = params.get( "onlyBookings" ) 737 738 onlyBookings = params.get( "onlyBookings" ) 739 739 self._onlyBookings = False 740 740 741 741 if onlyPrebookings and len( onlyPrebookings.strip() ) > 0: 742 742 if onlyPrebookings == 'on': … … 746 746 elif onlyBookings and len( onlyBookings.strip() ) > 0: 747 747 if onlyBookings == 'on': 748 resvEx.isConfirmed = True 748 resvEx.isConfirmed = True 749 749 self._onlyBookings = True 750 750 else: 751 751 # find pre-bookings as well 752 752 resvEx.isConfirmed = None 753 753 754 754 self._onlyMy = False 755 755 onlyMy = params.get( "onlyMy" ) … … 768 768 else: 769 769 self._rooms = None 770 770 771 771 self._search = False 772 772 search = params.get( "search" ) … … 775 775 self._search = True 776 776 self._title = "Search " + self._title 777 777 778 778 self._order = params.get( "order", "" ) 779 779 780 780 isArchival = params.get( "isArchival" ) 781 781 if isArchival and len( isArchival.strip() ) > 0: … … 783 783 else: 784 784 self._isArchival = None 785 785 786 786 self._autoCriteria = False 787 787 if params.get( "autoCriteria" ) == "True" or not resvEx.startDT: 788 788 now = datetime.now() 789 789 after = now + timedelta( 30 ) # 1 month later 790 790 791 791 resvEx.startDT = datetime( now.year, now.month, now.day, 0, 0, 0 ) 792 792 resvEx.endDT = datetime( after.year, after.month, after.day, 23, 59, 00 ) … … 805 805 resvEx.isCancelled = False 806 806 807 807 808 808 needsAVCSupport = params.get( "needsAVCSupport" ) 809 809 if needsAVCSupport and len( needsAVCSupport.strip() ) > 0: … … 837 837 def _process( self ): 838 838 # The following can't be done in checkParams since it must be after checkProtection 839 if self._onlyMy: 839 if self._onlyMy: 840 840 self._resvEx.createdBy = str( self._getUser().id ) 841 841 if self._ofMyRooms: … … 854 854 else: 855 855 self._rooms = rooms 856 856 857 857 # Init 858 858 resvEx = self._resvEx … … 876 876 self._resvs = CrossLocationQueries.getReservations( resvExample = resvEx, rooms = self._rooms, archival = self._isArchival, heavy = self._isHeavy, days = days ) 877 877 878 878 879 879 p = roomBooking_wp.WPRoomBookingBookingList( self ) 880 880 return p.display() … … 883 883 # 3. Details of ... 884 884 885 class RHRoomBookingRoomDetails( RHRoomBookingBase ): 886 885 class RHRoomBookingRoomDetails( RHRoomBookingBase ): 886 887 887 def _checkParams( self, params ): 888 888 locator = locators.WebLocator() 889 889 locator.setRoom( params ) 890 890 self._room = self._target = locator.getObject() 891 891 892 892 session = self._websession 893 893 self._afterActionSucceeded = session.getVar( "actionSucceeded" ) 894 894 self._afterDeletionFailed = session.getVar( "deletionFailed" ) 895 895 self._formMode = session.getVar( "formMode" ) 896 896 897 897 self._searchingStartDT = self._searchingEndDT = None 898 898 if not params.get( 'calendarMonths' ): 899 899 self._searchingStartDT = session.getVar( "defaultStartDT" ) 900 900 self._searchingEndDT = session.getVar( "defaultEndDT" ) 901 901 902 902 self._clearSessionState() 903 903 … … 910 910 return p.display() 911 911 912 class RHRoomBookingRoomStats( RHRoomBookingBase ): 913 912 class RHRoomBookingRoomStats( RHRoomBookingBase ): 913 914 914 def _checkParams( self, params ): 915 915 locator = locators.WebLocator() 916 916 locator.setRoom( params ) 917 917 self._period = params.get("period","pastmonth") 918 self._room = self._target = locator.getObject() 918 self._room = self._target = locator.getObject() 919 919 920 920 def _businessLogic( self ): … … 923 923 self._kpiReservableRooms = RoomBase.getNumberOfReservableRooms() 924 924 self._kpiReservableCapacity, self._kpiReservableSurface = RoomBase.getTotalSurfaceAndCapacity() 925 # Bookings 925 # Bookings 926 926 st = ReservationBase.getRoomReservationStats(self._room) 927 927 self._booking_stats = st … … 933 933 return p.display() 934 934 935 class RHRoomBookingBookingDetails( RHRoomBookingBase ): 935 class RHRoomBookingBookingDetails( RHRoomBookingBase ): 936 936 937 937 def _checkParams( self, params ): 938 938 939 939 locator = locators.WebLocator() 940 940 locator.setRoomBooking( params ) … … 959 959 960 960 class RHRoomBookingBookingForm( RHRoomBookingBase ): 961 961 962 962 def _checkParams( self, params ): 963 963 session = self._websession # Just an alias 964 964 self._thereAreConflicts = session.getVar( 'thereAreConflicts' ) 965 965 self._skipConflicting = False 966 966 967 967 # DATA FROM? 968 968 self._dataFrom = CandidateDataFrom.DEFAULTS … … 1006 1006 else: 1007 1007 candResv = self._loadResvCandidateFromDefaults( params ) 1008 1008 1009 1009 if self._formMode == FormMode.MODIF: 1010 1010 import copy … … 1014 1014 if self._dataFrom == CandidateDataFrom.SESSION: 1015 1015 self._loadResvCandidateFromSession( candResv, params ) 1016 1016 1017 1017 self._errors = session.getVar( "errors" ) 1018 1018 self._candResv = candResv 1019 1019 1020 1020 self._clearSessionState() 1021 1021 … … 1050 1050 Performs open a new booking form with the data of an already existing booking. 1051 1051 """ 1052 1052 1053 1053 def _checkParams( self, params ): 1054 1054 session = self._websession # Just an alias … … 1058 1058 1059 1059 self._formMode = FormMode.NEW 1060 1060 1061 1061 # Reservation ID 1062 1062 resvID = int(params.get( "resvID" )) … … 1079 1079 When succeeded redirects to booking details, otherwise returns to booking form. 1080 1080 """ 1081 1081 1082 1082 def _checkParams( self, params ): 1083 1083 1084 1084 resvID = params.get( "resvID" ) 1085 1085 roomLocation = params.get( "roomLocation" ) … … 1090 1090 # prebookings that conflict with other prebookings are 1091 1091 # silently added 1092 1092 1093 1093 self._forceAddition = params.get("forceAddition","False") 1094 1094 if self._forceAddition == 'True': … … 1103 1103 _candResv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1104 1104 self._orig_candResv = _candResv 1105 1105 1106 1106 import copy 1107 1107 candResv = copy.copy(_candResv) 1108 1108 1109 1109 if self._forceAddition: 1110 1110 # booking data comes from session if confirmation was required … … 1112 1112 else: 1113 1113 self._loadResvCandidateFromParams( candResv, params ) 1114 1114 1115 1115 self._resvID = resvID 1116 1116 1117 1117 else: 1118 1118 self._formMode = FormMode.NEW … … 1122 1122 candResv.isRejected = False 1123 1123 candResv.isCancelled = False 1124 1124 1125 1125 if self._forceAddition: 1126 1126 # booking data comes from session if confirmation was required … … 1128 1128 else: 1129 1129 self._loadResvCandidateFromParams( candResv, params ) 1130 1130 1131 1131 self._resvID = None 1132 1133 1134 self._candResv = candResv 1135 1132 1133 1134 self._candResv = candResv 1135 1136 1136 self._params = params 1137 1137 self._clearSessionState() 1138 1139 1138 1139 1140 1140 def _checkProtection( self ): 1141 1141 RHRoomBookingBase._checkProtection(self) … … 1143 1143 if not self._candResv.room.isActive and not self._getUser().isAdmin(): 1144 1144 raise MaKaCError( "You are not authorized to book this room." ) 1145 1145 1146 1146 if self._formMode == FormMode.MODIF: 1147 1147 if not self._candResv.canModify( self.getAW() ): … … 1149 1149 1150 1150 def _businessLogic( self ): 1151 1151 1152 1152 candResv = self._candResv 1153 1153 self._emailsToBeSent = [] 1154 1154 self._confirmAdditionFirst = False; 1155 1155 1156 1156 # Set confirmation status 1157 1157 candResv.isConfirmed = True … … 1160 1160 candResv.isConfirmed = False 1161 1161 1162 1163 errors = self._getErrorsOfResvCandidate( candResv ) 1164 session = self._websession 1165 1162 1163 errors = self._getErrorsOfResvCandidate( candResv ) 1164 session = self._websession 1165 1166 1166 if not errors and self._answer != 'No': 1167 1168 # If we're dealing with an unapproved pre-booking 1169 if not candResv.isConfirmed and not self._forceAddition: 1170 1167 1168 # If we're dealing with an unapproved pre-booking 1169 if not candResv.isConfirmed and not self._forceAddition: 1170 1171 1171 candResv.isConfirmed = None; 1172 1172 # find pre-booking collisions 1173 1173 self._collisions = candResv.getCollisions(sansID = candResv.id) 1174 1174 1175 1175 candResv.isConfirmed = False 1176 1176 1177 1177 # are there any collisions? 1178 1178 if len( self._collisions ) > 0: … … 1180 1180 self._saveResvCandidateToSession( candResv ) 1181 1181 # ask for confirmation about the pre-booking 1182 self._confirmAdditionFirst = True 1183 1182 self._confirmAdditionFirst = True 1183 1184 1184 1185 1185 # approved pre-booking or booking 1186 1186 if not self._confirmAdditionFirst: 1187 1187 1188 1188 # Form is OK and (no conflicts or skip conflicts) 1189 1189 if self._formMode == FormMode.NEW: … … 1200 1200 self._loadResvCandidateFromSession( self._orig_candResv, self._params ) 1201 1201 else: 1202 self._loadResvCandidateFromParams( self._orig_candResv, self._params ) 1202 self._loadResvCandidateFromParams( self._orig_candResv, self._params ) 1203 1203 self._orig_candResv.update() 1204 1204 self._emailsToBeSent += self._orig_candResv.notifyAboutUpdate() … … 1206 1206 session.setVar( "description", 'Please review details below.' ) 1207 1207 session.setVar( "actionSucceeded", True ) 1208 1209 1210 else: 1208 1209 1210 else: 1211 1211 session.setVar( "candDataInSession", True ) 1212 1212 session.setVar( "errors", errors ) 1213 1213 1214 1214 if self._answer == 'No': 1215 session.setVar( "actionSucceeded", True ) 1215 session.setVar( "actionSucceeded", True ) 1216 1216 else: 1217 1217 session.setVar( "actionSucceeded", False ) 1218 1218 session.setVar( "showErrors", True ) 1219 1219 session.setVar( "thereAreConflicts", self._thereAreConflicts ) 1220 1220 1221 1221 self._saveResvCandidateToSession( candResv ) 1222 1222 1223 1223 # Form is not properly filled OR there are conflicts 1224 self._errors = errors 1225 1226 def _process( self ): 1224 self._errors = errors 1225 1226 def _process( self ): 1227 1227 1228 1228 self._businessLogic() 1229 1229 1230 1230 if self._errors or self._answer == 'No': 1231 url = urlHandlers.UHRoomBookingBookingForm.getURL( self._candResv.room, resvID=self._resvID ) 1231 url = urlHandlers.UHRoomBookingBookingForm.getURL( self._candResv.room, resvID=self._resvID ) 1232 1232 elif self._confirmAdditionFirst: 1233 1233 p = roomBooking_wp.WPRoomBookingConfirmBooking( self ) … … 1235 1235 else: 1236 1236 url = urlHandlers.UHRoomBookingBookingDetails.getURL( self._candResv ) 1237 1237 1238 1238 self._redirect( url ) 1239 1239 … … 1243 1243 Form for creating NEW and MODIFICATION of an existing room. 1244 1244 """ 1245 1245 1246 1246 def _checkParams( self, params ): 1247 1247 session = self._websession # Just an alias … … 1275 1275 if self._showErrors: 1276 1276 self._errors = self._websession.getVar( "errors" ) 1277 1277 1278 1278 # CREATE CANDIDATE OBJECT 1279 1279 candRoom = None … … 1291 1291 else: 1292 1292 self._loadRoomCandidateFromDefaults( candRoom ) 1293 1293 1294 1294 if self._formMode == FormMode.MODIF: 1295 1295 candRoom = CrossLocationQueries.getRooms( roomID = roomID, location = roomLocation ) 1296 1296 1297 1297 if self._dataFrom == CandidateDataFrom.PARAMS: 1298 1298 self._loadRoomCandidateFromParams( candRoom, params ) 1299 1299 if self._dataFrom == CandidateDataFrom.SESSION: 1300 1300 self._loadRoomCandidateFromSession( candRoom ) 1301 1301 1302 1302 self._errors = session.getVar( "errors" ) 1303 1303 … … 1410 1410 1411 1411 class RHRoomBookingDeleteBooking( RHRoomBookingAdminBase ): 1412 1412 1413 1413 def _checkParams( self , params ): 1414 1414 resvID = int( params.get( "resvID" ) ) … … 1416 1416 self._resv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1417 1417 self._target = self._resv 1418 1418 1419 1419 def _process( self ): 1420 1420 # Booking deletion is always possible - just delete … … 1426 1426 1427 1427 class RHRoomBookingCancelBooking( RHRoomBookingBase ): 1428 1428 1429 1429 def _checkParams( self , params ): 1430 1430 resvID = int( params.get( "resvID" ) ) … … 1432 1432 self._resv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1433 1433 self._target = self._resv 1434 1434 1435 1435 def _checkProtection( self ): 1436 1436 RHRoomBookingBase._checkProtection(self) … … 1441 1441 ( not self._getUser().isAdmin() ): 1442 1442 raise MaKaCError( "You are not authorized to take this action." ) 1443 1443 1444 1444 def _process( self ): 1445 1445 # Booking deletion is always possible - just delete 1446 1446 self._emailsToBeSent = [] 1447 1447 self._resv.cancel() # Just sets isCancel = True 1448 self._resv.update( )1448 self._resv.update(udpateReservationIndex=False) 1449 1449 self._emailsToBeSent += self._resv.notifyAboutCancellation() 1450 1450 1451 1451 self._websession.setVar( 'actionSucceeded', True ) 1452 1452 self._websession.setVar( 'title', "Booking has been cancelled." ) … … 1457 1457 1458 1458 class RHRoomBookingCancelBookingOccurrence( RHRoomBookingBase ): 1459 1459 1460 1460 def _checkParams( self , params ): 1461 1461 resvID = int( params.get( "resvID" ) ) 1462 1462 roomLocation = params.get( "roomLocation" ) 1463 1463 date = params.get( "date" ) 1464 1464 1465 1465 self._resv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1466 1466 self._date = parse_date( date ) … … 1474 1474 if self._resv.createdBy != user.getId() and (not user.isAdmin()): 1475 1475 raise MaKaCError( "You are not authorized to take this action." ) 1476 1476 1477 1477 def _process( self ): 1478 1478 self._emailsToBeSent = [] 1479 self._resv.excludeDay( self._date )1480 self._resv.update( )1479 self._resv.excludeDay( self._date, unindex=True ) 1480 self._resv.update(udpateReservationIndex=False) 1481 1481 self._emailsToBeSent += self._resv.notifyAboutCancellation( date = self._date ) 1482 1482 1483 1483 self._websession.setVar( 'actionSucceeded', True ) 1484 1484 self._websession.setVar( 'title', "Selected occurrence has been cancelled." ) … … 1489 1489 1490 1490 class RHRoomBookingRejectBooking( RHRoomBookingBase ): 1491 1491 1492 1492 def _checkParams( self , params ): 1493 1493 resvID = int( params.get( "resvID" ) ) 1494 1494 roomLocation = params.get( "roomLocation" ) 1495 1495 reason = params.get( "reason" ) 1496 1496 1497 1497 self._resv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1498 1498 self._resv.rejectionReason = reason … … 1507 1507 ( not self._getUser().isAdmin() ): 1508 1508 raise MaKaCError( "You are not authorized to take this action." ) 1509 1509 1510 1510 def _process( self ): 1511 1511 self._emailsToBeSent = [] 1512 1512 self._resv.reject() # Just sets isRejected = True 1513 self._resv.update( )1513 self._resv.update(udpateReservationIndex=False) 1514 1514 self._emailsToBeSent += self._resv.notifyAboutRejection() 1515 1515 1516 1516 self._websession.setVar( 'actionSucceeded', True ) 1517 1517 self._websession.setVar( 'title', "Booking has been rejected." ) … … 1522 1522 1523 1523 class RHRoomBookingRejectALlConflicting( RHRoomBookingBase ): 1524 1524 1525 1525 # def _checkParams( self , params ): 1526 1526 # pass … … 1534 1534 ( not self._getUser().isAdmin() ): 1535 1535 raise MaKaCError( "You are not authorized to take this action." ) 1536 1536 1537 1537 def _process( self ): 1538 1538 userRooms = self._getUser().getRooms() … … 1543 1543 resvEx.isRejected = False 1544 1544 resvEx.isCancelled = False 1545 1545 1546 1546 resvs = CrossLocationQueries.getReservations( resvExample = resvEx, rooms = userRooms ) 1547 1547 … … 1565 1565 1566 1566 class RHRoomBookingAcceptBooking( RHRoomBookingBase ): 1567 1567 1568 1568 def _checkParams( self , params ): 1569 1569 resvID = int( params.get( "resvID" ) ) … … 1579 1579 ( not self._getUser().isAdmin() ): 1580 1580 raise MaKaCError( "You are not authorized to take this action." ) 1581 1581 1582 1582 def _process( self ): 1583 1583 self._emailsToBeSent = [] … … 1588 1588 self._resv.update(False) 1589 1589 self._emailsToBeSent += self._resv.notifyAboutConfirmation() 1590 1590 1591 1591 session.setVar( 'actionSucceeded', True ) 1592 1592 session.setVar( 'title', "Booking has been accepted." ) … … 1604 1604 session.setVar( 'title', "PRE-Booking conflicts with other (confirmed) bookings." ) 1605 1605 session.setVar( 'description', "" ) 1606 1606 1607 1607 self._formMode = FormMode.MODIF 1608 1608 self._saveResvCandidateToSession( self._resv ) … … 1619 1619 session.setVar( 'title', None ) 1620 1620 session.setVar( 'description', None ) 1621 1621 1622 1622 def _process( self ): 1623 1623 return roomBooking_wp.WPRoomBookingStatement( self ).display() 1624 1624 1625 1625 class RHRoomBookingAdmin( RHRoomBookingAdminBase ): 1626 1626 1627 1627 def _process( self ): 1628 1628 return admins.WPRoomBookingAdmin( self ).display() 1629 1629 1630 1630 class RHRoomBookingAdminLocation( RHRoomBookingAdminBase ): 1631 1631 1632 1632 def _checkParams( self, params ): 1633 1633 self._withKPI = False … … 1643 1643 else: 1644 1644 self._actionSucceeded = False 1645 1646 def _process( self ): 1647 1645 1646 def _process( self ): 1647 1648 1648 if self._withKPI: 1649 1649 self._kpiAverageOccupation = RoomBase.getAverageOccupation(location=self._location.friendlyName) … … 1652 1652 self._kpiReservableRooms = RoomBase.getNumberOfReservableRooms(location=self._location.friendlyName) 1653 1653 self._kpiReservableCapacity, self._kpiReservableSurface = RoomBase.getTotalSurfaceAndCapacity(location=self._location.friendlyName) 1654 1654 1655 1655 # Bookings 1656 1656 1657 1657 st = ReservationBase.getReservationStats(location=self._location.friendlyName) 1658 1658 self._booking_stats = st 1659 1659 self._totalBookings = st['liveValid'] + st['liveCancelled'] + st['liveRejected'] + st['archivalValid'] + st['archivalCancelled'] + st['archivalRejected'] 1660 1660 1661 1661 return admins.WPRoomBookingAdminLocation( self, self._location, actionSucceeded = self._actionSucceeded ).display() 1662 1662 … … 1666 1666 def _checkParams( self , params ): 1667 1667 self._defaultLocation = params["defaultLocation"] 1668 1668 1669 1669 def _process( self ): 1670 1670 Location.setDefaultLocation( self._defaultLocation ) … … 1684 1684 if self._pluginClass == None: 1685 1685 raise MaKaCError( "%s: Cannot find requested plugin" % name ) 1686 1686 1687 1687 def _process( self ): 1688 1688 if self._locationName: … … 1697 1697 def _checkParams( self , params ): 1698 1698 self._locationName = params["removeLocationName"] 1699 1700 def _process( self ): 1701 1699 1700 def _process( self ): 1701 1702 1702 if self._locationName: 1703 1703 Location.removeLocation( self._locationName ) … … 1713 1713 if str(self._location) == "None": 1714 1714 raise MaKaCError( "%s: Unknown Location" % name ) 1715 1715 1716 1716 def _process( self ): 1717 1717 if self._eq: … … 1728 1728 if str(self._location) == "None": 1729 1729 raise MaKaCError( "%s: Unknown Location" % name ) 1730 1730 1731 1731 def _process( self ): 1732 1732 self._location.factory.getEquipmentManager().removeEquipment( self._eq, location=self._location.friendlyName ) … … 1741 1741 if str(self._location) == "None": 1742 1742 raise MaKaCError( "%s: Unknown Location" % name ) 1743 1743 1744 1744 self._newAttr = None 1745 1745 if params.get( "newCustomAttributeName" ): 1746 1746 attrName = params["newCustomAttributeName"].strip() 1747 if attrName: 1747 if attrName: 1748 1748 attrIsReq = False 1749 1749 if params.get( "newCustomAttributeIsRequired" ) == "on": … … 1757 1757 'required': attrIsReq, 1758 1758 'hidden': attrIsHidden } 1759 1759 1760 1760 # Set "required" for _all_ custom attributes 1761 1761 manager = self._location.factory.getCustomAttributesManager() … … 1774 1774 manager.setRequired( ca['name'], required, location=self._location.friendlyName ) 1775 1775 manager.setHidden( ca['name'], hidden, location=self._location.friendlyName ) 1776 1776 1777 1777 def _process( self ): 1778 1778 if self._newAttr: … … 1789 1789 if str(self._location) == "None": 1790 1790 raise MaKaCError( "%s: Unknown Location" % name ) 1791 1791 1792 1792 def _process( self ): 1793 1793 self._location.factory.getCustomAttributesManager().removeAttribute( self._attr, location=self._location.friendlyName ) … … 1816 1816 1817 1817 class RHRoomBookingGetDateWarning( RHRoomBookingBase ): 1818 1818 1819 1819 def _checkParams( self, params ): 1820 1820 try: … … 1822 1822 except: 1823 1823 pass 1824 1824 1825 1825 def addRandom( self, s ): 1826 1826 return s 1827 1827 #import random 1828 1828 #return str( int( random.random() * 1000 ) ) + " | " + s 1829 1829 1830 1830 def _process( self ): 1831 1831 if not self._startDT or not self._endDT: 1832 1832 return self.addRandom( " " ) 1833 1833 1834 1834 if HolidaysHolder.isWorkingDay( self._startDT ) and \ 1835 1835 HolidaysHolder.isWorkingDay( self._endDT ): 1836 1836 return self.addRandom( " " ) 1837 1837 1838 1838 if isWeekend( self._startDT ) or isWeekend( self._endDT ): 1839 1839 return self.addRandom( "Warning: weekend chosen" ) 1840 1840 1841 1841 return self.addRandom( "Warning: holidays chosen" ) 1842 1842 1843 1843 1844 1844 class RHRoomBookingGetRoomSelectList( RHRoomBookingBase ): 1845 1845 1846 1846 def _checkParams( self, params ): 1847 1847 self.location = params.get( 'locationName' ) 1848 1848 self.forSubEvents = params.get( 'forSubEvents' ) == 'True' 1849 1850 def _process( self ): 1851 1849 1850 def _process( self ): 1851 1852 1852 self._roomList = [] 1853 1853 if self.location: 1854 1854 self._roomList = CrossLocationQueries.getRooms( location = self.location ) 1855 1855 self._locationRoom = "" 1856 1856 1857 1857 from MaKaC.webinterface import wcomponents 1858 1858 if self.forSubEvents: … … 1860 1860 else: 1861 1861 p = wcomponents.WRoomBookingRoomSelectList( self ) 1862 1862 1863 1863 return p.getHTML( self.getRequestParams() ) 1864 1864 1865 1865 #return "<div style='background-color: red;'> </div>" 1866 1866 1867 1867 class RHRoomBookingRejectBookingOccurrence( RHRoomBookingBase ): 1868 1868 1869 1869 def _checkParams( self , params ): 1870 1870 resvID = int( params.get( "resvID" ) ) … … 1872 1872 reason = params.get( "reason" ) 1873 1873 date = params.get( "date" ) 1874 1874 1875 1875 self._resv = CrossLocationQueries.getReservations( resvID = resvID, location = roomLocation ) 1876 1876 self._rejectionReason = reason … … 1886 1886 ( not self._getUser().isAdmin() ): 1887 1887 raise MaKaCError( "You are not authorized to take this action." ) 1888 1888 1889 1889 def _process( self ): 1890 1890 self._emailsToBeSent = [] 1891 self._resv.excludeDay( self._date )1892 self._resv.update( )1891 self._resv.excludeDay( self._date, unindex=True ) 1892 self._resv.update(udpateReservationIndex=False) 1893 1893 self._emailsToBeSent += self._resv.notifyAboutRejection( date = self._date, reason = self._rejectionReason ) 1894 1894 1895 1895 self._websession.setVar( 'actionSucceeded', True ) 1896 1896 self._websession.setVar( 'title', "Selected occurrence of this booking has been rejected." )
Note: See TracChangeset
for help on using the changeset viewer.
