Beispiel #1
0
def add():

    if "username" in session:
        usrname = session["username"]
        form = CarForm(request.form)
        if request.method == 'POST' and form.validate():
            car = Car()
            save_changes(car, form, new=True)
            flash('Car created successfully!')
            return render_template('adminBase.html', form=form)

        return render_template('addCar.html', form=form)
    else:
        flash("You must login first!", "info")
        return redirect(url_for("login"))
Beispiel #2
0
def edit(id):
    """
    edit a Car in the database
    """
    if "username" in session:
        usrname = session["username"]
        car = Car.query.filter(Car.car_id == id).first()

        if car:
            form = CarForm(formdata=request.form, obj=car)
            if request.method == 'POST' and form.validate():

                save_changes(car, form)
                flash('Car updated successfully!')
                return render_template('adminBase.html', form=form)
            return render_template('edit_car.html', form=form)
        else:
            return 'Error loading #{id}'.format(id=id)