Ignore:
Timestamp:
06/16/10 17:09:17 (3 years ago)
Author:
Jose Benito <jose.benito.gonzalez@…>
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)
Message:

[IMP] Booking Actions History

  • fixes #268
  • On the details page of a booking, the history of previous actions performed on that booking is displayed for the owner of the room, the people allowed to modify the booking and the administrators.
  • Updated the User Guide
  • reviewed by jbenito: doc regenerated
File:
1 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/plugins/RoomBooking/default/reservation.py

    r6463ac rcd05ca  
    2626from MaKaC.rb_factory import Factory 
    2727from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum, WeekDayEnum 
    28 from MaKaC.rb_tools import qbeMatch, doesPeriodsOverlap, iterdays, overlap, weekNumber, containsExactly_OR_containsAny 
     28from MaKaC.rb_tools import qbeMatch, doesPeriodsOverlap, iterdays, overlap, weekNumber, containsExactly_OR_containsAny, fromUTC 
    2929from MaKaC.rb_location import CrossLocationQueries 
    3030from MaKaC.plugins.RoomBooking.default.factory import Factory 
     
    5252        self._excludedDays = [] 
    5353        self.useVC = [] 
     54        self.resvHistory = ResvHistoryHandler() 
    5455 
    5556    def getUseVC( self ): 
     
    5960            self.useVC = [] 
    6061        return self.useVC 
     62 
     63    def getResvHistory( self ): 
     64        try: 
     65            return self.resvHistory 
     66        except: 
     67            self.resvHistory = ResvHistoryHandler() 
     68        return self.resvHistory 
    6169 
    6270    @staticmethod 
     
    121129        # room, once assigned to reservation, CAN NOT be changed later (index!) 
    122130 
    123     def indexDayReservations(self): 
     131    def indexDayReservations( self ): 
    124132        self._addToDayReservationsIndex() 
    125133        self._p_changed = True 
    126134 
    127     def unindexDayReservations(self): 
     135    def unindexDayReservations( self ): 
    128136        self._removeFromDayReservationsIndex() 
    129137        self._p_changed = True 
     
    396404        return dayD in self.getExcludedDays() 
    397405 
     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 
    398419    # Statistical 
    399420 
     
    423444        location = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) 
    424445        return Reservation.countReservations( archival = True, location = location ) 
     446 
    425447 
    426448    # ==== Private =================================================== 
     
    454476        return self.room.locationName 
    455477 
     478class 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 
     503class 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 
    456610# ============================================================================ 
    457611# ================================== TEST ==================================== 
Note: See TracChangeset for help on using the changeset viewer.