Exemplo n.º 1
0
def add_sector(booking_id, date, from_loc, to_loc, service):
  res = None
  b = Booking.get_by_id(booking_id)

  if b:
    res = Sector(date=date, from_loc=from_loc, to_loc=to_loc, service=service, booking=b)
    res.put()
    
    if date > b.last_date:
      b.last_date = date
      b.put()

    _use(b.key())

  return res.to_dict()
Exemplo n.º 2
0
def update_sector(sector_id, **kwds):
  s = Sector.get_by_id(sector_id)

  if s and len(kwds) > 0:
    if 'date' in kwds:
      s.date = kwds['date']
    if 'from_loc' in kwds:
      s.from_loc = kwds['from_loc']
    if 'to_loc' in kwds:
      s.to_loc = kwds['to_loc']
    if 'service' in kwds:
      s.service = kwds['service']

    s.put()
    _use(s.booking.key())

  return s.to_dict()
Exemplo n.º 3
0
def add_passenger_to_sector(sector_id, service_no, last_name=None, init=None, fare=None):
  s = Sector.get_by_id(sector_id)
  p = Passenger.get_by_key_name(service_no)

  if not p and last_name and init:
    p = Passenger(service_no=service_no, key_name=service_no, last_name=last_name, init=init)
    p.put()

  if p and s:
    psb = PassengerSectorBooking(passenger=p, sector=s, booking=s.booking, fare_type=fare, key_name=str(p.key())+str(s.key()))
    psb.put()

    _use(s.booking.key())
    _use(p.key())

    res = p.to_dict()
    res['fare'] = fare
    return res

  return None
Exemplo n.º 4
0
def delete_sector_by_id(sector_id):
  s = Sector.get_by_id(sector_id)
  if s:
    db.delete(s.passengers_rel)

  s.delete()
Exemplo n.º 5
0
def get_sector_by_id(sector_id):
  s = Sector.get_by_id(sector_id)
  if s:
    return s.to_dict()
  return None
Exemplo n.º 6
0
def get_sectors_by_booking_id(booking_id):
  b = db.Key.from_path('Booking', booking_id)
  ss = Sector.all()
  ss.filter('booking = ', b)

  return [s.to_dict() for s in ss]