-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
162 lines (131 loc) · 4.02 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from flask import Flask, render_template, url_for, g, request
import extensions
import controllers
import config
import os
import sys
#TODO:
# get rid of or fix js image optomization (cookies)
# animation reminder for logo (bounce click me)
# animation for logo when hard scroll to top
# change bg image every page reload until cookie is set
# change logo color
# new decsriptions for each media piece in project view
# sortBy button
# resume icons are cut off
# padding for html pv
# cleanup other bad code
# minifyer (css, js, combines into one file to save http req?)
# profile js, flask
app = Flask(__name__, template_folder='templates', static_folder='static')
# Register the controllers
app.register_blueprint(controllers.contact)
app.register_blueprint(controllers.main)
app.register_blueprint(controllers.portfolio)
app.register_blueprint(controllers.resume)
app.register_blueprint(controllers.view)
# Key for sessions (very secure)
app.secret_key = 'Barnburner Lullaby'
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
@app.template_global()
# TODO: cleanup, super hacky
# adds and removes tags for limiting portfolio projects
def addGETTag(newtag):
delim = ':'
args = request.args.copy()
if 'tags' not in args:
args['tags'] = newtag
elif newtag not in args['tags'].split(delim):
args['tags'] = args['tags'] + delim + newtag
else: # remove tag
if len(args['tags'].split(delim)) == 1:
return url_for('portfolio.main_route')
else:
rep = delim + newtag
if args['tags'].split(delim)[0] == newtag:
rep = newtag + delim
args['tags'] = args['tags'].replace(rep, '')
return url_for('portfolio.main_route', **args)
@app.template_global()
def getExt(filename):
filename, ext = os.path.splitext(filename)
return ext
@app.template_global()
def rawME(filename):
with open(filename, 'r') as f:
return f.read()
@app.before_request
def getCurrent():
global hImgs
global PAGES
hImgs = [
{
'active': 'active',
'src': url_for('static', filename='media/bg/00_large.jpg'),
'alt': 'Cloud Steps by Maverick Cook'
},
{
'active': '',
'src': url_for('static', filename='media/bg/01_large.jpg'),
'alt': 'Mushrooms by Maverick Cook'
},
{
'active': '',
'src': url_for('static', filename='media/bg/02_large.jpg'),
'alt': 'Macro Guitar Strings by Maverick Cook'
},
{
'active': '',
'src': url_for('static', filename='media/bg/03_large.jpg'),
'alt': 'Traverse City Stars by Maverick Cook'
},
{
'active': '',
'src': url_for('static', filename='media/bg/04_large.jpg'),
'alt': 'Macro Tree Stump by Maverick Cook'
}
]
PAGES = {
'index': ('Home', url_for('main.main_route')),
'pf': ('Portfolio', url_for('portfolio.main_route')),
'res': ('Resume', url_for('resume.main_route')),
'contact': ('Contact', url_for('contact.main_route')),
'faq': ('FAQ', url_for('main.faq_route')),
'jy': ('The Junkyard', url_for('main.junkyard_route'))
}
if 'hImg' not in request.cookies:
hImgs[0]['active'] = 'active'
else:
for i in range(len(hImgs)):
if 'i' + str(i) == request.cookies['hImg']:
hImgs[i]['active'] = 'active'
else:
hImgs[i]['active'] = ''
g.hImgs = hImgs
# Globals needed for base.html
@app.context_processor
def inject_user():
navPages = [
PAGES['index'],
PAGES['pf'],
PAGES['res'],
PAGES['contact']
]
evenMore = [
PAGES['faq'],
PAGES['jy']
]
URLS = {
'logo': url_for('static', filename='media/metram_logo_solid_highres.png'),
'logoWM' : url_for('static', filename='media/metram_watermark_solid_highres.png'),
'favicon': url_for('static', filename='media/favicon.png'),
}
return dict(navPages=navPages, evenMore=evenMore, URLS=URLS)
# Listen on external IPs
if __name__ == '__main__':
if len(sys.argv) > 1: # only arguments will be pased to development
app.run(host=config.webEnv['host'], port=config.webEnv['port'], debug=True)
else:
app.run()