コード例 #1
0
ファイル: main.py プロジェクト: runway7/signs.old
from google.appengine.ext import webapp
from google.appengine.ext.ndb import context
import routes

debug = True

ROUTES = routes.get_all()

if debug:
    import testing_handlers
    ROUTES.insert(0, ('/testing/create', testing_handlers.CreateHandler))

application = context.toplevel(
                    webapp.WSGIApplication(ROUTES, debug=debug).__call__
                )
コード例 #2
0
ファイル: main.py プロジェクト: saga/beacon
    zip_file = fetch_as_zip(zip_path)
    posts = [post for post in _extract_posts(zip_file)]
    Post.delete_all()
    Post.put_all(posts)

def serve_post(request):
    post_url = request.path_info
    post = Post.get_by_id(post_url)
    if not post: webapp.abort(404)
    return render('post.html', dict(post = post))

def tagged(request, tag):
    return render('index.html', dict(posts = Post.query(Post.tags == tag).order(-Post.date), without_intro = True))

def feed(request):
    response = render('feed.xml', dict(posts = Post.query().order(-Post.date)))
    response.headers['Content-Type'] = 'application/rss+xml'
    return response

def index(request):
    return render('index.html', dict(posts = Post.query().order(-Post.date)))

application = context.toplevel(webapp.WSGIApplication([
    webapp.SimpleRoute('/_refresh/', handler = refresh),
    webapp.Route('/tags/<tag>', handler = tagged, name = 'by-tag'), 
    webapp.SimpleRoute('/_ah/warmup', handler = index), 
    webapp.SimpleRoute('/feed', handler = feed), 
    webapp.SimpleRoute('/', handler = index), 
    webapp.SimpleRoute('/.*', handler = serve_post)
], debug=True).__call__)
コード例 #3
0
current_dir = os.path.dirname(__file__)
current_path = os.path.abspath(current_dir)

jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.join(current_dir, 'templates')))
jinja_environment.globals.update(dict(
    app_version = os.environ['CURRENT_VERSION_ID']
))

def render(template_file, data = {}):
    template = jinja_environment.get_template(template_file)
    response = webapp.get_request().app.response_class()
    response.out.write(template.render(data, url_for = webapp.uri_for))
    return response

def home(request):
	return render('home.html')

def faq(request):
	return render('faq.html')

ROUTES = [
	webapp.Route('/faq', handler=faq, name='faq'),
	webapp.Route('/', handler=home, name='home')
]

application = webapp.WSGIApplication(ROUTES, debug=debug)
application = context.toplevel(application.__call__)