-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
234 lines (193 loc) · 8.19 KB
/
main.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import webapp2
import logging
import jinja2
import os
import datetime
import json
from google.appengine.ext import ndb
from google.appengine.api import users
#Step 2: Set up Jinja environment
jinja_env = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
)
# MODELS
def joinEfxn():
print "Hello"
class Profile(ndb.Model):
name = ndb.StringProperty(required=True)
email = ndb.StringProperty(required=True)
classYear = ndb.StringProperty(required= True)
class Event(ndb.Model):
activity = ndb.StringProperty(required = True)
location = ndb.StringProperty(required = True)
timeDate = ndb.DateTimeProperty(required = True)
creator = ndb.StringProperty(required = True)
attendees = ndb.KeyProperty(kind = Profile, repeated = True)
class School(ndb.Model):
name = ndb.StringProperty(required = True)
facility = ndb.StringProperty(required = True)
# HANDLERS
class AboutPage(webapp2.RequestHandler):
def get(self):
template_vars = {
'logout_link' : users.create_logout_url(users.create_login_url('/'))
}
template = jinja_env.get_template("templates/about.html")
self.response.write(template.render(template_vars))
def post(self):
template_vars = {
'logout_link' : users.create_logout_url(users.create_login_url('/'))
}
template = jinja_env.get_template("templates/about.html")
self.response.write(template.render(template_vars))
class CreateAccount(webapp2.RequestHandler):
def get(self): #for a get request
template_vars = {
'logout_link' : users.create_logout_url(users.create_login_url('/'))
}
#Step 3: Use the Jinja environment to get our HTML
template = jinja_env.get_template("templates/createAccount.html")
self.response.write(template.render(template_vars))
def post(self):
#self.req.get lets us get data input
#however we get user input from post rather than url query
Name = self.request.get("Name")
Email = self.request.get("Email")
classYear = self.request.get("classYear")
Profile(
name = Name,
email = users.get_current_user().email(),
classYear = classYear,
).put()
self.redirect("/main", True)
class Main(webapp2.RequestHandler):
def get(self):
#filter for each attribute
event_query_list = Event.query().order(Event.timeDate).fetch()
#Step 3: Use the Jinja environment to get our HTML
template_vars = {
'logout_link' : users.create_logout_url('/'),
'events': event_query_list
}
template = jinja_env.get_template("templates/main.html")
self.response.write(template.render(template_vars))
def post(self):
#accessing current users name
email_address = users.get_current_user().email()
profile_match_model = Profile.query().filter(Profile.email == email_address).get()
eventkey = self.request.get('eventkey')
event = ndb.Key(urlsafe=eventkey).get()
bool_match = False
for attendee in event.attendees:
if (attendee == profile_match_model.key):
print "HEY"
bool_match = True
break
if bool_match:
self.redirect("/main",True)
else:
print "AAYY"
event.attendees.append(profile_match_model.key)
event.put()
self.redirect("/main",True)
class CreateNewEventPage(webapp2.RequestHandler):
def get(self):
template_vars = {
'logout_link' : users.create_logout_url('/'),
}
template = jinja_env.get_template("templates/createEvent.html")
self.response.write(template.render(template_vars))
def post(self):
activity = self.request.get("activity")
location = self.request.get("location")
meetingtime = self.request.get("meetingtime")
#getting email address of logged in user
email_address = users.get_current_user().email()
#getting the right datastore Profile model to match with that email
email_match_value = Profile.query().filter(Profile.email == email_address).get()
temp_tim_obj = datetime.datetime.strptime(meetingtime,"%Y-%m-%dT%H:%M")
Event(
activity = activity,
location = location,
#parse meetingtime input string and convert top python datetime obj
timeDate = temp_tim_obj,
#extracting the name attribute from the right profile and
#assigning it to the creator attribute of the model
creator = email_match_value.name,
attendees = [email_match_value.key]
).put()
self.redirect("/main",True)
template_vars = {
'logout_link' : users.create_logout_url('/'),
}
template = jinja_env.get_template("templates/main.html")
self.response.write(template.render(template_vars))
class JoinEventPage(webapp2.RequestHandler):
'''
So, whenever someone clicks the join button, we want to update the number
of people in the event party by 1.
Additionally, we want to also list the user's name (ex. John Doe) in the list
of people attendeeng.
Finally, once the user has joined an event, we want to send an alert to show
that they successfuly joined a certain event
'''
def get(self):
# passing in event clicked variable which holds event specific id and assigninging it variable in python
event_specific_key = self.request.get("eventclicked")
# going through id's in datastore and matching it with the id we're looking for, then storing that event in event list
event = ndb.Key(urlsafe=event_specific_key).get()
template_vars = {
"event" : event,
'logout_link' : users.create_logout_url(users.create_login_url('/'))
}
template = jinja_env.get_template("templates/joinEvent.html")
self.response.write(template.render(template_vars))
def post(self):
template_vars = {
'logout_link' : users.create_logout_url(users.create_login_url('/'))
}
template = jinja_env.get_template("templates/joinEvent.html")
self.response.write(template.render(template_vars))
#def post(self):
# event_specific_id = self.request.get("eventclicked")
# # going through id's in datastore and matching it with the id we're looking for, then storing that event in event list
# event_list = Event.query().filter(Event.id == event_specific_id).fetch()
# event_list[0].attendees = event_list[0].attendees + 1
class SignIn_Transition(webapp2.RequestHandler):
def get(self):
"""
If email is in dataStore continue to Main Page w list of joinEvent
creating a list that stores all the emails in dataStore.
user.email() represents the email of the user that just logged in according to
API docs.
User.email() represents the email attributes
assoicated with User models in dataStore.
"""
user = users.get_current_user()
signin_link = users.create_login_url('/')
email_address = user.email()
email_match_value = Profile.query().filter(Profile.email == email_address).get()
#creating an if statement that checks if the email used to \\
#login is already in datastore
if email_match_value:
self.redirect("/main", True)
#created a sign out link
#the structure of the main page
#redirect user to make account page
#where the create a user model with their email and extra info
else:
self.redirect("/createaccount", True)
class GCalendar(webapp2.RequestHandler):
def get(self):
template = jinja_env.get_template("templates/gCalendar.html")
self.response.write(template.render())
# the app configuration section
app = webapp2.WSGIApplication([
('/createaccount', CreateAccount),
('/', SignIn_Transition), #this maps the root url to the Main Page Handler
('/main', Main),
('/joinEvent', JoinEventPage),
('/about', AboutPage),
('/createEvent', CreateNewEventPage),
('/calendar', GCalendar),
], debug=True)