Exemple #1
0
    def request_stats(self, request):
        """Live stats for the server.

        Try sending lots of requests
        """
        # scheme = 'wss' if request.is_secure else 'ws'
        # host = request.get('HTTP_HOST')
        # address = '%s://%s/stats' % (scheme, host)
        doc = HtmlDocument(title="Live server stats", media_path="/assets/")
        # docs.head.scripts
        return doc.http_response(request)
Exemple #2
0
    def stats(self, request):
        '''Live stats for the server.

        Try sending lots of requests
        '''
        # scheme = 'wss' if request.is_secure else 'ws'
        # host = request.get('HTTP_HOST')
        # address = '%s://%s/stats' % (scheme, host)
        doc = HtmlDocument(title='Live server stats', media_path='/assets/')
        # docs.head.scripts
        return doc.http_response(request)
Exemple #3
0
    def html_document(self, request):
        '''Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        '''
        cfg = self.config
        site_url = cfg['SITE_URL']
        media_path = cfg['MEDIA_URL']
        if site_url:
            media_path = site_url + media_path
        doc = HtmlDocument(title=cfg['HTML_TITLE'],
                           media_path=media_path,
                           minified=cfg['MINIFIED_MEDIA'],
                           data_debug=self.debug,
                           charset=cfg['ENCODING'],
                           asset_protocol=cfg['ASSET_PROTOCOL'])
        doc.meta = HeadMeta(doc.head)
        doc.jscontext = dict(((p.name, cfg[p.name])
                              for p in cfg['_parameters'].values()
                              if p.jscontext))
        # Locale
        lang = cfg['LOCALE'][:2]
        doc.attr('lang', lang)
        #
        head = doc.head
        for script in cfg['SCRIPTS']:
            head.scripts.append(script)
        #
        required = cfg['REQUIREJS']
        if required:
            head.scripts.append(cfg['REQUIREJS_CONFIG'])
            head.scripts.append(cfg['REQUIREJS_URL'])
            head.scripts.require.extend((media_path+r[1:] if r.startswith('.')
                                         else r for r in required))
        #
        for entry in cfg['HTML_META'] or ():
            head.add_meta(**entry)

        self.fire('on_html_document', request, doc)
        #
        # Add links last
        links = head.links
        for link in cfg['HTML_LINKS']:
            if isinstance(link, dict):
                links.append(**link)
            else:
                links.append(link)
        return doc
Exemple #4
0
    def html_document(self, request):
        '''Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        '''
        cfg = self.config
        doc = HtmlDocument(title=cfg['HTML_TITLE'],
                           media_path=cfg['MEDIA_URL'],
                           minified=cfg['MINIFIED_MEDIA'],
                           data_debug=self.debug,
                           charset=cfg['ENCODING'],
                           asset_protocol=cfg['ASSET_PROTOCOL'])
        doc.meta = HeadMeta(doc.head)
        doc.jscontext = dict(((p.name, cfg[p.name])
                              for p in cfg['_parameters'].values()
                              if p.jscontext))
        # Locale
        lang = cfg['LOCALE'][:2]
        doc.attr('lang', lang)
        #
        # Head
        head = doc.head
        # Add requirejs if url available
        requirejs = cfg['REQUIREJS_URL']
        if requirejs:
            head.scripts.append(requirejs)

        for script in cfg['SCRIPTS']:
            head.scripts.append(script)
        #
        for entry in cfg['HTML_META'] or ():
            head.add_meta(**entry)

        self.fire('on_html_document', request, doc, safe=True)
        #
        # Add links last
        links = head.links
        for link in cfg['HTML_LINKS']:
            if isinstance(link, dict):
                links.append(**link)
            else:
                links.append(link)
        return doc
Exemple #5
0
    def html_document(self, request):
        """Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        """
        app = self.app
        cfg = app.config
        doc = HtmlDocument(title=cfg['HTML_TITLE'],
                           media_path=cfg['MEDIA_URL'],
                           minified=cfg['MINIFIED_MEDIA'],
                           data_debug=app.debug,
                           charset=cfg['ENCODING'],
                           asset_protocol=cfg['ASSET_PROTOCOL'])
        doc.meta = HeadMeta(doc.head)
        doc.jscontext = dict((
            (p.name, cfg[p.name]) for p in cfg['_parameters'].values()
            if p.jscontext
        ))
        doc.jscontext['debug'] = app.debug
        # Locale
        lang = cfg['LOCALE'][:2]
        doc.attr('lang', lang)
        #
        # Head
        head = doc.head

        for script in cfg['HTML_SCRIPTS']:
            head.scripts.append(script)
        #
        for entry in cfg['HTML_META'] or ():
            head.add_meta(**entry)

        for script in cfg['HTML_BODY_SCRIPTS']:
            doc.body.scripts.append(script, async=True)

        try:
            app.fire_event('on_html_document', data=(request, doc))
        except Exception:
            self.app.logger.exception('Unhandled exception on html document')
        #
        # Add links last
        links = head.links
        for link in cfg['HTML_LINKS']:
            if isinstance(link, dict):
                link = link.copy()
                href = link.pop('href', None)
                if href:
                    links.append(href, **link)
            else:
                links.append(link)
        return doc
