def add_climbers():
    error = False
    try:
        name = request.json['name']
        state = request.json['state']
        visited_spots = request.json['visited_spots']
        climber_id = request.get_json().get('id', None)

        if (climber_id):
            climber = Climber(id=climber_id, name=name, state=state)
        else:
            climber = Climber(name=name, state=state)

        db.session.add(climber)
        db.session.flush()
        for spot_id in visited_spots:
            visitedspots = VisitedSpot(climbing_spot_id=spot_id,
                                       climber_id=climber.id)
            db.session.add(visitedspots)
        db.session.commit()

        climbers = get_climbers()
    except:
        db.session.rollback()
        error = True
    finally:
        db.session.close()
    if error:
        #        flash('An error occurred. Climbing spot ' + request.json['name'] + ' could not be added.')
        abort(400)
    else:
        #        flash('Climbing spot ' + request.json['name'] + ' was successfully added!')
        if request.path == '/api/climbers':
            return jsonify({'success': True, 'climbers': climbers}), 200
        return render_template('climbers.html', climbers=climbers)
Exemple #2
0
 def get(self):
   user = users.get_current_user()
   context = {
       'user': user,
       'login': users.create_login_url('/login'),
       'logout': users.create_logout_url(self.request.uri)}
   if user:
     climber = Climber.from_appengine_user(user)
     memberships = climber.memberships.fetch(20)
     context['memberships'] = memberships
   else:
     context['error'] = 'log in to view memberships!'
   tmpl = path.join(path.dirname(__file__), 'static/html/memberships.html')
   self.response.out.write(render(tmpl, context))
Exemple #3
0
  def get(self):
    user = users.get_current_user()
    sends = []
    if user:
      member_gyms = [i.gym for i in Climber.from_appengine_user(user).memberships.fetch(20)]
      sends = [gym.sends.order('-timestamp').fetch(20) for gym in member_gyms]
    else:
      sends = Send.all().order('-timestamp').fetch(20)
    context = {
        'user': user,
#        'login': users.create_login_url(self.request.uri),
        'login': users.create_login_url('/login'),
        'logout': users.create_logout_url(self.request.uri),
        'sends': sends}
    tmpl = path.join(path.dirname(__file__), 'static/html/index.html')
    self.response.out.write(render(tmpl, context))
Exemple #4
0
  def post(self):
    user = users.get_current_user()
    if user:
      climber = Climber.from_appengine_user(user)
      gym = Gym()
      gym.name = self.request.get('name')
      gym.put()

      membership = GymMembership()
      membership.climber = climber
      membership.user = user
      membership.gym = gym
      membership.owner = True
      membership.put()

      context = {
          'gym_name': gym.name,
          'error': False}
    else:
      context = {'error': 'log in to create a gym!'}

    tmpl = path.join(path.dirname(__file__), 'static/html/addgymresult.html')
    self.response.out.write(render(tmpl, context))
Exemple #5
0
 def get(self):
   user = users.get_current_user()
   if user:
     climber = Climber.from_appengine_user(user)
   super(LoginHandler, self).get()