Example #1
0
  def assign_driver(self, id):
    bus = Bus.get_by_id(int(id), parent=self.get_current_account())

    if not bus:
      return self.redirect_to('bus.list', messages.BUS_NOT_FOUND)

    form = AssignDriverForm(self.request.POST, obj=bus)

    if self.request.method == 'POST' and form.validate():
      busDriver = BusDriver.get_by_driver_id(form.data['driver_id'])
      bus.bus_driver = busDriver.key()
      bus.put()

      self.session.add_flash(messages.BUS_DRIVER_ASSIGN_SUCCESS)
      return self.redirect_to('bus.list')
    # Unable to flash ASS_DRIVER_ERROR because request returns 302.
    # Form may not be validating correctly in the above, hence the
    # the form call below is the one that actually renders the
    # correct form.
    return self.render_to_response('bus/form.haml', {'form': form})
Example #2
0
    def assign_driver(self, id):
        bus = Bus.get_by_id(int(id), parent=self.get_current_account())

        if not bus:
            return self.redirect_to('bus.list', messages.BUS_NOT_FOUND)

        form = AssignDriverForm(self.request.POST, obj=bus)

        if self.request.method == 'POST' and form.validate():
            busDriver = BusDriver.get_by_driver_id(form.data['driver_id'])
            bus.bus_driver = busDriver.key()
            bus.put()

            self.session.add_flash(messages.BUS_DRIVER_ASSIGN_SUCCESS)
            return self.redirect_to('bus.list')
        # Unable to flash ASS_DRIVER_ERROR because request returns 302.
        # Form may not be validating correctly in the above, hence the
        # the form call below is the one that actually renders the
        # correct form.
        return self.render_to_response('bus/form.haml', {'form': form})
Example #3
0
  def create(self): 
    form = BusDriverForm(self.request.POST)

    if self.request.method == 'POST' and form.validate():

      if BusDriver.get_by_driver_id(form.data['driver_id']):
        self.session.add_flash(messages.BUS_DRIVER_EXISTS,
                               level='error')
        return self.render_to_response('bus_driver/form.haml', {'form': form})

      bus_driver = BusDriver(driver_id=form.data['driver_id'],
                             parent=self.get_current_account())

      bus_driver.name = ' '.join((form.data['first_name'],
                                  form.data['last_name']))
      bus_driver.put()

      self.session.add_flash(messages.BUS_DRIVER_CREATE_SUCCESS, level='info')
      return self.redirect_to('bus_driver.list')

    self.session.add_flash(messages.BUS_DRIVER_CREATE_ERROR, level='error')
    return self.redirect_to('bus_driver.list')