-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.py
More file actions
48 lines (40 loc) · 1.51 KB
/
helloworld.py
File metadata and controls
48 lines (40 loc) · 1.51 KB
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
import os
import webapp2
from google.appengine.ext.webapp import template
from google.appengine.api import users
from greeting import Greeting
class MainPage(webapp2.RequestHandler):
def get(self):
greetings = Greeting().uniqueList()
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 = {
'greetings': greetings,
'url': url,
'url_linktext': url_linktext,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Guestbook(webapp2.RequestHandler):
def post(self):
greeting = Greeting()
cont = self.request.get('content')
if cont != "":
if cont.lower().find("http") >= 0:
self.response.out.write("<h4>Sorry, HTTP is not allowed in the comment.</h4>Use the Back button to return to the Guest Book.")
return
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = cont
greeting.put()
self.redirect('/')
else:
self.response.out.write("<h4>Please enter a comment.</h4>Use the Back button to return to the Guest Book.")
application = webapp2.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)