Beispiel #1
0
    def get(self, path, feature_id=None):
        # Default to features page.
        # TODO: remove later when we want an index.html
        if not path:
            return self.redirect('/features')

        # Default /metrics to CSS ranking.
        # TODO: remove later when we want /metrics/index.html
        if path == 'metrics' or path == 'metrics/css':
            return self.redirect('/metrics/css/popularity')

        # Remove trailing slash from URL and redirect. e.g. /metrics/ -> /metrics
        if feature_id == '':
            return self.redirect(self.request.path.rstrip('/'))

        template_data = {}
        push_urls = []  # URLs to push in this response.

        template_data['embed'] = self.request.get('embed', None) is not None

        if path.startswith('features'):
            if path.endswith('.xml'):  # Atom feed request.
                status = self.request.get('status', None)
                if status:
                    feature_list = models.Feature.get_all_with_statuses(
                        status.split(','))
                else:
                    filterby = None
                    category = self.request.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.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(  # Memcached
                        limit=max_items,
                        filterby=filterby,
                        order='-updated')

                return self.render_atom_feed('Features', feature_list)
            else:
                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()])
                template_data[
                    'TEMPLATE_CACHE_TIME'] = settings.TEMPLATE_CACHE_TIME

                push_urls = http2push.use_push_manifest(
                    'push_manifest_features.json')

        elif path.startswith('feature'):
            feature = None
            try:
                feature = models.Feature.get_feature(int(feature_id))
            except TypeError:
                pass
            if feature is None:
                self.abort(404)

            was_updated = False
            if self.request.referer:
                was_updated = (
                    self.request.referer.endswith('/admin/features/new')
                    or '/admin/features/edit' in self.request.referer)

            template_data['feature'] = feature
            template_data['was_updated'] = was_updated

        elif path.startswith('metrics/css/timeline'):
            properties = sorted(
                models.CssPropertyHistogram.get_all().iteritems(),
                key=lambda x: x[1])
            template_data['CSS_PROPERTY_BUCKETS'] = json.dumps(
                properties, separators=(',', ':'))
        elif path.startswith('metrics/feature/timeline'):
            properties = sorted(
                models.FeatureObserverHistogram.get_all().iteritems(),
                key=lambda x: x[1])
            template_data['FEATUREOBSERVER_BUCKETS'] = json.dumps(
                properties, separators=(',', ':'))
        elif path.startswith('omaha_data'):
            omaha_data = get_omaha_data()
            return common.JSONHandler.get(self, omaha_data, formatted=True)
        elif path.startswith('samples'):
            feature_list = models.Feature.get_shipping_samples()  # Memcached

            if path.endswith('.json'):  # JSON request.
                return common.JSONHandler.get(self,
                                              feature_list,
                                              formatted=True)
            elif path.endswith('.xml'):  # Atom feed request.
                # 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.get('max-items', settings.RSS_FEED_LIMIT))
                except TypeError:
                    max_items = settings.RSS_FEED_LIMIT

                return self.render_atom_feed('Samples', feature_list)
            else:
                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()
                ])

        if path.startswith('metrics/'):
            push_urls = http2push.use_push_manifest(
                'push_manifest_metrics.json')

        # Add Link rel=preload header for h2 push on .html file requests.
        if push_urls:
            self.response.headers.add_header(
                'Link', self._generate_link_preload_headers(push_urls))

        self.render(data=template_data,
                    template_path=os.path.join(path + '.html'))
Beispiel #2
0
  def get(self, path, feature_id=None):
    # Default to features page.
    # TODO: remove later when we want an index.html
    if not path:
      return self.redirect('/features')

    # Default /metrics to CSS ranking.
    # TODO: remove later when we want /metrics/index.html
    if path == 'metrics' or path == 'metrics/css':
      return self.redirect('/metrics/css/popularity')

    # Remove trailing slash from URL and redirect. e.g. /metrics/ -> /metrics
    if feature_id == '':
      return self.redirect(self.request.path.rstrip('/'))

    template_data = {}
    push_urls = [] # URLs to push in this response.

    if path.startswith('features'):
      if path.endswith('.json'): # JSON request.
        feature_list = self.__get_feature_list()
        return common.JSONHandler.get(self, feature_list, formatted=True)
      elif path.endswith('.xml'): # Atom feed request.
        status = self.request.get('status', None)
        if status:
          feature_list = models.Feature.get_all_with_statuses(status.split(','))
        else:
          filterby = None
          category = self.request.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.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( # Memcached
              limit=max_items,
              filterby=filterby,
              order='-updated')

        return self.render_atom_feed('Features', feature_list)
      else:
        # if settings.PROD:
        #   feature_list = self.__get_feature_list()
        # else:
        #   result = urlfetch.fetch(
        #     self.request.scheme + '://' + self.request.host +
        #     '/static/js/mockdata.json')
        #   feature_list = json.loads(result.content)

        # 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['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()])

        push_urls = http2push.use_push_manifest('push_manifest_features.json')

    elif path.startswith('feature'):
      feature = None
      try:
        feature = models.Feature.get_feature(int(feature_id))
      except TypeError:
        pass
      if feature is None:
        self.abort(404)

      template_data['feature'] = feature

    elif path.startswith('metrics/css/timeline'):
      properties = sorted(
          models.CssPropertyHistogram.get_all().iteritems(), key=lambda x:x[1])
      template_data['CSS_PROPERTY_BUCKETS'] = json.dumps(
          properties, separators=(',',':'))
    elif path.startswith('metrics/feature/timeline'):
      properties = sorted(
          models.FeatureObserverHistogram.get_all().iteritems(), key=lambda x:x[1])
      template_data['FEATUREOBSERVER_BUCKETS'] = json.dumps(
          properties, separators=(',',':'))
    elif path.startswith('omaha_data'):
      omaha_data = self.__get_omaha_data()
      return common.JSONHandler.get(self, omaha_data, formatted=True)
    elif path.startswith('samples'):
      feature_list = models.Feature.get_shipping_samples() # Memcached

      if path.endswith('.json'): # JSON request.
        return common.JSONHandler.get(self, feature_list, formatted=True)
      elif path.endswith('.xml'): # Atom feed request.
        # 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.get('max-items',
                                           settings.RSS_FEED_LIMIT))
        except TypeError:
          max_items = settings.RSS_FEED_LIMIT

        return self.render_atom_feed('Samples', feature_list)
      else:
        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()])

    if path.startswith('metrics/'):
      push_urls = http2push.use_push_manifest('push_manifest_metrics.json')

    # Add Link rel=preload header for h2 push on .html file requests.
    if push_urls:
      self.response.headers.add_header(
          'Link', self._generate_link_preload_headers(push_urls))

    self.render(data=template_data, template_path=os.path.join(path + '.html'))