-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_community_page.py
102 lines (92 loc) · 4.47 KB
/
single_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
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
import os
from base_handler import *
from google.appengine.api import users
import MySQLdb
import cgi
class SingleCommunityPage(BaseHandler):
def get(self, community):
user = users.get_current_user()
if user:
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()
cursor.execute('SELECT * FROM users WHERE email = "%s" AND invite_accepted=1 AND community_id=%s'%(email,community))
if (cursor.rowcount == 0):
self.redirect('/communities')
else:
cursor.execute('SELECT name FROM communities WHERE id = %s'%community)
community_name = ""
for row in cursor:
community_name = row[0]
html_string=""
cursor.execute('SELECT id, album_name, album_artist FROM albums WHERE community_id = %s' % community)
for row in cursor:
album_name = row[1]
album_artist = row[2]
album_id = row[0]
album_string = """<div class="album">
<a href="/albums/%s">
<img class="album_art" src="http://placekitten.com/g/250/250" alt="%s">
</a>
<p><b>%s</b><br />%s</p>
</div>""" % (album_id, album_name, album_name, album_artist)
html_string = html_string + album_string
template_messages={
"community_id":community,
"community_name":community_name
}
self.render_response('community_albums.html', **template_messages)
self.response.write(html_string)
self.response.write('</div></div></body></html>')
else:
self.redirect('/communities')
def post(self, community):
#used to process post requests from /addalbums
user = users.get_current_user()
if user:
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()
cursor.execute('SELECT * FROM users WHERE email = "%s" AND invite_accepted=1 AND community_id=%s'%(email,community))
if (cursor.rowcount == 0):
self.redirect('/communities')
else:
album_name = cgi.escape(self.request.get('album_name'))
album_year = cgi.escape(self.request.get('album_year'))
album_genre = cgi.escape(self.request.get('album_genre'))
album_artist = cgi.escape(self.request.get('album_artist'))
posted_by = cgi.escape(self.request.get('posted_by'))
cursor.execute('INSERT INTO albums (album_name,album_year,album_genre,album_artist,posted_by,addition_date,community_id) VALUES ("%s",%s,"%s","%s","%s",NOW(),%s);' % (album_name,album_year,album_genre,album_artist,posted_by,community))
db.commit()
cursor.execute('SELECT name FROM communities WHERE id = %s'%community)
community_name = ""
for row in cursor:
community_name = row[0]
html_string=""
cursor.execute('SELECT id, album_name, album_artist FROM albums WHERE community_id = %s' % community)
for row in cursor:
album_name = row[1]
album_artist = row[2]
album_id = row[0]
album_string = """<div class="album">
<a href="/albums/%s">
<img class="album_art" src="http://placekitten.com/g/250/250" alt="%s">
</a>
<p><b>%s</b><br />%s</p>
</div>""" % (album_id, album_name, album_name, album_artist)
html_string = html_string + album_string
template_messages={
"community_id":community,
"community_name":community_name
}
self.render_response('community_albums.html', **template_messages)
self.response.write(html_string)
self.response.write('</div></div></body></html>')
else:
self.redirect('/communities')