Ejemplo n.º 1
0
def seed_db():
    from models.Animal import Animal
    from models.Shelter import Shelter
    import random

    shelters = []

    for i in range(5):
        shelter = Shelter()
        shelter.name = f"Shelter {i}"
        shelter.email = f"test{i}@email.com"
        shelter.phone = "000000000"
        shelter.address = f"{i} Bilbi Street"
        shelter.city = "Shelter City {i}"
        db.session.add(shelter)
        shelters.append(shelter)

    db.session.commit()

    for i in range(15):
        animal = Animal()
        animal.name = f"Animal{i}"
        animal.kind = f"Kind{i}"
        animal.breed = f"Breed{i}"
        animal.age = f"{i + 13} weeks"
        animal.shelter_id = random.choice(shelters).id
        db.session.add(animal)

    db.session.commit()
    print("Tables seeded")
Ejemplo n.º 2
0
def animal_create():
    form = AnimalForm(request.form)
    if request.method == 'POST' and form.validate_on_submit():
        animal_fields = request.form
        new_animal = Animal()
        new_animal.name = animal_fields["name"]
        new_animal.kind = animal_fields["kind"]
        new_animal.breed = animal_fields["breed"]
        new_animal.age = animal_fields["age"]
        new_animal.shelter_id = animal_fields["shelter_id"]

        db.session.add(new_animal)
        db.session.commit()
        # return jsonify(animal_schema.dump(new_animal))
        return 'Animal Added!'
    return render_template('animal_create.html', form=form)
def animal_create(user=None):
    shelter = Shelter.query.filter_by(user_id=user.id).first()

    if not shelter:
        return abort(400, description= "Not authorised, you need to create a shelter first")

    animal_fields = animalSchema.load(request.json)

    new_Animal = Animal()
    new_Animal.name = animal_fields["name"]
    new_Animal.kind = animal_fields["kind"]
    new_Animal.breed = animal_fields["breed"]
    new_Animal.age = animal_fields["age"]
    new_Animal.shelter_id = shelter.id

    db.session.add(new_Animal)
    db.session.commit()
    return jsonify(animalSchema.dump(new_Animal))
def animal_create():
    shelter = Shelter.query.filter_by(user_id=current_user.id).first()

    if not shelter:
        return abort(
            400,
            description="Not authorised, you need to create a shelter first")

    #animal_fields = animalSchema.load(request.json)

    new_Animal = Animal()
    new_Animal.name = request.form.get("name")
    new_Animal.kind = request.form.get("kind")
    new_Animal.breed = request.form.get("breed")
    new_Animal.age = request.form.get("age")
    new_Animal.shelter_id = shelter.id

    db.session.add(new_Animal)
    db.session.commit()
    #return jsonify(animalSchema.dump(new_Animal))
    return redirect(url_for('animals.animal_index'))
Ejemplo n.º 5
0
def seed_db():
    from main import bcrypt
    from models.Shelter import Shelter
    from models.Animal import Animal
    from models.User import User

    u1 = User()
    u1.username = "******"
    u1.password = bcrypt.generate_password_hash("123456").decode("utf-8")
    db.session.add(u1)

    u2 = User()
    u2.username = "******"
    u2.password = bcrypt.generate_password_hash("123456").decode("utf-8")
    db.session.add(u2)

    db.session.commit()

    s1 = Shelter()
    s1.name = "Brisbane Shelter"
    s1.address = "100 Main st "
    s1.email = "*****@*****.**"
    s1.city = "Brisbane"
    s1.phone = "1800011122"
    s1.user_id = 1
    db.session.add(s1)

    s2 = Shelter()
    s2.name = "Sydney Shelter"
    s2.address = "100 Adelaide st "
    s2.email = "*****@*****.**"
    s2.city = "Sydney"
    s2.phone = "180024135122"
    s2.user_id = 2
    db.session.add(s2)

    db.session.commit()

    a1 = Animal()
    a1.name = "Rusty"
    a1.kind = "Dog"
    a1.breed = "Jack Russell"
    a1.age = "10 years"
    a1.shelter_id = 1
    db.session.add(a1)

    a2 = Animal()
    a2.name = "Kubernetes"
    a2.kind = "Koala"
    a2.age = "2 years"
    a2.shelter_id = 1
    db.session.add(a2)

    a3 = Animal()
    a3.name = "Flask"
    a3.kind = "Snake"
    a3.breed = "Python"
    a3.age = "1 year"
    a3.shelter_id = 2
    db.session.add(a3)

    a4 = Animal()
    a4.name = "Docker"
    a4.kind = "Kangaroo"
    a4.age = "2 years"
    a4.shelter_id = 2
    db.session.add(a4)

    db.session.commit()