当前位置: 首页>>代码示例>>Python>>正文


Python Chrome.populate_hdf方法代码示例

本文整理汇总了Python中trac.web.chrome.Chrome.populate_hdf方法的典型用法代码示例。如果您正苦于以下问题:Python Chrome.populate_hdf方法的具体用法?Python Chrome.populate_hdf怎么用?Python Chrome.populate_hdf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.web.chrome.Chrome的用法示例。


在下文中一共展示了Chrome.populate_hdf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_request

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import populate_hdf [as 别名]
    def process_request(self, req):
        req.perm.assert_permission('STRACTISTICS_VIEW')
        add_stylesheet(req, 'hw/css/stractistics.css')
        
        #Reading options from trac.ini
        config = util.read_config_options(self.env.config)
        
        #Patch for Trac 0.11
        if trac.__version__.find('0.11') != -1:
            chrome = Chrome(self.env)
            chrome.populate_hdf(req)
                
        #Populating our context navigation bar.
        strac_ref = req.href.stractistics()
        links = []
        for elem in self.sections:
            links.append((elem[0], "/".join([strac_ref, elem[1]])))
        req.hdf['section_links'] = links
        
        db = self.env.get_db_cnx()
        module = req.args.get('module', None)
        if module is not None and module == 'user_reports':
            template, content_type = user_reports.user_reports(req, 
                                                               config, 
                                                               db)
        else:
            template, content_type = global_reports.global_reports(req, 
                                                                   config, 
                                                                   db)
        return template, content_type

    
                
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:32,代码来源:web_ui.py

示例2: test_nav_contributor_active

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import populate_hdf [as 别名]
 def test_nav_contributor_active(self):
     class TestNavigationContributor(Component):
         implements(INavigationContributor)
         def get_active_navigation_item(self, req):
             return 'test'
         def get_navigation_items(self, req):
             yield 'metanav', 'test', 'Test'
     env = EnvironmentStub(enable=[TestNavigationContributor])
     req = Mock(hdf=HDFWrapper(), href=Href('/trac.cgi'),
                path_info='/', base_path='/trac.cgi')
     chrome = Chrome(env)
     chrome.populate_hdf(req, TestNavigationContributor(env))
     self.assertEqual('Test', req.hdf['chrome.nav.metanav.test'])
     self.assertEqual('1', req.hdf['chrome.nav.metanav.test.active'])
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:16,代码来源:chrome.py

示例3: test_nav_contributor_order

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import populate_hdf [as 别名]
    def test_nav_contributor_order(self):
        class TestNavigationContributor1(Component):
            implements(INavigationContributor)
            def get_active_navigation_item(self, req):
                return None
            def get_navigation_items(self, req):
                yield 'metanav', 'test1', 'Test 1'
        class TestNavigationContributor2(Component):
            implements(INavigationContributor)
            def get_active_navigation_item(self, req):
                return None
            def get_navigation_items(self, req):
                yield 'metanav', 'test2', 'Test 2'
        env = EnvironmentStub(enable=[TestNavigationContributor1,
                                      TestNavigationContributor2])
        req = Mock(hdf=HDFWrapper(), href=Href('/trac.cgi'),
                   path_info='/', base_path='/trac.cgi')
        chrome = Chrome(env)

        # Test with both items set in the order option
        env.config.set('trac', 'metanav', 'test2, test1')
        chrome.populate_hdf(req, None)
        node = req.hdf.getObj('chrome.nav.metanav').child()
        self.assertEqual('test2', node.name())
        self.assertEqual('test1', node.next().name())

        # Test with only test1 in the order options
        req.hdf = HDFWrapper()
        env.config.set('trac', 'metanav', 'test1')
        chrome.populate_hdf(req, None)
        node = req.hdf.getObj('chrome.nav.metanav').child()
        self.assertEqual('test1', node.name())
        self.assertEqual('test2', node.next().name())

        # Test with only test2 in the order options
        req.hdf = HDFWrapper()
        env.config.set('trac', 'metanav', 'test2')
        chrome.populate_hdf(req, None)
        node = req.hdf.getObj('chrome.nav.metanav').child()
        self.assertEqual('test2', node.name())
        self.assertEqual('test1', node.next().name())

        # Test with none in the order options (order corresponds to
        # registration order)
        req.hdf = HDFWrapper()
        env.config.set('trac', 'metanav', 'foo, bar')
        chrome.populate_hdf(req, None)
        node = req.hdf.getObj('chrome.nav.metanav').child()
        self.assertEqual('test1', node.name())
        self.assertEqual('test2', node.next().name())
开发者ID:cyphactor,项目名称:lifecyclemanager,代码行数:52,代码来源:chrome.py

