-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaestbook.py
114 lines (93 loc) · 3.28 KB
/
gaestbook.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 cgi
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from models import *
from helpers import TemplateHelper
from facebook import Facebook
import settings
class MainPage(webapp.RequestHandler):
def get(self):
#TemplateHelper(self.response.out, 'index').render()
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)
authors = {}
TemplateHelper(self.response.out, 'gaestbook', {
'user': None,
'greetings': greetings,
'authors': authors
}).render()
def post(self):
# Initialize the Facebook Object.
logging.debug('Before creating facebook instance')
fb = Facebook(settings.key.api, settings.key.secret)
logging.debug('Created Facebook instance')
# Checks to make s ure that the user is logged into Facebook.
if fb.check_session(self.request):
pass
else:
# If not redirect them to your application add page.
url = fb.get_add_url()
self.response.out.write('<fb:redirect url="' + url + '" />')
return
# Checks to make sure the user has added your application.
if fb.added:
pass
else:
# If not redirect them to your application add page.
url = fb.get_add_url()
self.response.out.write('<fb:redirect url="' + url + '" />')
return
# Get the information about the user.
user = fb.users.getInfo(
[fb.uid],
['uid', 'name', 'pic_small'])[0]
logging.debug('Got user info')
greetings_query = Greeting.all().order('-date')
greetings = greetings_query.fetch(10)
for greeting in greetings:
greeting.fbinit(fb)
TemplateHelper(self.response.out, 'gaestbook', {
'user': Author(fb.uid, fb),
'greetings': greetings
}).render()
class Guestbook(webapp.RequestHandler):
def post(self):
fb = Facebook(settings.key.api, settings.key.secret)
logging.debug('Created Facebook instance')
# Checks to make s ure that the user is logged into Facebook.
if fb.check_session(self.request):
pass
else:
# If not redirect them to your application add page.
url = fb.get_add_url()
self.response.out.write('<fb:redirect url="' + url + '" />')
return
# Checks to make sure the user has added your application.
if fb.added:
pass
else:
# If not redirect them to your application add page.
url = fb.get_add_url()
self.response.out.write('<fb:redirect url="' + url + '" />')
return
greeting = Greeting()
greeting.uid = fb.uid
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
class TestPage(webapp.RequestHandler):
def get(self):
self.response.out.write("hej")
logging.debug("testpage")
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
logging.getLogger().setLevel(logging.DEBUG)
logging.debug("starting app...")
run_wsgi_app(application)
if __name__ == "__main__":
main()