forked from GoogleChrome/chromium-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
276 lines (205 loc) · 8.55 KB
/
server.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
from __future__ import division
from __future__ import print_function
# -*- coding: utf-8 -*-
# Copyright 2013 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.
__author__ = 'ericbidelman@chromium.org (Eric Bidelman)'
import json
import logging
import settings
import common
import guideforms
import models
import processes
import ramcache
import util
from google.appengine.api import users
def normalized_name(val):
return val.lower().replace(' ', '').replace('/', '')
class FeatureDetailHandler(common.FlaskHandler):
TEMPLATE_PATH = 'feature.html'
def get_template_data(self, feature_id):
f = models.Feature.get_by_id(feature_id)
if f is None:
self.abort(404)
if f.deleted:
# TODO(jrobbins): Check permissions and offer option to undelete.
self.abort(404)
feature_process = processes.ALL_PROCESSES.get(
f.feature_type, processes.BLINK_LAUNCH_PROCESS)
field_defs = guideforms.DISPLAY_FIELDS_IN_STAGES
template_data = {
'process_json': json.dumps(processes.process_to_dict(feature_process)),
'field_defs_json': json.dumps(field_defs),
'feature': f.format_for_template(),
'feature_id': f.key().id(),
'feature_json': json.dumps(f.format_for_template()),
'updated_display': f.updated.strftime("%Y-%m-%d"),
'new_crbug_url': f.new_crbug_url(),
}
return template_data
class FeatureListXMLHandler(common.FlaskHandler):
def get_template_data(self):
status = self.request.args.get('status', None)
if status:
feature_list = models.Feature.get_all_with_statuses(status.split(','))
else:
filterby = None
category = self.request.args.get('category', None)
# Support setting larger-than-default Atom feed sizes so that web
# crawlers can use this as a full site feed.
try:
max_items = int(self.request.args.get(
'max-items', settings.RSS_FEED_LIMIT))
except TypeError:
max_items = settings.RSS_FEED_LIMIT
if category is not None:
for k,v in models.FEATURE_CATEGORIES.iteritems():
normalized = normalized_name(v)
if category == normalized:
filterby = ('category =', k)
break
feature_list = models.Feature.get_all( # cached
limit=max_items,
filterby=filterby,
order='-updated')
return common.render_atom_feed(self.request, 'Features', feature_list)
class FeatureListHandler(common.FlaskHandler):
TEMPLATE_PATH = 'features.html'
def get_template_data(self, feature_id=None):
# Note: feature_id is not used here but JS gets it from the URL.
# This template data is all for filtering. The actual features
# are sent by an XHR request for /features.json.
template_data = {}
template_data['categories'] = [
(v, normalized_name(v)) for k,v in
models.FEATURE_CATEGORIES.iteritems()]
template_data['IMPLEMENTATION_STATUSES'] = json.dumps([
{'key': k, 'val': v} for k,v in
models.IMPLEMENTATION_STATUS.iteritems()])
template_data['VENDOR_VIEWS'] = json.dumps([
{'key': k, 'val': v} for k,v in
models.VENDOR_VIEWS.iteritems()])
template_data['WEB_DEV_VIEWS'] = json.dumps([
{'key': k, 'val': v} for k,v in
models.WEB_DEV_VIEWS.iteritems()])
template_data['STANDARDS_VALS'] = json.dumps([
{'key': k, 'val': v} for k,v in
models.STANDARDIZATION.iteritems()])
return template_data
class CssPopularityHandler(common.FlaskHandler):
TEMPLATE_PATH = 'metrics/css/timeline/popularity.html'
def get_template_data(self, bucket_id=None):
# Note: bucket_id is not used, but the JS looks in the URL to get it.
properties = sorted(
models.CssPropertyHistogram.get_all().iteritems(), key=lambda x:x[1])
template_data = {
'CSS_PROPERTY_BUCKETS': json.dumps(
properties, separators=(',',':')),
}
return template_data
class CssAnimatedHandler(CssPopularityHandler):
TEMPLATE_PATH = 'metrics/css/timeline/animated.html'
# The logic and data is the same, but it is filtered differenly in JS.
class FeaturePopularityHandler(common.FlaskHandler):
TEMPLATE_PATH = 'metrics/feature/timeline/popularity.html'
def get_template_data(self, bucket_id=None):
# Note: bucket_id is not used, but the JS looks in the URL to get it.
properties = sorted(
models.FeatureObserverHistogram.get_all().iteritems(), key=lambda x:x[1])
template_data = {
'FEATUREOBSERVER_BUCKETS': json.dumps(
properties, separators=(',',':')),
}
return template_data
class OmahaDataHandler(common.FlaskHandler):
JSONIFY = True
def get_template_data(self):
omaha_data = util.get_omaha_data()
return omaha_data
class FeaturesAPIHandler(common.FlaskHandler):
HTTP_CACHE_TYPE = 'private'
JSONIFY = True
def get_template_data(self, version=2):
user = users.get_current_user()
feature_list = models.Feature.get_chronological(
version=version, show_unlisted=self.user_can_edit(user))
return feature_list
class SamplesHandler(common.FlaskHandler):
TEMPLATE_PATH = 'samples.html'
def get_template_data(self):
feature_list = models.Feature.get_shipping_samples() # cached
template_data = {}
template_data['FEATURES'] = json.dumps(feature_list, separators=(',',':'))
template_data['CATEGORIES'] = [
(v, normalized_name(v)) for k,v in
models.FEATURE_CATEGORIES.iteritems()]
template_data['categories'] = dict([
(v, normalized_name(v)) for k,v in
models.FEATURE_CATEGORIES.iteritems()])
return template_data
class SamplesJSONHandler(common.FlaskHandler):
JSONIFY = True
def get_template_data(self):
feature_list = models.Feature.get_shipping_samples() # cached
return feature_list
class SamplesXMLHandler(common.FlaskHandler):
def get_template_data(self):
feature_list = models.Feature.get_shipping_samples() # cached
# Support setting larger-than-default Atom feed sizes so that web
# crawlers can use this as a full site feed.
try:
max_items = int(self.request.args.get(
'max-items', settings.RSS_FEED_LIMIT))
except TypeError:
max_items = settings.RSS_FEED_LIMIT
return common.render_atom_feed(self.request, 'Samples', feature_list)
# Main URL routes.
routes = [
# Note: The only requests being made now hit /features.json and
# /features_v2.json, but both of those cause version == 2.
# There was logic to accept another version value, but it it was not used.
(r'/features.json', FeaturesAPIHandler),
(r'/features_v2.json', FeaturesAPIHandler),
('/samples', SamplesHandler),
('/samples.json', SamplesJSONHandler),
('/samples.xml', SamplesXMLHandler),
('/feature/<int:feature_id>', FeatureDetailHandler),
('/', common.Redirector,
{'location': '/features'}),
('/metrics', common.Redirector,
{'location': '/metrics/css/popularity'}),
('/metrics/css', common.Redirector,
{'location': '/metrics/css/popularity'}),
('/features', FeatureListHandler),
('/features/<int:feature_id>', FeatureListHandler),
('/features.xml', FeatureListXMLHandler),
# TODO(jrobbins): These seem like they belong in metrics.py.
('/metrics/css/popularity', common.ConstHandler,
{'template_path': 'metrics/css/popularity.html'}),
('/metrics/css/animated', common.ConstHandler,
{'template_path': 'metrics/css/animated.html'}),
('/metrics/css/timeline/popularity', CssPopularityHandler),
('/metrics/css/timeline/popularity/<int:bucket_id>', CssPopularityHandler),
('/metrics/css/timeline/animated', CssAnimatedHandler),
('/metrics/css/timeline/animated/<int:bucket_id>', CssAnimatedHandler),
('/metrics/feature/popularity', common.ConstHandler,
{'template_path': 'metrics/feature/popularity.html'}),
('/metrics/feature/timeline/popularity', FeaturePopularityHandler),
('/metrics/feature/timeline/popularity/<int:bucket_id>', FeaturePopularityHandler),
# TODO(jrobbins): util.py has only one thing in it, so maybe move
# it and this handler to a new omaha.py file.
('/omaha_data', OmahaDataHandler),
]
app = common.FlaskApplication(routes, debug=settings.DEBUG)