Changeset cd05ca in indico for indico/MaKaC/plugins/RoomBooking/default/reservation.py
- Timestamp:
- 06/16/10 17:09:17 (3 years ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, new-webex, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- 3908a4
- Parents:
- 9c186f
- git-author:
- Ian Rolewicz <ian.rolewicz@…> (04/27/10 12:25:57)
- git-committer:
- Jose Benito <jose.benito.gonzalez@…> (06/16/10 17:09:17)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/plugins/RoomBooking/default/reservation.py
r6463ac rcd05ca 26 26 from MaKaC.rb_factory import Factory 27 27 from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum, WeekDayEnum 28 from MaKaC.rb_tools import qbeMatch, doesPeriodsOverlap, iterdays, overlap, weekNumber, containsExactly_OR_containsAny 28 from MaKaC.rb_tools import qbeMatch, doesPeriodsOverlap, iterdays, overlap, weekNumber, containsExactly_OR_containsAny, fromUTC 29 29 from MaKaC.rb_location import CrossLocationQueries 30 30 from MaKaC.plugins.RoomBooking.default.factory import Factory … … 52 52 self._excludedDays = [] 53 53 self.useVC = [] 54 self.resvHistory = ResvHistoryHandler() 54 55 55 56 def getUseVC( self ): … … 59 60 self.useVC = [] 60 61 return self.useVC 62 63 def getResvHistory( self ): 64 try: 65 return self.resvHistory 66 except: 67 self.resvHistory = ResvHistoryHandler() 68 return self.resvHistory 61 69 62 70 @staticmethod … … 121 129 # room, once assigned to reservation, CAN NOT be changed later (index!) 122 130 123 def indexDayReservations( self):131 def indexDayReservations( self ): 124 132 self._addToDayReservationsIndex() 125 133 self._p_changed = True 126 134 127 def unindexDayReservations( self):135 def unindexDayReservations( self ): 128 136 self._removeFromDayReservationsIndex() 129 137 self._p_changed = True … … 396 404 return dayD in self.getExcludedDays() 397 405 406 def createSnapshot( self ): 407 """ 408 Creates dynamically a dictionnary of the attributes of the object. 409 This dictionnary will be mainly used to compare the reservation 410 before and after a modification 411 """ 412 result = {} 413 414 for attr, val in self.__dict__.iteritems(): 415 result[attr] = val 416 417 return result 418 398 419 # Statistical 399 420 … … 423 444 location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) 424 445 return Reservation.countReservations( archival = True, location = location ) 446 425 447 426 448 # ==== Private =================================================== … … 454 476 return self.room.locationName 455 477 478 class ResvHistoryEntry( Persistent ): 479 480 def __init__( self, user, info, emails ): 481 self._timestamp = datetime.utcnow().strftime("%d %b %Y %H:%M") 482 self._responsibleUser = user.getFullName() 483 self._info = info #List of str 484 # Generate list of email addresses to which a notification email was sent, 485 # and adds them to the info if there are any 486 emailAddrs = "" 487 for email in emails : 488 for toAddr in email["toList"] : 489 emailAddrs += (", " + toAddr) 490 if emailAddrs != "": 491 self._info.append("Emails triggered to:<span style='font-family: \"Courier New\"'>" + emailAddrs[1:] +"</span>") 492 493 def getTimestamp( self ): 494 return self._timestamp 495 496 def getResponsibleUser( self ): 497 return self._responsibleUser 498 499 def getInfo( self ): 500 return self._info 501 502 503 class ResvHistoryHandler( Persistent ): 504 """ 505 Utility class used to record actions performed on a reservation 506 """ 507 508 # Dictionnary used to map Reservation attribute names to human-friendly 509 # names 510 _attrNamesMap = {"_utcStartDT" : "start date", 511 "_utcEndDT" : "end date", 512 "repeatability": "type", 513 "bookedForName": "'Booked for' name", 514 "contactEmail" : "'Booked for' email", 515 "contactPhone" : "'Booked for' phone", 516 "reason" : "reason" 517 } 518 519 # Dictionnary used to map Reservation attribute names to methods that 520 # will format them into human-friendly strings 521 _attrFormatMap = {"_utcStartDT" : fromUTC, 522 "_utcEndDT" : fromUTC, 523 "repeatability" : lambda x: RepeatabilityEnum.rep2description[x] 524 } 525 526 def __init__( self ): 527 self._entries = [] 528 529 def addHistoryEntry( self, entry ): 530 if entry == None : 531 return False 532 try: 533 self._entries.insert(0, entry ) 534 except: 535 self._entries = [] 536 self._entries.insert(0, entry ) 537 self.notifyModification() 538 return True 539 540 # def clearHistory(self): 541 # self._entries = [] 542 # self.notifyModification() 543 544 def getEntries( self ): 545 try : 546 return self._entries 547 except : 548 self._entries = [] 549 return self._entries 550 551 def hasHistory( self ): 552 return not(self._entries == None or self._entries == []) 553 554 def notifyModification( self ): 555 self._p_changed=1 556 557 558 def _bookingSnapshotsDiff( self, prevSnapshot, newSnapshot ): 559 """ 560 This method compares two "snapshots" of bookings and returns a 561 dictionnary containing the attributes that differs, along with their 562 values 563 """ 564 result = {} 565 for attr in newSnapshot.keys() : 566 if attr in prevSnapshot : 567 if prevSnapshot[attr] != newSnapshot[attr] : 568 result[attr] = {"prev": prevSnapshot[attr], 569 "new": newSnapshot[attr]} 570 else : 571 # The attribute was created in the meanwhile 572 result[attr] = {"prev": None, "new": newSnapshot[attr]} 573 574 return result 575 576 def getResvModifInfo(self, info, before, after): 577 """ 578 This utility method generates the info of the history entry when 579 a reservation is modified. 580 - info : List of str - The list to fill in with the info 581 - before : dict - Snapshot of the reservation before modification 582 - after : dict - Snapshot of the reservation after modification 583 """ 584 585 info.append("Booking modified") 586 # Getting the attributes that changed: 587 attrDiff = self._bookingSnapshotsDiff( before, after ) 588 # Create the info strings out of the diffs 589 for attr in attrDiff.keys() : 590 try: 591 attrName = self._attrNamesMap[attr] 592 except KeyError: 593 attrName = attr 594 try: 595 prevValue = self._attrFormatMap[attr](attrDiff[attr]["prev"]) 596 except KeyError, AttributeError: 597 prevValue = str(attrDiff[attr]["prev"]) 598 try: 599 newValue = self._attrFormatMap[attr](attrDiff[attr]["new"]) 600 except KeyError, AttributeError: 601 newValue = str(attrDiff[attr]["new"]) 602 603 if prevValue == "" : 604 info.append("The %s was set to '%s'" %(attrName, newValue)) 605 elif newValue == "" : 606 info.append("The %s was cleared" %attrName) 607 else : 608 info.append("The %s was changed from '%s' to '%s'" %(attrName, prevValue, newValue)) 609 456 610 # ============================================================================ 457 611 # ================================== TEST ====================================
Note: See TracChangeset
for help on using the changeset viewer.