Exemple #6
0
    def html_document(self, request):
        '''Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        '''
        cfg = self.config
        site_url = cfg['SITE_URL']
        media_path = cfg['MEDIA_URL']
        if site_url:
            media_path = site_url + media_path
        doc = HtmlDocument(title=cfg['HTML_TITLE'],
                           media_path=media_path,
                           minified=cfg['MINIFIED_MEDIA'],
                           data_debug=self.debug,
                           charset=cfg['ENCODING'],
                           asset_protocol=cfg['ASSET_PROTOCOL'])
        doc.meta = HeadMeta(doc.head)
        doc.jscontext = dict(((p.name, cfg[p.name])
                              for p in cfg['_parameters'].values()
                              if p.jscontext))
        # Locale
        lang = cfg['LOCALE'][:2]
        doc.attr('lang', lang)
        #
        head = doc.head
        for script in cfg['SCRIPTS']:
            head.scripts.append(script)
        #
        required = cfg['REQUIREJS']
        if required:
            head.scripts.append(cfg['REQUIREJS_CONFIG'])
            head.scripts.append(cfg['REQUIREJS_URL'])
            head.scripts.require.extend(
                (media_path + r[1:] if r.startswith('.') else r
                 for r in required))
        #
        for entry in cfg['HTML_META'] or ():
            head.add_meta(**entry)

        self.fire('on_html_document', request, doc)
        #
        # Add links last
        links = head.links
        for link in cfg['HTML_LINKS']:
            if isinstance(link, dict):
                links.append(**link)
            else:
                links.append(link)
        return doc
Exemple #7
0
    def html_document(self, request):
        '''Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        '''
        content_type = request.response.content_type
        handler = request.app_handler
        title = None
        if handler:
            title = handler.parameters.get('title')
        cfg = self.config
        doc = HtmlDocument(title=title or cfg['HTML_HEAD_TITLE'],
                           media_path=cfg['MEDIA_URL'],
                           minified=cfg['MINIFIED_MEDIA'],
                           known_libraries=media_libraries,
                           scripts_dependencies=javascript_dependencies,
                           require_callback=cfg['JSREQUIRE_CALLBACK'],
                           debug=self.debug,
                           content_type=content_type,
                           charset=cfg['ENCODING'])
        #
        if doc.has_default_content_type:
            head = doc.head
            head.links.append(cfg['CSS'])
            #
            required = cfg['JSREQUIRED']
            if required:
                scripts = head.scripts
                scripts.append('require')
                scripts.require(*required)
            #
            for entry in cfg['HTML_META'] or ():
                head.add_meta(**entry)

            self.fire('on_html_document', request, doc)
        return doc
Exemple #8
0
    def html_document(self, request):
        '''Build the HTML document.

        Usually there is no need to call directly this method.
        Instead one can use the :attr:`.WsgiRequest.html_document`.
        '''
        cfg = self.config
        doc = HtmlDocument(title=cfg['HTML_TITLE'],
                           media_path=cfg['MEDIA_URL'],
                           minified=cfg['MINIFIED_MEDIA'],
                           data_debug=self.debug,
                           charset=cfg['ENCODING'],
                           asset_protocol=cfg['ASSET_PROTOCOL'])
        doc.meta = HeadMeta(doc.head)
        doc.jscontext = dict(((p.name, cfg[p.name])
                              for p in cfg['_parameters'].values()
                              if p.jscontext))
        # Locale
        lang = cfg['LOCALE'][:2]
        doc.attr('lang', lang)
        #
        # Head
        head = doc.head
        # Add requirejs if url available
        requirejs = cfg['REQUIREJS_URL']
        if requirejs:
            head.scripts.append(requirejs)

        for script in cfg['SCRIPTS']:
            head.scripts.append(script)
        #
        for entry in cfg['HTML_META'] or ():
            head.add_meta(**entry)

        self.fire('on_html_document', request, doc, safe=True)
        #
        # Add links last
        links = head.links
        for link in cfg['HTML_LINKS']:
            if isinstance(link, dict):
                links.append(**link)
            else:
                links.append(link)
        return doc