1# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import urllib
6
7import webapp2
8
9from common import jinja
10from common import query_filter
11
12
13class Trace(webapp2.RequestHandler):
14
15  def get(self):
16    try:
17      filters = query_filter.Filters(self.request)
18    except ValueError as e:
19      self.response.headers['Content-Type'] = 'application/json'
20      self.response.out.write({'error': str(e)})
21      return
22
23    query_parameters = []
24    for filter_name, filter_values in filters.iteritems():
25      if filter_name == 'start_time':
26        query_parameters.append(('start_time', filter_values))
27      else:
28        for filter_value in filter_values:
29          query_parameters.append((filter_name, filter_value))
30    template_values = {
31        'query_string': urllib.urlencode(query_parameters),
32    }
33
34    template = jinja.ENVIRONMENT.get_template('trace.html')
35    self.response.out.write(template.render(template_values))
36