diff --git a/python2.7/testapp/app.yaml b/python2.7/testapp/app.yaml new file mode 100644 index 00000000..3606d29c --- /dev/null +++ b/python2.7/testapp/app.yaml @@ -0,0 +1,16 @@ +application: indextest +version: 1 +runtime: python27 +api_version: 1 +threadsafe: yes + +builtins: +- remote_api: on + +handlers: +- url: .* + script: guestbook.app + +libraries: +- name: webapp2 + version: "2.5.2" diff --git a/python2.7/testapp/guestbook.py b/python2.7/testapp/guestbook.py new file mode 100644 index 00000000..afce3e9c --- /dev/null +++ b/python2.7/testapp/guestbook.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# Copyright 2007 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import cgi +import datetime +import webapp2 +import random +from google.appengine.ext import ndb +from google.appengine.api import users + +guestbook_key = ndb.Key('Guestbook', 'default_guestbook') + +class Greeting(ndb.Model): + author = ndb.UserProperty() + content = ndb.StringProperty() + date = ndb.DateTimeProperty(auto_now_add=True) + number = ndb.IntegerProperty() + +class MainPage(webapp2.RequestHandler): + def get(self): + self.response.out.write('
') + + greetings = ndb.gql('SELECT * ' + 'FROM Greeting ' + 'WHERE ANCESTOR IS :1 ' + 'ORDER BY date DESC LIMIT 10', + guestbook_key) + + for greeting in greetings: + if greeting.author: + self.response.out.write('%s wrote:' % greeting.author.nickname()) + else: + self.response.out.write('An anonymous person wrote:') + self.response.out.write('%s' % + cgi.escape(greeting.content)) + + + self.response.out.write(""" + + + """) + + +class Guestbook(webapp2.RequestHandler): + def post(self): + greeting = Greeting(parent=guestbook_key) + greeting.number = random.randint(0,99999) + if users.get_current_user(): + greeting.author = users.get_current_user() + + greeting.content = self.request.get('content') + greeting.put() + self.redirect('/') + + +app = webapp2.WSGIApplication([ + ('/', MainPage), + ('/sign', Guestbook) +], debug=True) diff --git a/python2.7/testapp/guestbook.pyc b/python2.7/testapp/guestbook.pyc new file mode 100644 index 00000000..6ed019b3 Binary files /dev/null and b/python2.7/testapp/guestbook.pyc differ diff --git a/python2.7/testapp/index.yaml b/python2.7/testapp/index.yaml new file mode 100644 index 00000000..a4491b2a --- /dev/null +++ b/python2.7/testapp/index.yaml @@ -0,0 +1,22 @@ +indexes: + +# AUTOGENERATED + +# This index.yaml is automatically updated whenever the dev_appserver +# detects that a new type of query is run. If you want to manage the +# index.yaml file manually, remove the above marker line (the line +# saying "# AUTOGENERATED"). If you want to manage some indexes +# manually, move them above the marker line. The index.yaml file is +# automatically uploaded to the admin console when you next deploy +# your application using appcfg.py. + +- kind: Greeting + ancestor: yes + properties: + - name: date + direction: desc +- kind: Greeting + properties: + - name: date + direction: desc + - name: content diff --git a/python2.7/testapp/stylesheets/main.css b/python2.7/testapp/stylesheets/main.css new file mode 100644 index 00000000..a8666e26 --- /dev/null +++ b/python2.7/testapp/stylesheets/main.css @@ -0,0 +1,4 @@ +body { + font-family: Verdana, Helvetica, sans-serif; + background-color: #DDDDDD; +}