Пример #1
0
def delpup():

    form = Del_form()

    if form.validate_on_submit():
        id = form.id.data
        pup = Puppy.query.get(id)
        db.session.delete(pup)
        db.session.commit()

        return redirect(url_for('puppies.listpup'))
    return render_template("delpup.html", form=form)
Пример #2
0
def register():

    form = RegistrationForm()

    if form.validate_on_submit():
        user = User(email=form.email.data,
                    username=form.username.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("Your are Registered Successfully")
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Пример #3
0
def ownpup():
    form = Add_form()

    if form.validate_on_submit():
        name = form.name.data
        id = form.id.data

        new_own = Owner(name, id)

        db.session.add(new_own)
        db.session.commit()
        flash(f"Puppy {id} is adopted by {name}")
        return redirect(url_for("puppies.listpup"))
    return render_template("ownpup.html", form=form)
Пример #4
0
def addpup():
    form = Add_form()

    if form.validate_on_submit():

        name = form.name.data

        new_pup = Puppy(name)

        db.session.add(new_pup)
        db.session.commit()
        return redirect(url_for('puppies.listpup'))

    return render_template("addpup.html", form=form)
Пример #5
0
def login():

    form = Login()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user.checkpassword(form.password.data) and user is not None:
            login_user(user)
            flash("You have logged in Succesfully")

            next = request.args.get('next')

            if next is None or not next[0] == '/':
                next = url_for('index')

            return redirect(next)

    return render_template('/login.html', form=form)
Пример #6
0
def logout():
    logout_user()
    flash("You are logged out")
    return redirect(url_for('index'))