-
Notifications
You must be signed in to change notification settings - Fork 0
/
Views.py
114 lines (94 loc) · 3.34 KB
/
Views.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
import webapp2
import os
import urllib
from google.appengine.ext.webapp import template
from Event import Event
from AppUser import AppUser
from EventInteractions import getString
from EventInteractions import getDate
from EventInteractions import getDateTime
from EventInteractions import getInt
from google.appengine.ext import db
from google.appengine.api import users
class ViewUser(webapp2.RequestHandler):
def get(self):
userKey=self.request.path[6:] #Chops off the end of the request path to get the user key
user=AppUser.get_by_key_name(userKey)
if not user:
self.redirect('/?' + urllib.urlencode({'message':'Error: No such user found.'}))
currentUser = AppUser.getUser()
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'url': url,
'url_linktext': url_linktext,
'user': user,
'events': [],
'currentUser':currentUser
}
#Displays:
#Username (nickname)
#Good/bad event counts
#Verified status
#Events (later)
path = os.path.join(os.path.dirname(__file__), './templates/UserProfile.html')
self.response.out.write(template.render(path, template_values))
class ViewEvent(webapp2.RequestHandler):
def get(self):
eventKey=self.request.path[7:] #Chops off the end of the request path to get the event key
event=Event.get(eventKey)
currentUser = AppUser.getUser()
#if ((not event) or (not event.verified and not currentUser.verified)):
# self.redirect('/?' + urllib.urlencode({'message':'Error: Event not found or could not be accessed.'}))
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
'url': url,
'url_linktext': url_linktext,
'event' : event,
'currentUser' : currentUser
}
path=os.path.join(os.path.dirname(__file__), './templates/viewEvent.html')
self.response.out.write(template.render(path, template_values))
class ViewMake(webapp2.RequestHandler):
def get(self):
user=AppUser.getUser()
if users.get_current_user():
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login'
template_values = {
"user":user,
'url':url,
'url_linktext':url_linktext
}
path = os.path.join(os.path.dirname(__file__), './templates/MakeEvent.html')
self.response.out.write(template.render(path, template_values))
def post(self):
user = AppUser.getUser()
eventName=getString("name", self)
loc=getString("location", self)
date = getDate("date", self)
start=getDateTime("start",date, self)
event = Event(creator=user,name=eventName, location=loc, dateStart=start)
event.dateEnd=getDateTime("end",date, self)
event.description=getString("description", self)
event.host=getString("host", self)
event.attending=0
event.put()
if user.verified:
event.verify();
# Auto-verified if the user is, and thanks the user.
self.redirect('/?' + urllib.urlencode({'message':'''Thanks, yum!'''}))
self.redirect('/?' + urllib.urlencode({'message':'''Event Created! You'll need to wait for someone to verify it.'''}))
# redirect message if the user isn't verified.