105 lines
3.9 KiB
Python
105 lines
3.9 KiB
Python
from flask import Flask, render_template, send_from_directory
|
|
from flask_frozen import Freezer
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
freezer = Freezer(app)
|
|
|
|
app.config['FREEZER_RELATIVE_URLS'] = True
|
|
app.config['FREEZER_IGNORE_MIMETYPE_WARNINGS'] = True
|
|
|
|
@app.route('/')
|
|
@app.route('/index.html')
|
|
def index():
|
|
categories = os.listdir('projects/')
|
|
projects = []
|
|
for category in categories:
|
|
for project in os.listdir('projects/'+category):
|
|
# projects.append(project)
|
|
projects.append([category, project, os.listdir('projects/'+category+'/'+project)[0]])
|
|
return render_template('index.html', categories=categories, projects=projects)
|
|
|
|
@app.route('/projects')
|
|
@app.route('/projects/')
|
|
def show_projects():
|
|
categories=os.listdir('projects/')
|
|
return render_template('project_category.html', categories=categories)
|
|
|
|
@freezer.register_generator
|
|
def category_url_generator():
|
|
for category in os.listdir(os.getcwd() + '/projects/'):
|
|
if os.path.isdir(os.getcwd() + '/projects/' + category):
|
|
yield 'show_project_category', {'category':category}
|
|
|
|
@app.route('/projects/<category>.html')
|
|
def show_project_category(category):
|
|
categories=os.listdir('projects/')
|
|
projects = os.listdir('projects/' + category)
|
|
#print projects
|
|
if category in categories:
|
|
return render_template('project_category.html', category=category, projects=projects)
|
|
else:
|
|
return "Error, category not found!"
|
|
|
|
@freezer.register_generator
|
|
def project_url_generator():
|
|
for category in os.listdir(os.getcwd() + '/projects/'):
|
|
if os.path.isdir(os.getcwd() + '/projects/' + category):
|
|
for i in os.listdir(os.getcwd() + '/projects/' + category):
|
|
if os.path.isdir(os.getcwd() + '/projects/' + category + '/' + i):
|
|
#yield ('show_project', {'category': category, 'project_name': i})
|
|
yield ('show_project', {'category':category, 'project_name':i})
|
|
|
|
@app.route('/projects/<category>/<project_name>.html')
|
|
def show_project(category, project_name):
|
|
categories=os.listdir('projects')
|
|
projects = os.listdir('projects/' + category)
|
|
photo_dir = "projects/" + category + '/' + project_name
|
|
photos = os.listdir(photo_dir)
|
|
if project_name in projects:
|
|
return render_template('project.html', category=category, project_name=project_name, photos=photos, photo_dir=photo_dir)
|
|
else:
|
|
return "Error, project not found!"
|
|
|
|
@freezer.register_generator
|
|
def photo_url_generator():
|
|
projects_dir = os.getcwd() + '/projects/'
|
|
for category in os.listdir(projects_dir):
|
|
category_dir = projects_dir + category
|
|
if os.path.isdir(category_dir):
|
|
for i in os.listdir(category_dir):
|
|
project_dir = category_dir + '/' + i
|
|
if os.path.isdir(project_dir):
|
|
for photo in os.listdir(project_dir):
|
|
yield ('show_project_file', {'category':category, 'project_name':i, 'filename':photo})
|
|
|
|
|
|
@app.route('/projects/<category>/<project_name>/<filename>')
|
|
def show_project_file(category, project_name, filename):
|
|
return send_from_directory('projects/' + category + '/'+ project_name + '/', filename)
|
|
|
|
@app.route('/about-us')
|
|
def about():
|
|
return render_template('aboutus.html', title="About Us - JPs Contracting")
|
|
|
|
@app.route('/what-we-do')
|
|
def whatwedo():
|
|
return render_template('whatwedo.html', title="What We Do - JPs Contracting")
|
|
|
|
@app.route('/portfolio')
|
|
def portfolio():
|
|
categories = os.listdir('projects/')
|
|
projects = []
|
|
for category in categories:
|
|
for project in os.listdir('projects/'+category):
|
|
# projects.append(project)
|
|
projects.append([category, project, os.listdir('projects/'+category+'/'+project)[0]])
|
|
return render_template('index.html', title="JPs Contracting - Portfolio", categories=categories, projects=projects)
|
|
|
|
@app.route('/contact')
|
|
def contact():
|
|
return render_template('contactus.html', title="Contact Us - JPs Contracting")
|
|
|
|
if __name__ == '__main__':
|
|
freezer.freeze()
|