• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python keyword_substitution.substitute_keywords_with_data函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.keyword_substitution.substitute_keywords_with_data函数的典型用法代码示例。如果您正苦于以下问题:Python substitute_keywords_with_data函数的具体用法?Python substitute_keywords_with_data怎么用?Python substitute_keywords_with_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_subbing_no_userid_or_courseid

    def test_subbing_no_userid_or_courseid(self):
        """
        Tests that no subbing occurs if no user_id or no course_id is given.
        """
        test_string = 'This string should not be subbed here %%USER_ID%%'

        result = Ks.substitute_keywords_with_data(test_string, None, self.course.id)
        self.assertEqual(test_string, result)

        result = Ks.substitute_keywords_with_data(test_string, self.user.id, None)
        self.assertEqual(test_string, result)
开发者ID:JacobWay,项目名称:edx-platform,代码行数:11,代码来源:test_keyword_sub_utils.py


示例2: get_course_info_section

def get_course_info_section(request, course, section_key):
    """
    This returns the snippet of html to be rendered on the course info page,
    given the key for the section.

    Valid keys:
    - handouts
    - guest_handouts
    - updates
    - guest_updates
    """
    info_module = get_course_info_section_module(request, course, section_key)

    html = ''
    if info_module is not None:
        try:
            html = info_module.render(STUDENT_VIEW).content
            context = {
                'username': request.user.username,
                'user_id': request.user.id,
                'name': request.user.profile.name,
                'course_title': course.display_name,
                'course_id': course.id,
                'course_start_date': get_default_time_display(course.start),
                'course_end_date': get_default_time_display(course.end),
            }
            html = substitute_keywords_with_data(html, context)
        except Exception:  # pylint: disable=broad-except
            html = render_to_string('courseware/error-message.html', None)
            log.exception(
                u"Error rendering course=%s, section_key=%s",
                course, section_key
            )

    return html
开发者ID:caseylitton,项目名称:edx-platform,代码行数:35,代码来源:courses.py


示例3: _render

    def _render(format_string, message_body, context):
        """
        Create a text message using a template, message body and context.

        Convert message body (`message_body`) into an email message
        using the provided template.  The template is a format string,
        which is rendered using format() with the provided `context` dict.

        Any keywords encoded in the form %%KEYWORD%% found in the message
        body are substituted with user data before the body is inserted into
        the template.

        Output is returned as a unicode string.  It is not encoded as utf-8.
        Such encoding is left to the email code, which will use the value
        of settings.DEFAULT_CHARSET to encode the message.
        """

        # Substitute all %%-encoded keywords in the message body
        if 'user_id' in context and 'course_id' in context:
            message_body = substitute_keywords_with_data(message_body, context)

        result = format_string.format(**context)

        # Note that the body tag in the template will now have been
        # "formatted", so we need to do the same to the tag being
        # searched for.
        message_body_tag = COURSE_EMAIL_MESSAGE_BODY_TAG.format()
        result = result.replace(message_body_tag, message_body, 1)

        # finally, return the result, after wrapping long lines and without converting to an encoded byte array.
        return wrap_message(result)
开发者ID:Rosivania,项目名称:edx-platform,代码行数:31,代码来源:models.py


示例4: test_name_sub

    def test_name_sub(self):
        test_string = "This is the test string. subthis:  %%USER_FULLNAME%% into user name"
        user_name = self.user.profile.name
        result = Ks.substitute_keywords_with_data(test_string, self.user.id, self.course.id)

        self.assertNotIn('%%USER_FULLNAME%%', result)
        self.assertIn(user_name, result)
开发者ID:JacobWay,项目名称:edx-platform,代码行数:7,代码来源:test_keyword_sub_utils.py


示例5: test_course_name_sub

    def test_course_name_sub(self, test_info):
        """ Tests subbing course name in various scenarios """
        course_name = self.course.display_name
        result = Ks.substitute_keywords_with_data(test_info['test_string'], self.user.id, self.course.id)

        self.assertIn(course_name, result)
        self.assertEqual(result, test_info['expected'])
开发者ID:JacobWay,项目名称:edx-platform,代码行数:7,代码来源:test_keyword_sub_utils.py


示例6: test_subbing_no_userid_or_courseid

    def test_subbing_no_userid_or_courseid(self):
        """
        Tests that no subbing occurs if no user_id or no course_id is given.
        """
        test_string = 'This string should not be subbed here %%USER_ID%%'

        no_course_context = dict(
            (key, value) for key, value in self.context.iteritems() if key != 'course_title'
        )
        result = Ks.substitute_keywords_with_data(test_string, no_course_context)
        self.assertEqual(test_string, result)

        no_user_id_context = dict(
            (key, value) for key, value in self.context.iteritems() if key != 'user_id'
        )
        result = Ks.substitute_keywords_with_data(test_string, no_user_id_context)
        self.assertEqual(test_string, result)
开发者ID:189140879,项目名称:edx-platform,代码行数:17,代码来源:test_keyword_sub_utils.py


示例7: test_should_not_sub

    def test_should_not_sub(self):
        """
        Test that sub-ing doesn't work without subtags
        """
        test_string = "this string has no subtags"
        result = Ks.substitute_keywords_with_data(test_string, self.user.id, self.course.id)

        self.assertEquals(test_string, result)
