jpscontracting/run_site.py

140 lines
5.0 KiB
Python
Raw Permalink Normal View History

from flask import Flask, render_template, send_from_directory
2017-06-01 17:55:06 +00:00
from flask_frozen import Freezer
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
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():
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('new_index.html', categories=categories)
### This is for JPs new request of wide portfolio categories
@app.route('/old_index')
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]])
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)
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):
yield 'show_project_category', {'category': category}
2017-06-06 03:28:33 +00:00
@app.route('/projects/<category>.html')
def show_project_category(category):
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-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):
# 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')
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!"
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):
yield ('show_project_file', {'category': category, 'project_name': i, 'filename': photo})
2017-06-06 03:28:33 +00:00
@app.route('/projects/<category>/<project_name>/<filename>')
def show_project_file(category, project_name, filename):
return send_from_directory('projects/' + category + '/' + project_name + '/', filename)
@freezer.register_generator
def category_photo_url_generator():
categories = os.getcwd() + '/images/categories/'
for category in os.listdir(categories):
category = category
yield ('show_category_banner', {'filename': category})
@app.route('/category/<path:filename>')
def show_category_banner(filename):
return send_from_directory('images/categories/', filename)
2017-01-12 13:06:39 +00:00
@app.route('/about-us')
2017-01-25 23:07:07 +00:00
def about():
return render_template('aboutus.html', title="About Us - JPs Contracting")
2017-01-25 23:07:07 +00:00
@app.route('/what-we-do')
def whatwedo():
return render_template('whatwedo.html', title="What We Do - JPs Contracting")
@app.route('/portfolio')
2017-01-25 23:07:07 +00:00
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)
2017-01-25 23:07:07 +00:00
2017-01-25 23:07:07 +00:00
@app.route('/contact')
def contact():
return render_template('contactus.html', title="Contact Us - JPs Contracting")
2017-06-01 17:55:06 +00:00
if __name__ == '__main__':
freezer.freeze()