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)
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)
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)
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)
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)
def logout(): logout_user() flash("You are logged out") return redirect(url_for('index'))