开发者ID:JacobWay,项目名称:edx-platform,代码行数:8,代码来源:test_keyword_sub_utils.py


示例8: test_illegal_subtag

    def test_illegal_subtag(self):
        """
        Test that sub-ing doesn't ocurr with illegal tags
        """
        test_string = "%%user_id%%"
        result = Ks.substitute_keywords_with_data(test_string, self.user.id, self.course.id)

        self.assertEquals(test_string, result)
开发者ID:JacobWay,项目名称:edx-platform,代码行数:8,代码来源:test_keyword_sub_utils.py


示例9: test_anonymous_id_subs

    def test_anonymous_id_subs(self, test_info):
        """ Tests subbing anon user id in various scenarios """
        anon_id = '123456789'
        with patch.dict(Ks.KEYWORD_FUNCTION_MAP, {'%%USER_ID%%': lambda x, y: anon_id}):
            result = Ks.substitute_keywords_with_data(test_info['test_string'], self.user.id, self.course.id)

            self.assertIn(anon_id, result)
            self.assertEqual(result, test_info['expected'])
开发者ID:JacobWay,项目名称:edx-platform,代码行数:8,代码来源:test_keyword_sub_utils.py


示例10: test_sub_multiple_tags

    def test_sub_multiple_tags(self, test_info):
        """ Test that subbing works with multiple subtags """
        anon_id = '123456789'

        with patch('util.keyword_substitution.anonymous_id_from_user_id', lambda user_id: anon_id):
            result = Ks.substitute_keywords_with_data(
                test_info['test_string'], self.context,
            )
            self.assertEqual(result, test_info['expected'])
开发者ID:189140879,项目名称:edx-platform,代码行数:9,代码来源:test_keyword_sub_utils.py


示例11: test_course_name_sub

    def test_course_name_sub(self, test_string, expected):
        """ Tests subbing course name in various scenarios """
        course_name = self.course.display_name
        result = Ks.substitute_keywords_with_data(
            test_string, self.context,
        )

        self.assertIn(course_name, result)
        self.assertEqual(result, expected)
开发者ID:appsembler,项目名称:edx-platform,代码行数:9,代码来源:test_keyword_sub_utils.py


示例12: test_anonymous_id_sub

 def test_anonymous_id_sub(self):
     """
     Test that anonymous_id is subbed
     """
     test_string = "Turn %%USER_ID%% into anonymous id"
     anonymous_id = Ks.anonymous_id_from_user_id(self.user.id)
     result = Ks.substitute_keywords_with_data(
         test_string, self.context,
     )
     self.assertNotIn('%%USER_ID%%', result)
     self.assertIn(anonymous_id, result)
开发者ID:189140879,项目名称:edx-platform,代码行数:11,代码来源:test_keyword_sub_utils.py


示例13: test_name_sub

    def test_name_sub(self):
        """
        Test that the user's full name is correctly subbed
        """
        test_string = "This is the test string. subthis: %%USER_FULLNAME%% into user name"
        user_name = self.user.profile.name
        result = Ks.substitute_keywords_with_data(
            test_string, self.context,
        )

        self.assertNotIn('%%USER_FULLNAME%%', result)
        self.assertIn(user_name, result)
开发者ID:189140879,项目名称:edx-platform,代码行数:12,代码来源:test_keyword_sub_utils.py


示例14: test_no_subbing_empty_subtable

    def test_no_subbing_empty_subtable(self):
        """
        Test that no sub-ing occurs when the sub table is empty.
        """
        # Set the keyword sub mapping to be empty
        Ks.KEYWORD_FUNCTION_MAP = {}

        test_string = 'This user\'s name is %%USER_FULLNAME%%'
        result = Ks.substitute_keywords_with_data(test_string, self.user.id, self.course.id)

        self.assertNotIn(self.user.profile.name, result)
        self.assertIn('%%USER_FULLNAME%%', result)
开发者ID:JacobWay,项目名称:edx-platform,代码行数:12,代码来源:test_keyword_sub_utils.py


示例15: test_sub_mutiltple_tags

    def test_sub_mutiltple_tags(self, test_info):
        """ Test that subbing works with multiple subtags """
        anon_id = '123456789'
        patched_dict = {
            '%%USER_ID%%': lambda x, y: anon_id,
            '%%USER_FULLNAME%%': lambda x, y: self.user.profile.name,
            '%%COURSE_DISPLAY_NAME': lambda x, y: self.course.display_name,
            '%%COURSE_END_DATE': lambda x, y: get_default_time_display(self.course.end)
        }

        with patch.dict(Ks.KEYWORD_FUNCTION_MAP, patched_dict):
            result = Ks.substitute_keywords_with_data(test_info['test_string'], self.user.id, self.course.id)
            self.assertEqual(result, test_info['expected'])
开发者ID:JacobWay,项目名称:edx-platform,代码行数:13,代码来源:test_keyword_sub_utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python list_node.ListNode类代码示例发布时间:2022-05-26
下一篇:
Python jsonresult.get_result函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap