Updated chain for Freezing Flask!

This commit is contained in:
Alexander Hosking 2017-06-05 23:28:33 -04:00
parent 4b59780b41
commit a92de4b93a
2 changed files with 43 additions and 5 deletions

View File

@ -6,3 +6,10 @@ source env/bin/activate
export FLASK_APP=run_site.py export FLASK_APP=run_site.py
export FLASK_DEBUG=1 export FLASK_DEBUG=1
flask run --host=0.0.0.0 flask run --host=0.0.0.0
`
## Building the static site
`
source env/bin/activate
python run_site.py
`

View File

@ -5,8 +5,11 @@ import os
app = Flask(__name__) app = Flask(__name__)
freezer = Freezer(app) freezer = Freezer(app)
app.config['FREEZER_RELATIVE_URLS'] = True
app.config['FREEZER_IGNORE_MIMETYPE_WARNINGS'] = True
@app.route('/') @app.route('/')
@app.route('/index') @app.route('/index.html')
def index(): def index():
categories = os.listdir('projects/') categories = os.listdir('projects/')
projects = [] projects = []
@ -22,17 +25,32 @@ def show_projects():
categories=os.listdir('projects/') categories=os.listdir('projects/')
return render_template('project_category.html', categories=categories) return render_template('project_category.html', categories=categories)
@app.route('/projects/<category>') @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): def show_project_category(category):
categories=os.listdir('projects/') categories=os.listdir('projects/')
projects = os.listdir('projects/' + category) projects = os.listdir('projects/' + category)
print projects #print projects
if category in categories: if category in categories:
return render_template('project_category.html', category=category, projects=projects) return render_template('project_category.html', category=category, projects=projects)
else: else:
return "Error, category not found!" return "Error, category not found!"
@app.route('/projects/<category>/<project_name>') @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): def show_project(category, project_name):
categories=os.listdir('projects') categories=os.listdir('projects')
projects = os.listdir('projects/' + category) projects = os.listdir('projects/' + category)
@ -43,11 +61,24 @@ def show_project(category, project_name):
else: else:
return "Error, project not found!" 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>') @app.route('/projects/<category>/<project_name>/<filename>')
def show_project_file(category, project_name, filename): def show_project_file(category, project_name, filename):
return send_from_directory('projects/' + category + '/'+ project_name + '/', filename) return send_from_directory('projects/' + category + '/'+ project_name + '/', filename)
@app.route('/about') @app.route('/about.html')
def about(): def about():
return render_template('aboutus.html', title="About Us - JPs Contracting") return render_template('aboutus.html', title="About Us - JPs Contracting")