def create(): lat = request.form.get('lat') lng = request.form.get('lng') position = Position.get_or_none(Position.user == current_user.id) if position == None: Position.create(user=current_user.id, lat=lat, lng=lng) return jsonify({'ok': True, 'message': 'Position has been saved'}) else: position.lat = lat position.lng = lng if not position.save(): resp = jsonify({'message': 'Unable to save position'}) resp.status_code = 400 return resp return jsonify({'ok': True, 'message': 'Position has been saved'})
def new(): post_data = request.get_json() lat = post_data.get('lat') lng = post_data.get('lng') user = User.get_or_none(id=post_data.get('id')) position = Position.get_or_none(Position.user == user.id) if position == None: Position.create(user=user.id, lat=lat, lng=lng) return jsonify({'ok': True, 'message': 'Position has been saved'}) else: position.lat = lat position.lng = lng if not position.save(): resp = jsonify({'message': 'Unable to save position'}) resp.status_code = 400 return resp return jsonify({'ok': True, 'message': 'Position has been saved'})