예제 #1
0
def upload_image(username):
    """Upload an image."""

    # Cannot upload an image to another user's account
    if username != current_user.username:
        return jsonify({'status': 'fail', 'message': 'Access denied.'}), 401

    image_file = request.files.get('image')
    cloudinary_upload = cloudinary.uploader.upload(image_file)
    image_url = cloudinary_upload['url']

    # Check if request wants to set permissions
    permission = None
    if request.form.get('permission'):
        permission = request.form.get('permission')

    # Create Image and catch errors such as providing incorrect
    # permission values other than PRVIATE or PUBLIC
    try:
        user = crud.get_user_by_username(current_user.username)
        image = crud.create_image(image_url, user, permission)
    except:
        return jsonify(error_msg), 500

    return jsonify({
        'status': 'success',
        'message': 'Image successfully uploaded.',
        'permission': image.permission.name,
        "image_url": image_url
    })
예제 #2
0
def create_test_image(test_recipe):
    """Create test image."""

    image_in_api = test_recipe["strMealThumb"]

    image = crud.create_image(image_in_api)

    return image
예제 #3
0
def seed_image():
    """preloaded images for image library"""

    with open('data/image_data.json') as f:
        image_data = json.loads(f.read())

    for image in image_data:
        image_name = image['image_name']
        image_description = image['image_description']
        image_url = image['image_url']

        new_image = crud.create_image(image_name, image_description, image_url)
예제 #4
0
def image():
    if 'user_id' not in session:
        return redirect('/')
    user_id = session['user_id']
    image_title = request.json.get('image_title')
    artist = request.json.get('artist')
    location = request.json.get('location')
    image_url = request.json.get('image_url')

    image_obj = crud.create_image(user_id, image_title, artist, location,
                                  image_url)

    return jsonify({'completed': True})
예제 #5
0
def upload_item():
    """Upload new image to repository"""

    image = request.files.get('file')
    print(image)
    if image:
        image_url = upload_api.upload_closet_image(image)
        image_name = request.form.get('image_name')
        image_description = request.form.get('image_description')

        new_image = crud.create_image(image_name, image_description, image_url)
        session['image_id'] = new_image.image_id

        return jsonify(crud.jsonify_image(new_image))
예제 #6
0
def upload_images(user_id):
    """Upload images to cloudinary."""

    image = request.files.get("file")

    #getting the user id using session
    user_id = session.get('user_id')

    if image:
        image_path = cloudinary_image_api.upload_image(image)

        description = request.form.get("user-description")
        print("description:", description)

        new_image = crud.create_image(image_path, description, user_id)

    return redirect(f'/profile/{user_id}')
예제 #7
0
    'green',
    'brown',
]

# Create colors
for color in list_colors:
    crud.create_color(color)

# Load dummy images data from JSON file
with open('data/images.json') as f:
    image_data = json.loads(f.read())

# Create images
for image in image_data:
    # create the images
    title, url_path = (image['title'], image['url_path'])
    uuid_num = uuid.uuid4()
    width, height = (image['width'], image['height'])
    file_size = image['file_size']
    date_added = datetime.strptime(image['date_added'], '%Y-%m-%d')
    status = image['status']

    image_obj = crud.create_image(title, url_path, uuid_num, width, height,
                                  file_size, date_added, status)

    # link to the colors
    colors = image['colors']
    for color in colors:
        color_obj = crud.get_id_by_color(color)
        crud.create_image_color(image_obj.id, color_obj.id)
