-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin_community_page.py
74 lines (65 loc) · 2.49 KB
/
join_community_page.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
from base_handler import *
import cgi
import MySQLdb
from google.appengine.api import users
import os
class JoinCommunityPage(BaseHandler):
def get(self):
user = users.get_current_user()
if not user:
self.redirect('/')
else:
email = user.email()
if (os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
db = MySQLdb.connect(unix_socket='/cloudsql/hack-the-north-1:its-not-django', db='musicsite', user='root')
else:
db = MySQLdb.connect(host='localhost', user='root', passwd="htndjango",db="musicsite")
cursor = db.cursor()
result = cursor.execute('SELECT community_name,community_id FROM users WHERE email = "%s" AND invite_accepted = 0 AND invite_hidden=0;' % email)
count = cursor.rowcount
if (count == 0):
template_messages={
"message": "You have no pending invites!"
}
else:
#known bug where if you have two pending invites of the same name, accepting will cause you to accept both
pendinglist = []
for row in cursor:
pendinglist.append(row[0])
template_messages={
"message": "You have %s pending invite(s)!" % count,
"invites": pendinglist
}
db.close()
self.render_response('join_community_page.html', **template_messages)
def post(self):
community = cgi.escape(self.request.get('community'))
user = users.get_current_user()
if not user:
self.redirect('/')
else:
email = user.email()
if (os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
db = MySQLdb.connect(unix_socket='/cloudsql/hack-the-north-1:its-not-django', db='musicsite', user='root')
else:
db = MySQLdb.connect(host='localhost', user='root', passwd="htndjango",db="musicsite")
cursor = db.cursor()
result = cursor.execute('UPDATE users SET invite_accepted=1 WHERE email="%s" AND community_name="%s";' % (email,community))
db.commit()
result = cursor.execute('SELECT community_name,community_id FROM users WHERE email = "%s" AND invite_accepted = 0 AND invite_hidden=0;' % email)
count = cursor.rowcount
if (count == 0):
template_messages={
"message": "%s has been joined successfully! You have no pending invites!" % community
}
else:
pendinglist = []
for row in cursor:
pendinglist.append(row[0])
invitelist = ""
template_messages={
"message": "%s has been joined successfully! You have %s pending invite(s)!" % (community,count),
"invites": pendinglist
}
db.close()
self.render_response('join_community_page.html', **template_messages)