<s> """<STR_LIT>""" <EOL> import cgi <EOL> import urllib <EOL> from google . appengine . ext import ndb <EOL> import webapp2 <EOL> class Greeting ( ndb . Model ) : <EOL> """<STR_LIT>""" <EOL> content = ndb . StringProperty ( ) <EOL> date = ndb . DateTimeProperty ( auto_now_add = True ) <EOL> @ classmethod <EOL> def query_book ( cls , ancestor_key ) : <EOL> return cls . query ( ancestor = ancestor_key ) . order ( - cls . date ) <EOL> class MainPage ( webapp2 . RequestHandler ) : <EOL> def get ( self ) : <EOL> self . response . out . write ( '<STR_LIT>' ) <EOL> guestbook_name = self . request . get ( '<STR_LIT>' ) <EOL> ancestor_key = ndb . Key ( "<STR_LIT>" , guestbook_name or "<STR_LIT>" ) <EOL> greetings = Greeting . query_book ( ancestor_key ) . fetch ( <NUM_LIT:20> ) <EOL> for greeting in greetings : <EOL> self . response . out . write ( '<STR_LIT>' % <EOL> cgi . escape ( greeting . content ) ) <EOL> self . response . out . write ( """<STR_LIT>""" % ( urllib . urlencode ( { '<STR_LIT>' : guestbook_name } ) , <EOL> cgi . escape ( guestbook_name ) ) ) <EOL> class SubmitForm ( webapp2 . RequestHandler ) : <EOL> def post ( self ) : <EOL> guestbook_name = self . request . get ( '<STR_LIT>' ) <EOL> greeting = Greeting ( parent = ndb . Key ( "<STR_LIT>" , <EOL> guestbook_name or "<STR_LIT>" ) , <EOL> content = self . request . get ( '<STR_LIT:content>' ) ) <EOL> greeting . put ( ) <EOL> self . redirect ( '<STR_LIT>' + urllib . urlencode ( <EOL> { '<STR_LIT>' : guestbook_name } ) ) <EOL> app = webapp2 . WSGIApplication ( [ <EOL> ( '<STR_LIT:/>' , MainPage ) , <EOL> ( '<STR_LIT>' , SubmitForm ) <EOL> ] ) </s>
