コード例 #1
0
  def update(self, id):
    busRoute = BusRoute.get_by_id(int(id), parent=self.get_current_account())

    if not busRoute:
      self.session.add_flash(messages.BUS_ROUTE_NOT_FOUND,
                             level='error')
      return self.redirect_to('bus_route.list')

    form = BusRouteForm(self.request.POST, obj=busRoute)

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

      self.session.add_flash(messages.BUS_ROUTE_UPDATE_SUCCESS)
      return self.redirect_to('bus_route.list')

    return self.render_to_response('bus_route/form.haml', {'form': form})
コード例 #2
0
  def create(self): 
    form = BusRouteForm(self.request.POST)

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

      if BusRoute.get_by_route_number(form.data['route_number']):
        self.session.add_flash(messages.BUS_ROUTE_NAME_EXISTS,
                               level='error')
        return self.render_to_response('bus_route/form.haml', {'form': form})

      busRoute = BusRoute(route_number=form.data['route_number'],
                          stops=form.data['stops'],
                          parent=self.get_current_account())
      busRoute.put()

      self.session.add_flash(messages.BUS_ROUTE_CREATE_SUCCESS, level='info')
      return self.redirect_to('bus_route.list')

    self.session.add_flash(messages.BUS_ROUTE_CREATE_ERROR, level='error')
    return self.redirect_to('bus_route.list')
コード例 #3
0
 def list(self):
   # We pass form so we can generate it with the modal using macros.
   return self.render_to_response('bus_route/list.haml', {'form': BusRouteForm()})