-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseRequestHandler.py
More file actions
executable file
·46 lines (37 loc) · 1.42 KB
/
Copy pathBaseRequestHandler.py
File metadata and controls
executable file
·46 lines (37 loc) · 1.42 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
#!/usr/bin/env python
#
__author__ = 'Chris Constantine'
import datetime
import os
import random
import string
import sys
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import login_required
# Set to true if we want to have our webapp print stack traces, etc
_DEBUG = True
# Add our custom Django template filters to the built in filters
template.register_template_library('templatefilters')
class BaseRequestHandler(webapp.RequestHandler):
"""Supplies a common template generation function.
When you call generate(), we augment the template variables supplied with
the current user in the 'user' variable and the current webapp request
in the 'request' variable.
"""
def generate(self, template_name, template_values={}):
values = {
'request': self.request,
'user': users.GetCurrentUser(),
'login_url': users.CreateLoginURL(self.request.uri),
'logout_url': users.CreateLogoutURL('http://' + self.request.host + '/'),
'debug': self.request.get('deb'),
'application_name': 'Row Counts',
}
values.update(template_values)
directory = os.path.dirname(__file__)
path = os.path.join(directory, os.path.join('templates', template_name))
self.response.out.write(template.render(path, values, debug=_DEBUG))