Changeset 809:4da4f80a2ab4 for src


Ignore:
Timestamp:
09/08/16 07:32:45 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The past, pending flights are retrieved (re #307)

Location:
src/mlx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/rpc.py

    r790 r809  
    7373            raise Exception("Invalid aircraft type code: '" + typeCode + "'")
    7474
     75    @staticmethod
     76    def _decodeStatus(status):
     77        """Decode the status from the status string."""
     78        if status=="booked":
     79            return BookedFlight.STATUS_BOOKED
     80        elif status=="reported":
     81            return BookedFlight.STATUS_REPORTED
     82        elif status=="accepted":
     83            return BookedFlight.STATUS_ACCEPTED
     84        elif status=="rejected":
     85            return BookedFlight.STATUS_REJECTED
     86        else:
     87            raise Exception("Invalid flight status code: '" + status + "'")
     88
    7589    # FIXME: copied from web.BookedFlight
    7690    @staticmethod
     
    7993        return datetime.datetime.strptime(date + " " + time,
    8094                                          "%Y-%m-%d %H:%M:%S")
     95
     96    # FIXME: copied from web.BookedFlight
     97    STATUS_BOOKED = 1
     98
     99    # FIXME: copied from web.BookedFlight
     100    STATUS_REPORTED = 2
     101
     102    # FIXME: copied from web.BookedFlight
     103    STATUS_ACCEPTED = 3
     104
     105    # FIXME: copied from web.BookedFlight
     106    STATUS_REJECTED = 4
    81107
    82108    # The instructions for the construction
     
    87113        "cargoWeight" : int,
    88114        "mailWeight" : int,
    89         "aircraftType" : lambda value: BookedFlight._decodeAircraftType(value)
     115        "aircraftType" : lambda value: BookedFlight._decodeAircraftType(value),
     116        "status" : lambda value: BookedFlight._decodeStatus(value)
    90117        }
    91118
     
    246273    def getFlights(self):
    247274        """Get the flights available for performing."""
    248         flights = []
     275        bookedFlights = []
     276        reportedFlights = []
     277        rejectedFlights = []
    249278
    250279        value = self._performCall(lambda sessionID:
    251280                                  self._server.getFlights(sessionID))
    252281        for flightData in value:
    253             flights.append(BookedFlight(flightData))
    254 
    255         flights.sort(cmp = lambda flight1, flight2:
    256                      cmp(flight1.departureTime, flight2.departureTime))
    257 
    258         return flights
     282            flight = BookedFlight(flightData)
     283            if flight.status == BookedFlight.STATUS_BOOKED:
     284                bookedFlights.append(flight)
     285            elif flight.status == BookedFlight.STATUS_REPORTED:
     286                reportedFlights.append(flight)
     287            elif flight.status == BookedFlight.STATUS_REJECTED:
     288                rejectedFlights.append(flight)
     289
     290        for flights in [bookedFlights, reportedFlights, rejectedFlights]:
     291            flights.sort(cmp = lambda flight1, flight2:
     292                         cmp(flight1.departureTime, flight2.departureTime))
     293
     294        return (bookedFlights, reportedFlights, rejectedFlights)
    259295
    260296    def getEntryExamStatus(self):
  • src/mlx/web.py

    r806 r809  
    9696                         const.AIRCRAFT_B738, const.AIRCRAFT_DH8D ]
    9797
     98    STATUS_BOOKED = 1
     99
     100    STATUS_REPORTED = 2
     101
     102    STATUS_ACCEPTED = 3
     103
     104    STATUS_REJECTED = 4
     105
    98106    @staticmethod
    99107    def getDateTime(date, time):
     
    137145        """Construct a booked flight with the given ID."""
    138146        self.id = id
     147
     148    @property
     149    def status(self):
     150        """Get the status of the flight.
     151
     152        For web-based flights this is always STATUS_BOOKED."""
     153        return BookedFlight.STATUS_BOOKED
    139154
    140155    def readFromWeb(self, f):
     
    769784            result.rank = loginResult[1]
    770785            result.password = password
    771             result.flights = client.getFlights()
     786            flights = client.getFlights()
     787            result.flights = flights[0]
     788            result.reportedFlights = flights[1]
     789            result.rejectedFlights = flights[2]
    772790            if result.rank=="STU":
    773791                reply = client.getEntryExamStatus()
Note: See TracChangeset for help on using the changeset viewer.