2021-03-23 01:33:02 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright 2021 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.
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import settings
|
|
|
|
from framework import basehandlers
|
2021-03-24 20:11:13 +03:00
|
|
|
from framework import permissions
|
2021-03-23 01:33:02 +03:00
|
|
|
from framework import utils
|
2022-08-24 02:00:02 +03:00
|
|
|
from internals import core_models
|
2022-08-13 01:49:32 +03:00
|
|
|
from internals import core_enums
|
2021-03-23 01:33:02 +03:00
|
|
|
from framework import ramcache
|
|
|
|
|
2021-05-07 02:37:30 +03:00
|
|
|
# from google.appengine.api import users
|
|
|
|
from framework import users
|
2021-03-23 01:33:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
class FeaturesJsonHandler(basehandlers.FlaskHandler):
|
|
|
|
|
|
|
|
HTTP_CACHE_TYPE = 'private'
|
|
|
|
JSONIFY = True
|
|
|
|
|
|
|
|
def get_template_data(self, version=2):
|
|
|
|
user = users.get_current_user()
|
2022-08-24 02:00:02 +03:00
|
|
|
feature_list = core_models.Feature.get_chronological(
|
2021-04-24 00:12:07 +03:00
|
|
|
version=version,
|
2022-08-27 01:30:55 +03:00
|
|
|
show_unlisted=permissions.can_edit_any_feature(user))
|
2021-03-23 01:33:02 +03:00
|
|
|
return feature_list
|
|
|
|
|
|
|
|
|
|
|
|
class FeatureListHandler(basehandlers.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, utils.normalized_name(v)) for k,v in
|
2022-08-13 01:49:32 +03:00
|
|
|
list(core_enums.FEATURE_CATEGORIES.items())]
|
2021-03-23 01:33:02 +03:00
|
|
|
template_data['IMPLEMENTATION_STATUSES'] = json.dumps([
|
|
|
|
{'key': k, 'val': v} for k,v in
|
2022-08-13 01:49:32 +03:00
|
|
|
list(core_enums.IMPLEMENTATION_STATUS.items())])
|
2021-03-23 01:33:02 +03:00
|
|
|
template_data['VENDOR_VIEWS'] = json.dumps([
|
|
|
|
{'key': k, 'val': v} for k,v in
|
2022-08-13 01:49:32 +03:00
|
|
|
list(core_enums.VENDOR_VIEWS.items())])
|
2021-03-23 01:33:02 +03:00
|
|
|
template_data['WEB_DEV_VIEWS'] = json.dumps([
|
|
|
|
{'key': k, 'val': v} for k,v in
|
2022-08-13 01:49:32 +03:00
|
|
|
list(core_enums.WEB_DEV_VIEWS.items())])
|
2021-03-23 01:33:02 +03:00
|
|
|
template_data['STANDARDS_VALS'] = json.dumps([
|
|
|
|
{'key': k, 'val': v} for k,v in
|
2022-08-13 01:49:32 +03:00
|
|
|
list(core_enums.STANDARDIZATION.items())])
|
2021-03-23 01:33:02 +03:00
|
|
|
|
|
|
|
return template_data
|
|
|
|
|
|
|
|
|
2022-08-22 20:34:33 +03:00
|
|
|
# TODO(jrobbins): Delete this some time after Oct 2022.
|
2021-03-23 01:33:02 +03:00
|
|
|
class FeatureListXMLHandler(basehandlers.FlaskHandler):
|
|
|
|
|
|
|
|
def get_template_data(self):
|
|
|
|
status = self.request.args.get('status', None)
|
|
|
|
if status:
|
2022-08-24 02:00:02 +03:00
|
|
|
feature_list = core_models.Feature.get_all_with_statuses(status.split(','))
|
2021-03-23 01:33:02 +03:00
|
|
|
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:
|
2022-08-13 01:49:32 +03:00
|
|
|
for k,v in list(core_enums.FEATURE_CATEGORIES.items()):
|
2021-03-23 01:33:02 +03:00
|
|
|
normalized = utils.normalized_name(v)
|
|
|
|
if category == normalized:
|
2021-09-18 03:20:25 +03:00
|
|
|
filterby = ('category', k)
|
2021-03-23 01:33:02 +03:00
|
|
|
break
|
|
|
|
|
2022-08-24 02:00:02 +03:00
|
|
|
feature_list = core_models.Feature.get_all( # cached
|
2021-03-23 01:33:02 +03:00
|
|
|
limit=max_items,
|
|
|
|
filterby=filterby,
|
2021-07-22 22:47:33 +03:00
|
|
|
order='-updated',
|
2021-07-28 23:42:18 +03:00
|
|
|
version=2)
|
2021-03-23 01:33:02 +03:00
|
|
|
|
|
|
|
return utils.render_atom_feed(self.request, 'Features', feature_list)
|