Exemplo n.º 1
0
def post_pet(user_id):
    """
    Creates a new Pet
    """
    user = storage.get(User, user_id)

    if not user:
        abort(404)

    if not request.get_json():
        abort(400, description="Not a JSON")

    if 'name' not in request.get_json():
        abort(400, description="Missing name")

    data = request.get_json()
    data["user_id"] = user_id

    pet = Pet(**data)
    pet.save()

    # creating the instance Picture for this pet
    picture = Picture(pet_id=pet.id)
    picture.save()

    return make_response(jsonify(pet.to_dict()), 201)
Exemplo n.º 2
0
def upload_pet_pictures(pet_id):
    """
    Upload the picture of a pet
    """
    data = request.get_data()
    if not data:
        abort(400, "Missing Photo")

    picture = Picture(data=data, pet_id=pet_id, name='photo_' + pet_id)
    picture.save()
    return make_response(jsonify({"status": "OK"}), 201)
Exemplo n.º 3
0
def upload_file(username):
    # A
    if "user_file" not in request.files:
        return "No user_file key in request.files"

# B
    file = request.files["user_file"]

    # C.
    if file.filename == "":
        return "Please select a file"

# D.
    if file and allowed_file(file.filename):
        file.filename = secure_filename(file.filename)
        output = upload_file_to_s3(file, S3_BUCKET)
        picture = Picture(picture_name=str(output), user=current_user.id)
        if picture.save():
            flash('Photo successfully uploaded')
            return redirect(url_for('users.show', username=current_user.name))
        else:
            return redirect(url_for('users.upload_file'))

    else:
        return redirect(url_for('users.upload'))
Exemplo n.º 4
0
user_1 = User(nickname="bryan",
              email="*****@*****.**",
              auth_id="a0t14527")
user_1.save()

pet_1 = Pet(user_id=user_1.id,
            name="Napa",
            race="labrador",
            birthday=date(2020, 9, 26),
            color="Yellow",
            specie="Perro",
            description="Cute new born")
pet_1.save()

pet_2 = Pet(user_id=user_1.id,
            name="firulais",
            race="labrador",
            birthday=date(2020, 10, 16))
pet_2.save()

collar_1 = Collar(user_id=user_1.id, pet_id=pet_1.id, numero_ref="1")
collar_1.save()

picture = Picture(pet_id=pet_1.id, name="firstpicture.jpg")
picture.save()
"""
 Verification
"""
print("Creacion de objetos exitosa")