예제 #8
0
def create_recipe():
    """Show create recipe page."""

    if request.method == "GET":

        cuisines = crud.get_cuisines()
        categories = crud.get_categories()
        ingredients = crud.get_ingredients()

        if session.get("user_id") == None:
            flash("Please log in to create a new recipe.")
            return redirect('/')

        return render_template("create_recipe.html",
                               cuisines=cuisines,
                               categories=categories,
                               ingredients=ingredients)

    elif request.method == "POST":

        kwargs = {
            "title": request.form.get("title"),
            "description": request.form.get("description"),
            "prep_time": request.form.get("prep_time"),
            "cook_time": request.form.get("cook_time"),
            "total_time": request.form.get("total_time"),
            "serving_qty": request.form.get("serving_qty"),
            "source": request.form.get("source"),
            "user_id": session.get("user_id"),
            "cuisine_id": request.form.get("cuisine_id")
        }

        recipe = crud.create_recipe(**kwargs)

        category_id = request.form.get("category_id")
        crud.create_recipe_category(recipe.recipe_id, category_id)

        # Get ingredient, measurement, and instruction items in a dictionary
        # If flat is False, returns all items as a list
        request_dict = request.form.to_dict(flat=False)

        for ingredient, measurement in zip(request_dict["ingredients"],
                                           request_dict["measurements"]):
            ingredient_object = crud.create_ingredient(ingredient)
            crud.create_recipe_ingredient(recipe.recipe_id,
                                          ingredient_object.ingredient_id,
                                          measurement)

        for step_num, instruction in enumerate(request_dict["instructions"]):
            crud.create_recipe_step(recipe.recipe_id, step_num + 1,
                                    instruction)

        # Get images from create recipe form
        for image in request_dict["images"]:
            image_object = crud.create_image(image)
            crud.create_recipe_image(recipe.recipe_id, image_object.image_id)

        if recipe:
            flash('Congrats! A new recipe was created.')

        else:
            flash('Error.')

        return redirect('/create_recipe')
예제 #9
0
    'Lieblich', 'Sutherland', 'Ong', 'Ainawaer', 'Flatland', 'Gerrity',
    'Latif', 'Wong'
]
tags = [
    'nature', 'trail', 'Denali', 'Yosemite', 'Acadia', 'Arches', 'Carlsbad',
    'Everglades', 'Glacier', 'Mesa Verde', 'Olympic'
]

user_list = []
#create fake 10 fake users
for n in range(10):
    username = f'Test{n}'
    password = '******'
    user_fname = choice(fnames)
    user_lname = choice(lnames)
    profile_picture = choice(files)
    email = f'hiker{n}@gmail.com'

    #create user
    user_object = crud.create_user(username, password, user_fname, user_lname,
                                   email, profile_picture)
    user_list.append(user_object)
    # images
    for i in range(5):
        image = crud.create_image(user_object.user_id, choice(files),
                                  choice(tags), choice(tags), choice(tags))

# friends
for users in user_list:
    friend_object = crud.create_friend(users.user_id, randint(1, 10))
예제 #10
0
    instagram_channel_in_db.append(db_instagram_channel)
#
with open('data/image.json') as f:

    image_data = json.loads(f.read())

image_in_db = []

for image in image_data:
    channel_name, format, image_url, video_views, hearts, comments, tags, date_posted, date_updated = (
        image['channel_name'], image['format'], image['image_url'],
        image['video_views'], image['hearts'], image['comments'],
        image['tags'], image['date_posted'], image['date_updated'])

    db_image = crud.create_image(channel_name, format, image_url, video_views,
                                 hearts, comments, tags, date_posted,
                                 date_updated)

    image_in_db.append(db_image)

#
with open('data/instagram_comment.json') as f:

    instagram_comment_data = json.loads(f.read())

instagram_comment_in_db = []

