2017-02-06 22:34:21 +00:00
|
|
|
from flask import Flask, render_template, send_from_directory
|
2017-06-01 17:55:06 +00:00
|
|
|
from flask_frozen import Freezer
|
2017-02-06 22:34:21 +00:00
|
|
|
import os
|
2017-01-12 13:06:39 +00:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2017-06-01 17:55:06 +00:00
|
|
|
freezer = Freezer(app)
|
2017-01-12 13:06:39 +00:00
|
|
|
|
2017-06-06 03:28:33 +00:00
|
|
|
app.config['FREEZER_RELATIVE_URLS'] = True
|
|
|
|
app.config['FREEZER_IGNORE_MIMETYPE_WARNINGS'] = True
|
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2017-01-12 13:06:39 +00:00
|
|
|
@app.route('/')
|
2018-11-22 04:01:10 +00:00
|
|
|
@app.route('/index.html')
|
2017-01-12 13:06:39 +00:00
|
|
|
def index():
|
2017-02-06 22:34:21 +00:00
|
|
|
categories = os.listdir('projects/')
|
|
|
|
projects = []
|
|
|
|
for category in categories:
|
2018-12-31 06:28:24 +00:00
|
|
|
for project in os.listdir('projects/'+category):
|
|
|
|
# projects.append(project)
|
|
|
|
projects.append([category, project, os.listdir(
|
|
|
|
'projects/'+category+'/'+project)[0]])
|
2018-12-31 06:35:14 +00:00
|
|
|
return render_template('new_index.html', categories=categories)
|
2017-02-06 22:34:21 +00:00
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
### This is for JPs new request of wide portfolio categories
|
2018-12-31 06:35:14 +00:00
|
|
|
@app.route('/old_index')
|
2018-12-31 06:28:24 +00:00
|
|
|
def new_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]])
|
2018-12-31 06:35:14 +00:00
|
|
|
return render_template('index.html', categories=categories, projects=projects)
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2017-02-06 22:34:21 +00:00
|
|
|
@app.route('/projects')
|
|
|
|
@app.route('/projects/')
|
|
|
|
def show_projects():
|
2018-12-31 06:28:24 +00:00
|
|
|
categories = os.listdir('projects/')
|
|
|
|
return render_template('project_category.html', categories=categories)
|
|
|
|
|
2017-02-06 22:34:21 +00:00
|
|
|
|
2017-06-06 03:28:33 +00:00
|
|
|
@freezer.register_generator
|
|
|
|
def category_url_generator():
|
|
|
|
for category in os.listdir(os.getcwd() + '/projects/'):
|
|
|
|
if os.path.isdir(os.getcwd() + '/projects/' + category):
|
2018-12-31 06:28:24 +00:00
|
|
|
yield 'show_project_category', {'category': category}
|
|
|
|
|
2017-06-06 03:28:33 +00:00
|
|
|
|
|
|
|
@app.route('/projects/<category>.html')
|
2017-02-06 22:34:21 +00:00
|
|
|
def show_project_category(category):
|
2018-12-31 06:28:24 +00:00
|
|
|
projects = []
|
|
|
|
for project in os.listdir('projects/'+category):
|
|
|
|
projects.append([category, project, os.listdir(
|
|
|
|
'projects/'+category+'/'+project)[0]])
|
|
|
|
if category:
|
|
|
|
return render_template('project_category.html', category=category, projects=projects)
|
|
|
|
else:
|
|
|
|
return "Error, category not found!"
|
|
|
|
|
2017-02-06 22:34:21 +00:00
|
|
|
|
2017-06-06 03:28:33 +00:00
|
|
|
@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):
|
2018-12-31 06:28:24 +00:00
|
|
|
# yield ('show_project', {'category': category, 'project_name': i})
|
|
|
|
yield ('show_project', {'category': category, 'project_name': i})
|
2017-06-06 03:28:33 +00:00
|
|
|
|
|
|
|
@app.route('/projects/<category>/<project_name>.html')
|
2017-02-06 22:34:21 +00:00
|
|
|
def show_project(category, project_name):
|
2018-12-31 06:28:24 +00:00
|
|
|
# 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!"
|
2017-02-06 22:34:21 +00:00
|
|
|
|
2017-06-06 03:28:33 +00:00
|
|
|
@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):
|
2018-12-31 06:28:24 +00:00
|
|
|
yield ('show_project_file', {'category': category, 'project_name': i, 'filename': photo})
|
2017-06-06 03:28:33 +00:00
|
|
|
|
|
|
|
|
2017-02-06 22:34:21 +00:00
|
|
|
@app.route('/projects/<category>/<project_name>/<filename>')
|
|
|
|
def show_project_file(category, project_name, filename):
|
2018-12-31 06:28:24 +00:00
|
|
|
return send_from_directory('projects/' + category + '/' + project_name + '/', filename)
|
|
|
|
|
|
|
|
@freezer.register_generator
|
|
|
|
def category_photo_url_generator():
|
|
|
|
categories = os.getcwd() + '/images/categories/'
|
2018-12-31 06:57:08 +00:00
|
|
|
for category in os.listdir(categories):
|
2018-12-31 07:05:32 +00:00
|
|
|
category = category
|
2018-12-31 06:28:24 +00:00
|
|
|
yield ('show_category_banner', {'filename': category})
|
|
|
|
|
2018-12-31 06:57:08 +00:00
|
|
|
@app.route('/category/<path:filename>')
|
2018-12-31 06:28:24 +00:00
|
|
|
def show_category_banner(filename):
|
|
|
|
return send_from_directory('images/categories/', filename)
|
|
|
|
|
2017-01-12 13:06:39 +00:00
|
|
|
|
2018-11-22 03:56:58 +00:00
|
|
|
@app.route('/about-us')
|
2017-01-25 23:07:07 +00:00
|
|
|
def about():
|
2017-02-08 13:51:28 +00:00
|
|
|
return render_template('aboutus.html', title="About Us - JPs Contracting")
|
2017-01-25 23:07:07 +00:00
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2018-11-20 06:30:20 +00:00
|
|
|
@app.route('/what-we-do')
|
|
|
|
def whatwedo():
|
|
|
|
return render_template('whatwedo.html', title="What We Do - JPs Contracting")
|
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2017-02-07 14:22:47 +00:00
|
|
|
@app.route('/portfolio')
|
2017-01-25 23:07:07 +00:00
|
|
|
def portfolio():
|
2017-02-07 14:22:47 +00:00
|
|
|
categories = os.listdir('projects/')
|
|
|
|
projects = []
|
|
|
|
for category in categories:
|
2018-12-31 06:28:24 +00:00
|
|
|
for project in os.listdir('projects/'+category):
|
|
|
|
# projects.append(project)
|
|
|
|
projects.append([category, project, os.listdir(
|
|
|
|
'projects/'+category+'/'+project)[0]])
|
2017-02-07 14:22:47 +00:00
|
|
|
return render_template('index.html', title="JPs Contracting - Portfolio", categories=categories, projects=projects)
|
2017-01-25 23:07:07 +00:00
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2017-01-25 23:07:07 +00:00
|
|
|
@app.route('/contact')
|
|
|
|
def contact():
|
2017-02-07 14:22:47 +00:00
|
|
|
return render_template('contactus.html', title="Contact Us - JPs Contracting")
|
2017-02-06 22:34:21 +00:00
|
|
|
|
2018-12-31 06:28:24 +00:00
|
|
|
|
2017-06-01 17:55:06 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
freezer.freeze()
|