from . import portfolio_blueprint
from flask import render_template, abort, send_from_directory
from os import listdir
import os

categories = ['residential', 'commercial', 'office', 'industrial']

@portfolio_blueprint.route('/')
def index():
    return render_template('index.html')

@portfolio_blueprint.route('/portfolio/')
def gallery():
    photos = listdir('portfolio/residential')
    return render_template('gallery.html', photos=photos)

def photo_generator():
    for photo in listdir('portfolio/residential'):
        path = photo
    yield ('show_photo', {'category':'residential', 'filename':path})

@portfolio_blueprint.route('/portfolio/<category>/<path:filename>')
def show_photo(category, filename):
    root_dir = os.getcwd()
    # print(os.getcwd())
    # print(os.path.join(os.getcwd(), 'portfolio', category, filename))
    # print(listdir('portfolio/residential'))
    
    return send_from_directory(os.path.join(root_dir, 'portfolio', category), filename)