def clean_fuel_burn(self): value = self.cleaned_data['fuel_burn'] if value == '': return '' if '+' in value or '-' in value or '/' in value or '*' in value: value = FuelBurn.pre_eval(value) ## this will raise the proper validation exceptions FuelBurn.split_and_validate(value) return value
def calc_fuel(self): """ Calculated the `gallons` and `mpg` database fields. It tries to use the fuel_burn value opn the flight but falls back to using the value associated with the plane if no value is present. """ distance = self.route.total_line_all if self.fuel_burn or self.plane.fuel_burn: if self.fuel_burn: fb = FuelBurn(input=self.fuel_burn, time=self.total, mileage=distance) else: fb = FuelBurn(input=self.plane.fuel_burn, time=self.total, mileage=distance) self.gallons = fb.as_unit('gallons', for_db=True) self.gph = fb.as_unit('gph', for_db=True) self.mpg = fb.as_unit('mpg', for_db=True)
def get_fuel_burn(self): """ Return the fuel burn for this flight as a FuelBurn object. If the flight has no fuel burn info, then create the object from the plane's default """ mileage = self.route.total_line_all fb = self.fuel_burn if not fb: fb = getattr(self.plane, "fuel_burn", None) return FuelBurn(time=self.total, input=fb, mileage=mileage)