Esempio n. 1
0
def edit_puppy(shelter_id, shelter_name, puppy_id):
    SHELTERS = Shelter.query.all()
    shelterq = Shelter.query.all()
    editpuppy = Puppy.query.filter_by(id=puppy_id).one()
    editprofile = Profile.query.filter_by(puppy_id=editpuppy.id).one()
    form = CreatePuppy(obj=editpuppy)
    form1 = CreateProfile(obj=editprofile)
    form.shelter.choices = [(i.id, i.name) for i in shelterq]
    if form.validate_on_submit():
        editpuppy.name = form.name.data
        editpuppy.gender = form.gender.data
        editpuppy.picture = form.picture.data
        editpuppy.weight = form.weight.data
        editpuppy.shelter_id = form.shelter.data
        editpuppy.weight = form.weight.data

        editprofile.breed = form1.breed.data
        editprofile.specialNeeds = form1.specialNeeds.data
        editprofile.description = form1.description.data
        db.session.add(editpuppy)
        db.session.add(editprofile)
        if overflow(editpuppy.shelter_id):
            db.session.commit()
            counting_shows()
            flash(
                '<strong>%s</strong> was successfully edited!' %
                editpuppy.name, 'info')
            return redirect(
                url_for('puppy_profile',
                        shelter_id=shelter_id,
                        shelter_name=shelter_name,
                        puppy_id=puppy_id))
        else:
            flash(
                '<strong>%s</strong> has too many puppies try another.' %
                editpuppy.shelter.name, 'danger')
            db.session.rollback()
            counting_shows()
            return redirect(
                url_for('puppy_profile',
                        shelter_id=shelter_id,
                        shelter_name=shelter_name,
                        puppy_id=puppy_id))
    return render_template("edit_puppy_profile.html",
                           editpuppy=editpuppy,
                           form=form,
                           form1=form1,
                           SHELTERS=SHELTERS)
Esempio n. 2
0
def new_puppy():
    SHELTERS = Shelter.query.all()
    shelterq = Shelter.query.all()
    form = CreatePuppy()
    form1 = CreateProfile()
    form.shelter.choices = [(i.id, i.name) for i in shelterq]
    if form.validate_on_submit() and form1.validate_on_submit:
        newpuppy = Puppy(name=form.name.data,
                         gender=form.gender.data,
                         dateOfBirth=create_random_age(),
                         picture=form.picture.data,
                         shelter_id=form.shelter.data,
                         weight=create_random_weight(),
                         show=True)
        db.session.add(newpuppy)
        db.session.commit()
        newprofile = Profile(breed=form1.breed.data,
                             specialNeeds=form1.specialNeeds.data,
                             description=descriptions(),
                             puppy_id=newpuppy.id)
        db.session.add(newprofile)
        db.session.commit()
        if overflow(newpuppy.shelter_id):
            # db.session.commit()
            counting_shows()
            flash(
                '<strong>Successfully</strong> Added ' + '<u>' +
                newpuppy.name + '</u>' + ' to ' + newpuppy.shelter.name,
                'success')
            return redirect(url_for('index'))
        else:
            flash(
                '<div class="text-capitalize"><strong>%s</strong></div> has too many puppies try another shelter!'
                % newpuppy.shelter.name, 'danger')
            db.session.rollback()
            counting_shows()
            return redirect(url_for('index'))

    return render_template('create_puppy.html',
                           form=form,
                           form1=form1,
                           SHELTERS=SHELTERS)