示例4: dispatch

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import populate_hdf [as 别名]
    def dispatch(self, req):
        """Find a registered handler that matches the request and let it process
        it.
        
        In addition, this method initializes the HDF data set and adds the web
        site chrome.
        """
        self.log.debug('Dispatching %r', req)
        chrome = Chrome(self.env)

        # Setup request callbacks for lazily-evaluated properties
        req.callbacks.update({
            'authname': self.authenticate,
            'chrome': chrome.prepare_request,
            'hdf': self._get_hdf,
            'perm': self._get_perm,
            'session': self._get_session,
            'tz': self._get_timezone,
            'form_token': self._get_form_token
        })

        try:
            try:
                # Select the component that should handle the request
                chosen_handler = None
                try:
                    for handler in self.handlers:
                        if handler.match_request(req):
                            chosen_handler = handler
                            break
                    if not chosen_handler:
                        if not req.path_info or req.path_info == '/':
                            chosen_handler = self.default_handler
                    # pre-process any incoming request, whether a handler
                    # was found or not
                    chosen_handler = self._pre_process_request(req,
                                                               chosen_handler)
                except TracError, e:
                    raise HTTPInternalError(e)
                if not chosen_handler:
                    if req.path_info.endswith('/'):
                        # Strip trailing / and redirect
                        target = req.path_info.rstrip('/').encode('utf-8')
                        if req.query_string:
                            target += '?' + req.query_string
                        req.redirect(req.href + target, permanent=True)
                    raise HTTPNotFound('No handler matched request to %s',
                                       req.path_info)

                req.callbacks['chrome'] = partial(chrome.prepare_request,
                                                  handler=chosen_handler)

                # Protect against CSRF attacks: we validate the form token for
                # all POST requests with a content-type corresponding to form
                # submissions
                if req.method == 'POST':
                    ctype = req.get_header('Content-Type')
                    if ctype:
                        ctype, options = cgi.parse_header(ctype)
                    if ctype in ('application/x-www-form-urlencoded',
                                 'multipart/form-data') and \
                            req.args.get('__FORM_TOKEN') != req.form_token:
                        raise HTTPBadRequest('Missing or invalid form token. '
                                             'Do you have cookies enabled?')

                # Process the request and render the template
                resp = chosen_handler.process_request(req)
                if resp:
                    if len(resp) == 2: # Clearsilver
                        chrome.populate_hdf(req)
                        template, content_type = \
                                  self._post_process_request(req, *resp)
                        # Give the session a chance to persist changes
                        req.session.save()
                        req.display(template, content_type or 'text/html')
                    else: # Genshi
                        template, data, content_type = \
                                  self._post_process_request(req, *resp)
                        if 'hdfdump' in req.args:
                            req.perm.require('TRAC_ADMIN')
                            # debugging helper - no need to render first
                            from pprint import pprint
                            out = StringIO()
                            pprint(data, out)
                            req.send(out.getvalue(), 'text/plain')
                        else:
                            output = chrome.render_template(req, template,
                                                            data, content_type)
                            # Give the session a chance to persist changes
                            req.session.save()
                            req.send(output, content_type or 'text/html')
                else:
                    self._post_process_request(req)
            except RequestDone:
                raise
            except:
                # post-process the request in case of errors
                err = sys.exc_info()
                try:
                    self._post_process_request(req)
#.........这里部分代码省略.........
开发者ID:twisted-infra,项目名称:twisted-trac-source,代码行数:103,代码来源:main.py

示例5: dispatch

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import populate_hdf [as 别名]
    def dispatch(self, req):
        """Find a registered handler that matches the request and let it process
        it.
        
        In addition, this method initializes the HDF data set and adds the web
        site chrome.
        """
        # FIXME: For backwards compatibility, should be removed in 0.11
        self.env.href = req.href
        # FIXME in 0.11: self.env.abs_href = Href(self.env.base_url)
        self.env.abs_href = req.abs_href

        # Select the component that should handle the request
        chosen_handler = None
        early_error = None
        req.authname = 'anonymous'
        req.perm = NoPermissionCache()
        try:
            if not req.path_info or req.path_info == '/':
                chosen_handler = self.default_handler
            else:
                for handler in self.handlers:
                    if handler.match_request(req):
                        chosen_handler = handler
                        break

            # Attach user information to the request early, so that
            # the IRequestFilter can see it while preprocessing
            if not getattr(chosen_handler, 'anonymous_request', False):
                try:
                    req.authname = self.authenticate(req)
                    req.perm = PermissionCache(self.env, req.authname)
                    req.session = Session(self.env, req)
                    req.form_token = self._get_form_token(req)
                except:
                    req.authname = 'anonymous'
                    req.perm = NoPermissionCache()
                    early_error = sys.exc_info()

            chosen_handler = self._pre_process_request(req, chosen_handler)
        except:
            early_error = sys.exc_info()
            
        if not chosen_handler and not early_error:
            early_error = (HTTPNotFound(u'Aucun composant ne peut gérer la '
                                        u'requète %s', req.path_info),
                           None, None)

        # Prepare HDF for the clearsilver template
        try:
            use_template = getattr(chosen_handler, 'use_template', True)
            req.hdf = None
            if use_template:
                chrome = Chrome(self.env)
                req.hdf = HDFWrapper(loadpaths=chrome.get_all_templates_dirs())
                populate_hdf(req.hdf, self.env, req)
                chrome.populate_hdf(req, chosen_handler)
        except:
            req.hdf = None # revert to sending plaintext error
            if not early_error:
                raise

        if early_error:
            try:
                self._post_process_request(req)
            except Exception, e:
                self.log.exception(e)
            raise early_error[0], early_error[1], early_error[2]
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:70,代码来源:main.py


注:本文中的trac.web.chrome.Chrome.populate_hdf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。