Example #1
0
def login():
    username, password = request.json['username'], request.json['password']

    # find user
    try:
        user = User.query.filter(User.username == username).one()
    except NoResultFound:
        return error(Errors.AUTHENTICATION_ERROR)
    # check password
    if not user.check_password(password):
        return error(Errors.AUTHENTICATION_ERROR)
    # generate password and return
    auth_token = AuthToken(user_id=user.id)
    db.session.add(auth_token)
    db.session.commit()

    return jsonify({'token': auth_token.token})
Example #2
0
def rud_stop_point(stop_point_id):
    stop_point = StopPoint.query.get(stop_point_id)
    if not stop_point:
        return error(Errors.OBJECT_NOT_FOUND_ERROR)
    if request.method == 'DELETE':
        db.session.delete(stop_point)
        db.session.commit()
    return jsonify(location_schema.dump(stop_point))
Example #3
0
def create_location():
    name, slug = request.json['name'], request.json['slug']
    try:
        location = Location(name=name, slug=slug)
        db.session.add(location)
        db.session.commit()
    except IntegrityError:
        return error(Errors.SLUG_ALREADY_EXISTS_ERROR)
    return jsonify(location_schema.dump(location))
Example #4
0
def rud_location(location_id):
    # find location
    location = Location.query.get(location_id)
    if not location:
        return error(Errors.OBJECT_NOT_FOUND_ERROR)
    if request.method == 'DELETE':
        db.session.delete(location)
        db.session.commit()
    return jsonify(location_schema.dump(location))
Example #5
0
def get_timetable_for_location_slug(slug):
    try:
        location = Location.query.filter(Location.slug == slug).one()
    except NoResultFound:
        return error(Errors.OBJECT_NOT_FOUND_ERROR, status_code=404)
    stop_point_refs = [stop_point.ref for stop_point in location.stop_points]

    result_lists = list(get_timetable_for_stop_point_ref_list_multithreaded(stop_point_refs))
    result = itertools.chain.from_iterable(result_lists) # todo: have to sort the lists while/after jaining them
    return jsonify(list(result))