-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
99 lines (75 loc) · 2.37 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from flask import Flask, render_template, request
from waitress import serve
from flask import Flask, url_for
import random, os
app = Flask(__name__)
app.debug = False
@app.template_filter('shuffle')
def filter_shuffle(seq):
try:
result = list(seq)
random.shuffle(result)
return result
except:
return seq
@app.template_filter('capfirst')
def filter_capfirst(s):
return s[:1].upper() + s[1:]
@app.route('/')
def enter():
return render_template('onboard.html')
@app.route('/work')
def work():
path = "static/img/projects"
fname = []
for root, d_names, f_names in os.walk(path):
for f in f_names:
fname.append(os.path.join(root, f))
return render_template('work.html', work_list = fname)
@app.route('/projects/<project>')
def project(project):
path = "static/img/projects/" + project
fname = []
for root, d_names, f_names in os.walk(path):
for f in f_names:
fname.append(os.path.join(root, f))
return render_template('projects/' + project + '.html', project = project, work_list = fname)
@app.context_processor
def inject_projects():
path = "templates/projects"
projects = []
for root, d_names, f_names in os.walk(path):
for f in f_names:
# Filter for HTML files only
if f.endswith('.html'):
project_name = f.split('.')[0] # Remove the file extension
projects.append(project_name)
return dict(projects=projects)
#@app.route('/')
#@app.route('/index')
#def index():
# return render_template('index.html')
@app.context_processor
def override_url_for():
return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path, endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)
if __name__ == '__main__':
app.run(host='0.0.0.0')
#if __name__ == '__main__':
#app. run(host='0.0.0.0', port=3000)
@app.context_processor
def override_url_for():
return dict(url_for=dated_url_for)
def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path, endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)