def image():
    image_create_form = ImageCreateForm(request.form)
    image_delete_form = ImageDeleteForm(request.form)

    if image_delete_form.validate_on_submit():
        did_delete = image_delete_form.deleteImage()
        if did_delete:
            flash('Image Removed', 'info')
        else:
            flash('Image Doesn\'t Exists', 'error')

    elif image_create_form.validate_on_submit():
        image_create_form.create()
        flash('Image Created', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(image_create_form)
        # 1 retrieve rows from the UserImages
        # User.query.filter(User.filename('user')).all()

    usr_images = UserImages.query.filter(UserImages.user_id == current_user.id)
    # 2 define imgs to be a list of filenames
    # imgs = [url_for('static', filename='uploadFolder/' + i.filename) for i in usr_images]
    image_forms = [ImageDeleteForm(img=i) for i in usr_images]

    return render_template('users/image.html', form=image_create_form, img_forms=image_forms)
def register():
    """Register new user."""
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        User.create(username=form.username.data, email=form.email.data, password=form.password.data, active=True)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
def home():
    """Home page."""
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash('You are logged in.', 'success')
            redirect_url = request.args.get('next') or url_for('user.me')
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_template('public/home.html', form=form)
def profile():

    profile_picture_form = profilePicForm(request.form)

    if profile_picture_form.validate_on_submit():
        profile_picture_form.createPP
        flash('Profile Picture Updated', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(profile_picture_form)

    user_pictures = profilePictures.query.filter(profilePictures.filename)
    # profilePictures.create(user_id=cu rrent_user.id, filename=filename)

    # profile_pics = [(img=i) for i in user_pictures]
    return render_template('users/profile.html', form=profile_picture_form, img_forms=user_pictures)  #, img_forms=profile_pics
def formImage():
    """create Image"""
    form = ImageCreateForm(request.form, csrf_enabled=False)

    if form.validate_on_submit():
        form.create()
        #^^^^^^^^^^add to imgs[].
        flash('Image Created', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
        # 1 retrieve rows from the UserImages
        # User.query.filter(User.filename('user')).all()
        usr_images = UserImages.query.filter(UserImages.user_id == current_user.id)
        # 2 define imgs to be a list of filenames
        imgs = [url_for('static', filename='uploadFolder/' + i.filename) for i in usr_images]

    return render_template('users/image.html', form=form, imgs=imgs)