2017-10-26 14:13:28 +00:00
|
|
|
"""Render recent responses and logs."""
|
|
|
|
import calendar
|
2017-10-26 04:32:59 +00:00
|
|
|
import datetime
|
2017-10-26 14:19:13 +00:00
|
|
|
import urllib
|
2017-10-26 04:32:59 +00:00
|
|
|
|
|
|
|
import appengine_config
|
2017-10-26 14:13:28 +00:00
|
|
|
|
2017-10-26 04:32:59 +00:00
|
|
|
from oauth_dropins.webutil import util
|
2017-10-26 14:13:28 +00:00
|
|
|
from oauth_dropins.webutil.handlers import TemplateHandler
|
|
|
|
from oauth_dropins.webutil import logs
|
2017-10-26 04:32:59 +00:00
|
|
|
import webapp2
|
|
|
|
|
|
|
|
from models import Response
|
|
|
|
|
2017-10-26 14:13:28 +00:00
|
|
|
VERSION_1_DEPLOYED = datetime.datetime(2017, 10, 26, 16, 0)
|
|
|
|
|
|
|
|
|
|
|
|
class LogHandler(logs.LogHandler):
|
|
|
|
VERSION_IDS = ['1']
|
|
|
|
|
2017-10-26 04:32:59 +00:00
|
|
|
|
|
|
|
class ResponsesHandler(TemplateHandler):
|
|
|
|
"""Renders recent Responses, with links to logs."""
|
|
|
|
|
|
|
|
def template_file(self):
|
|
|
|
return 'templates/responses.html'
|
|
|
|
|
|
|
|
def template_vars(self):
|
|
|
|
responses = Response.query().order(-Response.updated).fetch(20)
|
|
|
|
|
|
|
|
for r in responses:
|
2017-10-26 14:30:52 +00:00
|
|
|
r.source_link = util.pretty_link(r.source())
|
|
|
|
r.target_link = util.pretty_link(r.target())
|
|
|
|
# TODO: support inbound too
|
2017-10-26 14:19:13 +00:00
|
|
|
if r.direction == 'out' and r.updated >= VERSION_1_DEPLOYED:
|
|
|
|
r.log_url_path = '/log?' + urllib.urlencode({
|
|
|
|
'key': r.key.id(),
|
|
|
|
'start_time': calendar.timegm(r.updated.timetuple()),
|
|
|
|
})
|
2017-10-26 04:32:59 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'responses': responses,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app = webapp2.WSGIApplication([
|
2017-10-26 14:13:28 +00:00
|
|
|
('/log', LogHandler),
|
2017-10-26 04:32:59 +00:00
|
|
|
('/responses', ResponsesHandler),
|
|
|
|
], debug=appengine_config.DEBUG)
|