for instagram_comment in instagram_comment_data:
    channel_name, image_id, comment, commentator, replied, date_posted, date_updated = (
        instagram_comment['channel_name'], instagram_comment['image_id'],
        instagram_comment['comment'], instagram_comment['commentator'],
예제 #11
0
def edit_user_profile():
    """Edit user profile with user form responses."""

    # if user is not logged in, redirect them to the login page
    if not current_user.is_authenticated:
        return redirect('/create-account')
# collect the users id using Flask-Login function 'current_user'
    user_id = current_user.user_id
    user_object = User.query.get(user_id)

    form_id = request.form.get("form_id")

    #add image from gallery
    if form_id == "add_from_gallery":
        image_name = request.form.get("image_name")
        tag1 = request.form.get("tag1")
        tag2 = request.form.get("tag2")
        tag3 = request.form.get("tag3")

        crud.create_image(user_id, image_name, tag1, tag2, tag3)

    #delete image
    if form_id == "delete_image":
        # for security, ensure that the user deleting the image is the logged in user
        if current_user.user_id == user_id:
            image_id = request.form.get("image_id")
            Image.query.filter(Image.image_id == image_id).delete()
            db.session.commit()

        return redirect("user_profile")

    #add image
    if form_id == "add_image":
        tag1 = request.form.get("tag1")
        tag2 = request.form.get("tag2")
        tag3 = request.form.get("tag3")

        if "file1" not in request.files:
            flash("We couldn't find your profile picture!")
            return redirect("/user_profile")

        f = request.files["file1"]

        result = image_helper.resize_image_square_crop(f.stream, (400, 400))
        (success, msg, resized_image) = result
        if success is False:
            flash(msg)
            return redirect("user_profile")
        else:
            file_name = str(user_id) + ".jpg"
            path = os.path.join(UPLOAD_FOLDER_IMAGE, file_name)
            resized_image.save(path)

        image = crud.create_image(user_id, file_name, tag1, tag2, tag3)

        return redirect("user_profile")

    #basic form
    if form_id == "basic_profile_information":
        user_fname = request.form.get("first_name")
        user_lname = request.form.get("last_name")
        email = request.form.get("email")
        crud.update_user_profile_info(user_id, user_fname, user_lname, email)

        return redirect("user_profile")

    #profile pic
    elif form_id == "profile_picture":
        if "file1" not in request.files:
            flash("We couldn't find your profile picture!")
            return redirect("/user_profile")

        f = request.files["file1"]

        result = image_helper.resize_image_square_crop(f.stream, (400, 400))
        (success, msg, resized_image) = result
        if success is False:
            flash(msg)
            return redirect("user_profile")
        else:
            file_name = str(user_id) + ".jpg"
            path = os.path.join(UPLOAD_FOLDER_PROFILE_PICTURE, file_name)
            resized_image.save(path)

            crud.set_user_profile_picture(user_id, file_name)

        return redirect("user_profile")

    #edit friends
    elif form_id == "edit_friends":
        unfriend_id = request.form.get("friends")
        User_Friend.query.filter(
            User_Friend.user_friend_list_id == unfriend_id).delete()

        flash("Friend Removed")

        return redirect("user_profile")

    #password
    elif form_id == "password_change":
        old_password = request.form.get("old_password")
        new_password = request.form.get("new_password")

        if (crud.update_password(user_id, old_password, new_password) is
                False):
            flash("Old password is incorrect")
        else:
            flash("Password Updated")
        return redirect("user_profile")

    else:
        return redirect("user_profile")

    return render_template('profile_edit.html',
                           user_id=user_id,
                           user_object=user_object)
예제 #12
0
def DO_ALL_CRUD():

    jb = crud.create_user(
        first_name="Jen",
        last_name="Brissman",
        email="*****@*****.**",
        password=
        "******",
    )

    sm = crud.create_user(
        first_name="Sean",
        last_name="Montgomery",
        email="*****@*****.**",
        password=
        "******",
    )

    jb_1 = crud.create_image(
        user_id=1,
        image_title="We The Youth ",
        location="Point Breeze, Philadelphia, PA, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619932052/mxfnawmcjclmcfu7m6hz.jpg",
        artist="Keith Haring ")

    jb_2 = crud.create_image(
        user_id=1,
        image_title="Nobody Likes Me",
        location="Stanley Park Drive, Vancouver, BC, Canada",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619932267/dgzi2f2pntycxshkmkj5.jpg",
        artist="Iheart")

    jb_3 = crud.create_image(
        user_id=1,
        image_title="Sailor's Kiss",
        location="The High Line, West 30th Street, New York, NY, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619933391/meq168zr4pglkskc8oge.jpg",
        artist="Kobra")

    jb_4 = crud.create_image(
        user_id=1,
        image_title="First Love",
        location="Berlin, Germany",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619934247/hun3z6salup2dodkeyfy.jpg",
        artist="Tavar Zawacki - Above")

    jb_5 = crud.create_image(
        user_id=1,
        image_title="Bridge The Divide",
        location="Berlin, Germany",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620004892/xr4wxuihcrpdl557a57z.jpg",
        artist="Above")

    jb_6 = crud.create_image(
        user_id=1,
        image_title="Bonfire",
        location="NYC, NY, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620005160/awblug5nlxremmihnbyy.webp",
        artist="Maya Hayuk")

    jb_7 = crud.create_image(
        user_id=1,
        image_title="Buffalo-Skeleton",
        location="Lexington, KY, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619972000/ydu5wgtsq3oulhafzv5o.jpg",
        artist="ROA")

    jb_8 = crud.create_image(
        user_id=1,
        image_title="Part I",
        location="Ribeira Grande, Portugal",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619932936/wrunm2bl7ztdocquec5s.jpg",
        artist="Vhils")

    jb_9 = crud.create_image(
        user_id=1,
        image_title="Women Are Heroes",
        location="Kibera slum, Nairobi, Kenya",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619933572/xydacpgcz6l9mjrxwwbr.png",
        artist="JR")

    jb_10 = crud.create_image(
        user_id=1,
        image_title="Untitled",
        location="Wynwood Walls, Northwest 2nd Avenue, Miami, FL, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619934537/occpxh9tpozbzrzanp64.jpg",
        artist="Martin Whatson")

    jb_11 = crud.create_image(
        user_id=1,
        image_title="KAWS Mural                      ",
        location=
        "Brooklyn Academy of Music, Lafayette Avenue, Brooklyn, NY, USA",
        image_url=
        " http://res.cloudinary.com/jenbrissman/image/upload/v1619971024/btc4r9g87m80zborsx6t.jpg",
        artist="KAWS")

    jb_12 = crud.create_image(
        user_id=1,
        image_title="The Natural State",
        location="Fort Chaffee, Fort Smith, AR, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619971314/qwgb9dnwj7lnzodipzqb.png",
        artist="DabsMyla")

    jb_13 = crud.create_image(
        user_id=1,
        image_title="Vetri Cucina - Secret Stairwell",
        location="Palms Casino Resort, West Flamingo Road, Las Vegas, NV, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619971525/rkjdezuoqpc4jhqbi6mk.png",
        artist="DabsMyla")

    jb_14 = crud.create_image(
        user_id=1,
        image_title="Mobile Lovers",
        location="Bristol, UK",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619972639/eumoj4xfkehqc3dseavw.jpg",
        artist="Banksy")

    jb_15 = crud.create_image(
        user_id=1,
        image_title="Super Nurse!",
        location="Amsterdam, Netherlands",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619972421/wnd4xulrydirrfguy0lg.jpg",
        artist="FAKE")

    jb_16 = crud.create_image(
        user_id=1,
        image_title="Visual Disobedience",
        location="The Pulse, Beach Road, Repulse Bay, Hong Kong",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1619933271/lx8g3tlccrbzppngefqt.jpg",
        artist="Shepard Fairey")

    jb_17 = crud.create_image(
        user_id=1,
        image_title="Fight For Street Art!",
        location="Williamsburg, Brooklyn, NY, USA",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620005301/kcgyt2hixkdpn28z8wbl.jpg",
        artist="Kobra")

    jb_18 = crud.create_image(
        user_id=1,
        image_title="Girl With Balloon",
        location="Waterloo Bridge / South Bank (Stop P), London, UK",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620009224/pxaiopkkajvv1f8izd9v.jpg",
        artist="Banksy")

    jb_19 = crud.create_image(
        user_id=1,
        image_title="Rainbow Boy",
        location="Albatross Gardens, South Croydon, UK ",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620009575/dhwbfrzgv7x3l1koaytd.jpg",
        artist="Chris Shea")

    jb_20 = crud.create_image(
        user_id=1,
        image_title="Timing Is Everything ",
        location="Shoreditch, London, UK ",
        image_url=
        "http://res.cloudinary.com/jenbrissman/image/upload/v1620009871/ug1l9mofslh4clet40zi.jpg",
        artist="Tavar Zawaki - Above")