Ejemplo n.º 1
0
def createShelter():
    if request.method == "GET":
        return render_template("create_shelter.html")
    else:
        #Validation would be done on the client-side with JS, which i'm not going to do in this project
        newShelter = Shelter()
        newShelter.name = request.form["shelterName"]
        newShelter.city = request.form["shelterCity"]
        session.add(newShelter)
        session.commit()
        return redirect(url_for("shelters"))
Ejemplo n.º 2
0
def newShelter():
    """Create new shelter"""
    if request.method == 'POST':
        if request.form['name']:
            name = request.form['name']
            address = request.form['address']
            city = request.form['city']
            state = request.form['state']
            zipCode = request.form['zip']
            user_id = login_session['user_id']
            newShelter = Shelter(name=name,
                                 address=address,
                                 city=city,
                                 state=state,
                                 zipCode=zipCode,
                                 user_id=user_id)
            session.add(newShelter)
            session.commit()
            flash("New Shelter Created")
            return redirect(url_for("listShelter"))
        else:
            flash("A name for your shelter would be deeply appreciated.")
            return render_template('shelter-new.html')
    else:
        return render_template("shelter-new.html")
Ejemplo n.º 3
0
def item_new(list_type):
    if request.method == 'GET':
        puppies = session.query(Puppy).all()
        shelters = session.query(Shelter).all()
        owners = session.query(Owner).all()
        if list_type =='puppies':
            template = 'puppies_add.html'
            form = puppyForm()
            form.shelter.choices = [ (g.id, g.name) for g in session.query(Shelter).all() ]
        elif list_type =='shelters':
            template = 'shelters_add.html'
            form = shelterForm()
        elif list_type == 'owners':
            template = 'owners_add.html'
            form = ownerForm()
        else:
            template = 'error404.html'
            form = puppyForm()
            list_type = 'puppies'
        return render_template( template, list_type=list_type, puppies = puppies, shelters = shelters, owners = owners, form = form)
#handles POST
    elif request.method == 'POST':
        if list_type == 'puppies':
            form = puppyForm(request.form)
            form.shelter.choices = [ (g.id, g.name) for g in session.query(Shelter).all() ]
            if form.validate():
                thisshelter = session.query(Shelter).filter(Shelter.id==form.shelter.data).first()
                newItem = Puppy(name=form.name.data, dateOfBirth=form.dateOfBirth.data, gender=form.gender.data,
                     weight=form.weight.data, picture=form.picture.data, shelter_id=thisshelter.id )
            else:
                for fieldName, errorMessages in form.errors.iteritems():
                    for err in errorMessages:
                        flash('Error in '+fieldName+' field. '+err)
                return redirect(url_for('item_new', list_type = list_type))
        elif list_type =='shelters':
            form = shelterForm(request.form)
            if form.validate():
                newItem = Shelter(name=form.name.data, address=form.address.data, city = form.city.data,
                    state = form.state.data, zipCode = form.zipCode.data, website = form.website.data)
            else:
                for fieldName, errorMessages in form.errors.iteritems():
                    for err in errorMessages:
                        flash('Error in '+fieldName+' field. '+err)
                return redirect(url_for('item_new', list_type = list_type))
        elif list_type == 'owners':
            form = ownerForm(request.form)
            if form.validate():
                newItem = Owner(name=form.name.data, surname=form.surname.data,
                     gender =form.gender.data, age = form.age.data)
            else:
                for fieldName, errorMessages in form.errors.iteritems():
                    for err in errorMessages:
                        flash('Error in '+fieldName+' field. '+err)
                return redirect(url_for('item_new', list_type = list_type))
        session.add(newItem)
        session.commit()
        #app.logger.info('Added %s %s to the database.', list_type, form.name.data)
        flash("Succesfully added "+form.name.data+"!")
        return redirect(url_for('list_view', list_type=list_type))
Ejemplo n.º 4
0
def createShelter():
    if request.method == 'POST':
        newShelter = Shelter(name=request.form['name'],
                             address=request.form['address'],
                             phone=request.form['phone'],
                             email=request.form['email'],
                             owner=request.form['owner'])
        session.add(newShelter)
        session.commit()
        return redirect(url_for('allShelters'))
    return render_template('addshelter.html')
from random import randint
import datetime
import random

engine = create_engine('sqlite:///puppies.db')

Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()

#Add Shelters
shelter1 = Shelter(name="Oakland Animal Services",
                   address="1101 29th Ave",
                   city="Oakland",
                   state="California",
                   zipCode="94601",
                   website="oaklandanimalservices.org")
session.add(shelter1)

shelter2 = Shelter(name="San Francisco SPCA Mission Adoption Center",
                   address="250 Florida St",
                   city="San Francisco",
                   state="California",
                   zipCode="94103",
                   website="sfspca.org")
session.add(shelter2)

shelter3 = Shelter(name="Wonder Dog Rescue",
                   address="2926 16th Street",
                   city="San Francisco",
Ejemplo n.º 6
0
DBSession = sessionmaker(bind=engine)
session = DBSession()

User1 = User(
    name="Bob Shafer",
    email="*****@*****.**",
    picture=
    "https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png"
)
session.add(User1)
session.commit()

# Add Shelters
shelter1 = Shelter(name="Oakland Animal Services",
                   address="1101 29th Ave",
                   city="Oakland",
                   state="California",
                   zipCode="94601",
                   user_id=1)
session.add(shelter1)

shelter2 = Shelter(name="San Francisco SPCA Mission Adoption Center",
                   address="250 Florida St",
                   city="San Francisco",
                   state="California",
                   zipCode="94103",
                   user_id=1)
session.add(shelter2)

shelter3 = Shelter(name="Wonder Dog Rescue",
                   address="2926 16th Street",
                   city="San Francisco",
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

try:
    session.query(Shelter).delete()
    session.query(Puppy).delete()
    session.commit()
except:
    session.rollback()

shelter1 = Shelter(name="Rajat Patwa puppy shelter",
                   address="Street no. 7, House no. 8 ANewGalaxy, Mars.",
                   phone="a cool phone number",
                   email="a cool email address",
                   owner="Rajat Patwa")

session.add(shelter1)
session.commit()

puppy1 = Puppy(name="Tommy",
               weight=5.35,
               age=2,
               breed='German Shepherd',
               gender='Male',
               shelter=shelter1)

session.add(puppy1)
session.commit()