Beispiel #1
0
def cars():
    cars_query = (Cars.select(Cars.car_plate, Users.first_name,
                              Users.last_name, Users.phone_number,
                              CarColors.color_name).join(Users).join(
                                  CarColors,
                                  on=(Cars.color_id == CarColors.color_id)))
    carsList = list(cars_query.dicts())
    print(carsList)
    return render_template('cars.html', carsList=carsList)
Beispiel #2
0
def get_data_cars():
    if request.method == 'GET':
        cars = Cars.select()
        result = []
        for car in cars:
            result.append(model_to_dict(car))
        return jsonify(result)
    if request.method == 'POST':
        if not request.json or not 'dealer' in request.json:
            abort(400)
        data = {
            'brand': request.json.get('brand', ""),
            'car_model': request.json.get('car_model', ""),
            'year_release': request.json.get('year_release'),
            'price': request.json.get('price'),
            'dealer': request.json.get('dealer'),
        }
        new_car = dict_to_model(Cars, data)
        new_car.save()
        return jsonify({'result': data}), 201
Beispiel #3
0
def edit_car(car_plate):
    if request.method == 'GET':
        cars_query = CarColors.select()
        car_colors = list(cars_query.dicts())
        users_query = Users.select()
        users = list(users_query.dicts())
        cars_query = (Cars.select(
            Cars.car_plate, Cars.user_id,
            Cars.color_id).where(Cars.car_plate == car_plate))
        car = list(cars_query.dicts())[0]
        return render_template('edit_car.html',
                               car=car,
                               users=users,
                               carColors=car_colors)
    elif request.method == 'POST':
        try:
            car_to_update = get_car_to_update()
            Cars.update(car_to_update).where(
                Cars.car_plate == car_plate).execute()
            flash('Updated car successfully.', 'success')
            return redirect(url_for('cars'))
        except:
            flash('Couldnt update car.', 'danger')
            return redirect(url_for('cars'))