-
Notifications
You must be signed in to change notification settings - Fork 0
/
wedding.py
219 lines (193 loc) · 7.25 KB
/
wedding.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from flask import render_template, request, url_for, redirect, Blueprint
from flask_login import current_user
from markdown import markdown
from slugify import slugify
from pyairtable.formulas import match, FIELD, FIND, STR_VALUE, OR, EQUAL
from itertools import groupby
from operator import itemgetter
from app import AT, META, dt_parse
# from utils import email_confirm
META["Path"] = None
wedding = Blueprint(
'wedding',
__name__,
template_folder = 'templates',
static_folder = 'static'
)
@wedding.route('/')
def home_redirect():
return redirect(url_for('wedding.home'))
@wedding.route('/home')
def home():
META["Path"] = request.path
return render_template('home.html', data=META)
def process_events(events):
d = []
for e in events:
e = e['fields']
e['StartTime'] = dt_parse(e['StartTime'])
e['EndTime'] = dt_parse(e['EndTime'])
e['Slug'] = slugify(e['Name'])
if "Artists" in e:
artists = []
for a in e["Artists"]:
artist = AT["vendors"].get(a)['fields']
if 'Status' in artist:
if artist['Status'] == 'Confirmed':
artists.append(artist)
artists = sorted(artists, key = itemgetter('Role'))
a_dict = {}
for role, artist in groupby(artists, key = itemgetter('Role')):
a_dict[role] = list(artist)
e['Artists'] = a_dict
d.append(e)
return groupby(d, lambda x: x['StartTime'].date())
def compose_formula(list, field):
f = []
for term in list:
f.append(FIND(STR_VALUE(term), 'ARRAYJOIN(' + FIELD(field) + ')'))
f.append(EQUAL(0, FIELD(field)))
return OR(','.join(f))
@wedding.route('/itinerary')
def itinerary():
if META["Published"]:
META['Path'] = request.path
if current_user.is_authenticated:
person = AT["people"].get(current_user.id).get("fields")
if "GroupNames" in person:
formula = compose_formula(person["GroupNames"], "LimitedInviteNames")
else:
formula = EQUAL(0, FIELD("LimitedInviteNames"))
events = AT["events"].all(formula = formula, sort = ["StartTime"])
for e in events:
e['fields']['Description'] = markdown(e['fields']['Description'])
META['events'] = process_events(events)
return render_template(
'itinerary.html',
data=META
)
else:
return redirect(url_for('auth.login'))
else:
return redirect(url_for('wedding.home'))
@wedding.route('/qa')
def qa():
if META["Published"]:
META["Path"] = request.path
d = []
for i in AT["qa"].all(fields = ['Question', 'Answer']):
d.append(i['fields'])
return render_template(
'qa.html',
meta = META,
data = d
)
else:
return redirect(url_for('wedding.home'))
@wedding.route('/travel/accommodations')
def accommodations():
if META["Published"]:
META["Path"] = request.path
acc = []
for a in AT["accommodations"].all():
a['fields']['Description'] = markdown(a['fields']['Description'])
acc.append(a['fields'])
META['acc'] = acc
return render_template('accommodations.html', data = META)
else:
return redirect(url_for('wedding.home'))
@wedding.route('/travel/getting-around/')
def getting_around():
if META["Published"]:
META["Path"] = request.path
META['GettingAround'] = markdown(
AT['meta'].first(fields=['GettingAround'])['fields']['GettingAround']
)
return render_template('getting-around.html', data=META)
else:
return redirect(url_for('wedding.home'))
@wedding.route('/travel/things-to-do/')
def things_to_do():
if META["Published"]:
META["Path"] = request.path
return render_template('travel.html', data=META)
else:
return redirect(url_for('wedding.home'))
@wedding.route('/colophon')
def colophon():
if META["Published"]:
META["Path"] = request.path
META['Colophon'] = markdown(
AT['meta'].first(fields=['Colophon'])['fields']['Colophon']
)
return render_template('colophon.html', data=META)
else:
return redirect(url_for('wedding.home'))
def check_none(field, values, values_dict, none_val = None):
field_lc = field.lower()
field_id = "_".join([field_lc, "id"])
values_dict[field_id] = "_".join([field_lc, values_dict["id"]])
if field not in values:
values_dict[field] = none_val
else:
values_dict[field] = values[field]
return values_dict
def check_form(field, values, request):
field_lc = field.lower()
field_id = "_".join([field_lc, "id"])
if field_id in values:
if values[field_id] in request.form:
if request.form[values[field_id]] == "None":
values[field] = None
else:
values[field] = request.form[values[field_id]]
return values
@wedding.route('/rsvp', methods = ['GET', 'POST'])
def rsvp():
if META["Published"]:
META['Path'] = request.path
e = None
a = []
attending = False
if not current_user.is_authenticated:
return redirect(url_for('auth.login'))
else:
party_id = AT["people"].get(current_user.id)["fields"]["Party"][0]
people = []
party = AT["parties"].get(party_id)["fields"]
for p in party['People']:
values = {}
person = AT["people"].get(p)
values["id"] = person["id"]
person = person["fields"]
text_fields = ["Name", "AnythingElse"]
choice_fields = ["WeddingRSVP", "WelcomeRSVP", "BagelsRSVP", "Email", "Meal"]
for field in text_fields:
values = check_none(field, person, values, none_val = "")
for field in choice_fields:
values = check_none(field, person, values)
if request.method == 'POST':
for field in text_fields + choice_fields:
values = check_form(field, values, request)
AT["people"].update(values["id"], {
"Name": values["Name"],
"WeddingRSVP": values["WeddingRSVP"],
"WelcomeRSVP": values["WelcomeRSVP"],
"BagelsRSVP": values["BagelsRSVP"],
"Email": values["Email"],
"Meal": values["Meal"],
"AnythingElse": values["AnythingElse"]
})
AT["parties"].update(party_id, {
"Reply": True
})
people.append(values)
if values["WeddingRSVP"] == "Yes":
a.append(True)
else:
a.append(False)
if(any(a)):
attending = True
return render_template('rsvp.html', party = party, people = people, attending = attending, error = e, meta=META)
else:
return redirect(url_for('wedding.home'))