forked from Techtonica/techtonica.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_site.py
201 lines (156 loc) · 4.52 KB
/
main_site.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
"""
This is the main Python file that sets up rendering and templating
for Techtonica.org
"""
import os
import sys
import pendulum
from dotenv import find_dotenv, load_dotenv
from eventbrite import Eventbrite
from flask import Flask, redirect, render_template, url_for
from flask_sslify import SSLify
load_dotenv(find_dotenv(usecwd=True))
# Gracefully handle running locally without eventbrite token
try:
eventbrite = Eventbrite(os.environ["EVENTBRITE_OAUTH_TOKEN"])
except:
print("Not able to authenticate to EventBrite")
app = Flask(__name__)
sslify = SSLify(app)
# MAIN HANDLERS
@app.route("/")
def render_home_page():
"""
Renders the home page from jinja2 template
"""
events = get_events()
return render_template("home.html", events=events)
@app.route("/team/")
def render_team_page():
"""
Renders the team page from jinja2 template
"""
return render_template("team.html")
@app.route("/careers/")
def render_careers_page():
"""
Renders the careers page from jinja2 template
"""
return redirect(url_for("render_openings_page"))
@app.route("/conduct/")
def render_conduct_page():
"""
Renders the conduct page from jinja2 template
"""
return render_template("conduct.html")
@app.route("/privacy/")
def render_privacy_page():
"""
Renders the privacy page from jinja2 template
"""
return render_template("privacy.html")
@app.route("/thankyou/")
def render_thankyou_page():
"""
Renders the newsletter signup's thank you page from jinja2 template.
"""
return render_template("thankyou.html")
@app.route("/sponsor/")
def render_sponsor_page():
"""
Renders the sponsor page from jinja2 template
"""
return render_template("sponsor.html")
@app.route("/faqs/")
def render_faqs_page():
"""
Renders the FAQs page from jinja2 template
"""
return render_template("faqs.html")
@app.route("/openings/")
def render_openings_page():
"""
Renders the openings page from jinja2 template
"""
return render_template("openings.html")
"""
@app.route("/openings/seam/")
def render_seam_page():
Renders the openings page from jinja2 template
return render_template("seam.html")
"""
@app.route("/openings/curriculumdev/")
def render_curriculumdev_page():
"""
Renders the openings page from jinja2 template
"""
return render_template("curriculumdev.html")
@app.route("/openings/board/")
def render_board_page():
"""
Renders the openings page from jinja2 template
"""
return render_template("board.html")
@app.route("/mentor/")
def render_mentor_page():
"""
Renders the mentor page from jinja2 template
"""
return render_template("mentor.html")
@app.route("/apprenticeship/")
def render_apprenticeship_page():
"""
Renders the apprenticeship page from jinja2 template
"""
return render_template("apprenticeship.html")
@app.route("/donate/")
def render_donate_page():
"""
Renders the donate page from jinja2 template
"""
return render_template("donate.html")
@app.route("/volunteer/")
def render_volunteer_page():
"""
Renders the volunteer page from jinja2 template
"""
return render_template("volunteer.html")
@app.route("/news/")
def render_news_page():
"""
Renders the news page from jinja2 template
"""
return render_template("news.html")
def get_events():
try:
group_id = eventbrite.get_user()["id"]
response = eventbrite.get(
f"/organizations/{group_id}/events/",
data={"status": "live", "order_by": "start_asc", "page_size": 4},
expand=("venue",),
)
events = [Event(event) for event in response["events"]]
return events
except NameError:
# Gracefully handle failures getting events from EventBrite
print("Not returning EventBrite Events:", sys.exc_info()[1])
return []
class Event(object):
def __init__(self, event):
self.title = event["name"]["text"]
self.url = event["url"]
self.venue = None
self.address = None
self.date = (
pendulum.parse(event["start"]["local"])
.set(tz=event["start"]["timezone"])
.format("MMMM D, YYYY, h:mmA zz")
)
if event["venue"]:
self.venue = event["venue"]["name"]
self.address = event["venue"]["address"][
"localized_multi_line_address_display"
]
if __name__ == "__main__":
app.debug = False
# app.run(host='0.0.0.0', port=9999)