<s> import cgi <EOL> import datetime <EOL> import webapp2 <EOL> from google . appengine . ext import ndb <EOL> from google . appengine . api import users <EOL> guestbook_key = ndb . Key ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class Greeting ( ndb . Model ) : <EOL> author = ndb . UserProperty ( ) <EOL> content = ndb . TextProperty ( ) <EOL> date = ndb . DateTimeProperty ( auto_now_add = True ) <EOL> class MainPage ( webapp2 . RequestHandler ) : <EOL> def get ( self ) : <EOL> self . response . out . write ( '<STR_LIT>' ) <EOL> greetings = ndb . gql ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> guestbook_key ) <EOL> for greeting in greetings : <EOL> if greeting . author : <EOL> self . response . out . write ( '<STR_LIT>' % greeting . author . nickname ( ) ) <EOL> else : <EOL> self . response . out . write ( '<STR_LIT>' ) <EOL> self . response . out . write ( '<STR_LIT>' % <EOL> cgi . escape ( greeting . content ) ) <EOL> self . response . out . write ( """<STR_LIT>""" ) <EOL> class Guestbook ( webapp2 . RequestHandler ) : <EOL> def post ( self ) : <EOL> greeting = Greeting ( parent = guestbook_key ) <EOL> if users . get_current_user ( ) : <EOL> greeting . author = users . get_current_user ( ) <EOL> greeting . content = self . request . get ( '<STR_LIT:content>' ) <EOL> greeting . put ( ) <EOL> self . redirect ( '<STR_LIT:/>' ) <EOL> app = webapp2 . WSGIApplication ( [ <EOL> ( '<STR_LIT:/>' , MainPage ) , <EOL> ( '<STR_LIT>' , Guestbook ) <EOL> ] , debug = True ) </s>
