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


Python Fragment.add_css方法代码示例

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


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

示例1: create_fragment

# 需要导入模块: from web_fragments.fragment import Fragment [as 别名]
# 或者: from web_fragments.fragment.Fragment import add_css [as 别名]
 def create_fragment(self, content=None):
     """
     Create a fragment.
     """
     fragment = Fragment(content)
     fragment.add_css('body {background-color:red;}')
     fragment.add_javascript('alert("Hi!");')
     return fragment
开发者ID:mitodl,项目名称:edx-platform,代码行数:10,代码来源:test_xblock_utils.py

示例2: _staff_view

# 需要导入模块: from web_fragments.fragment import Fragment [as 别名]
# 或者: from web_fragments.fragment.Fragment import add_css [as 别名]
    def _staff_view(self, context):
        """
        Render the staff view for a split test module.
        """
        fragment = Fragment()
        active_contents = []
        inactive_contents = []

        for child_location in self.children:  # pylint: disable=no-member
            child_descriptor = self.get_child_descriptor_by_location(child_location)
            child = self.system.get_module(child_descriptor)
            rendered_child = child.render(STUDENT_VIEW, context)
            fragment.add_fragment_resources(rendered_child)
            group_name, updated_group_id = self.get_data_for_vertical(child)

            if updated_group_id is None:  # inactive group
                group_name = child.display_name
                updated_group_id = [g_id for g_id, loc in self.group_id_to_child.items() if loc == child_location][0]
                inactive_contents.append({
                    'group_name': _(u'{group_name} (inactive)').format(group_name=group_name),
                    'id': text_type(child.location),
                    'content': rendered_child.content,
                    'group_id': updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': text_type(child.location),
                'content': rendered_child.content,
                'group_id': updated_group_id,
            })

        # Sort active and inactive contents by group name.
        sorted_active_contents = sorted(active_contents, key=itemgetter('group_name'))
        sorted_inactive_contents = sorted(inactive_contents, key=itemgetter('group_name'))

        # Use the new template
        fragment.add_content(self.system.render_template('split_test_staff_view.html', {
            'items': sorted_active_contents + sorted_inactive_contents,
        }))
        fragment.add_css('.split-test-child { display: none; }')
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_staff.js'))
        fragment.initialize_js('ABTestSelector')
        return fragment
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:47,代码来源:split_test_module.py


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