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


Python Chrome._add_form_token方法代码示例

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


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

示例1: expand_macro

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import _add_form_token [as 别名]
    def expand_macro(self, formatter, name, content, args=None):
        """
        Returns the outcome from macro.
        """
        req = formatter.context.req

        # Check permissions
        if 'TIMELINE_VIEW' not in req.perm:
            # Return default content / instructions
            return tag.div(
                tag.h2(_('Project team'), **{'class': 'title'}),
                tag.p(_('Project team cannot be found or no permission to follow it')),
                **{'class': 'watch'}
            )

        # Load project info from optional project argument. Defaults to current env
        project = Project.get(self.env)
        team, members = self._get_team_info(project)

        # Return rendered HTML with JS attached to it
        data = {
            'project_id': project.id,
            'env_name': self.env.project_identifier,
            'project_name': self.env.project_identifier,  # TODO: redundant
            'team': team,
            'members': members
        }

        # NOTE: Use fragment to not to recreate chrome (add_script does not work) and run post processing manually
        chrome = Chrome(self.env)
        stream = chrome.render_template(req, 'multiproject_team.html', data, fragment=True)
        if req.form_token:
            stream |= chrome._add_form_token(req.form_token)

        return stream
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:37,代码来源:team.py

示例2: expand_macro

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import _add_form_token [as 别名]
    def expand_macro(self, formatter, name, content, args=None):
        """
        Returns the outcome from macro.
        Supported arguments:

        - project: Name of the project to show status / provide follow buttons. Defaults to current project

        """
        req = formatter.req

        # Parse optional arguments
        if args is None:
            args = parse_args(content)
            if len(args) > 1:
                args = args[1]

        # Read optional project name - fallback to current
        project_name = self.env.project_identifier
        if args and 'project' in args:
            project_name = args.get('project', '').strip()

        # Load project id from db
        project_id = Project.get(env_name=project_name).id
        watchers, is_watching = self._get_status(req, project_id)

        # If user is already watching, do not show the block
        if is_watching:
            return tag.div('')

        # Show macro only when user has permission to view timeline
        if name not in self.macros or 'TIMELINE_VIEW' not in req.perm or not project_id:
            # Return default content / instructions
            return tag.div(
                tag.h2(_('Follow project'), **{'class': 'title'}),
                tag.p(_('Project cannot be found or no permission to follow it')),
                **{'class': 'watch'}
            )

        # For anonymous users, advice login/registering
        if req.authname == 'anonymous':
            return tag.div(
                tag.h2(_('Follow project'), **{'class': 'title'}),
                tag.p(_('Only registered users can follow the project activity. ')),
                tag.p(tag.a('Please login or register to service first', href=req.href('../home/user'))),
                **{'class': 'watch'}
            )

        # Return rendered HTML with JS attached to it
        data = {
            'project_id': project_id,
            'env_name': self.env.project_identifier,
            'project_name': project_name
        }

        chrome = Chrome(self.env)
        stream = chrome.render_template(req, 'multiproject_watch.html', data, fragment=True)
        if req.form_token:
            stream |= chrome._add_form_token(req.form_token)

        return stream
开发者ID:juhamust,项目名称:multiproject,代码行数:62,代码来源:watch.py

示例3: expand_macro

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import _add_form_token [as 别名]
    def expand_macro(self, formatter, name, content, args=None):
        """
        Returns the outcome from macro.
        Supported arguments:

        - project: Name of the project to show status / provide follow buttons. Defaults to current project

        """
        req = formatter.req

        # Load project from db
        project = Project.get(self.env)

        # Get project metadata (categories)
        (combined_categories, separated_categories_per_context, context_by_id,
         context_order, languages) = self._get_project_categories(project)

        # Get project visibility: public or private
        ug = CQDEUserGroupStore(project.trac_environment_key)
        visibility = _('Public') if ug.is_public_project() else _('Private')

        # Return rendered HTML with JS attached to it
        data = {
            '_project_': project,
            'combined_categories': combined_categories,
            'separated_categories_per_context': separated_categories_per_context,
            'context_order': context_order,
            'languages': languages,
            'context_by_id': context_by_id,
            'visibility_label': visibility, # Private / Public
            'to_web_time': to_web_time # TODO: Is this really required?
        }

        chrome = Chrome(self.env)
        stream = chrome.render_template(req, 'multiproject_summary.html', data, fragment=True)
        if req.form_token:
            stream |= chrome._add_form_token(req.form_token)
        return stream
开发者ID:juhamust,项目名称:multiproject,代码行数:40,代码来源:summary.py


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