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


Python ptah.register_settings函数代码示例

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


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

示例1: test_settings_group_multiple_validation

    def test_settings_group_multiple_validation(self):
        def validator1(fs, appstruct):
            raise ptah.form.Invalid('Error1', fs['node1'])

        def validator2(fs, appstruct):
            raise ptah.form.Invalid('Error2', fs['node2'])

        node1 = ptah.form.TextField(
            'node1',
            default = 'test')

        node2 = ptah.form.TextField(
            'node2',
            default = 'test')

        ptah.register_settings(
            'group3', node1, node2, validator=(validator1, validator2))

        self.init_ptah()

        group = ptah.get_settings('group3', self.registry)
        data, err = group.extract({
            'group3.node1': 'value',
            'group3.node2': 'value'})

        self.assertEqual(err.msg, {'group3': text_type(['Error1', 'Error2'])})
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:26,代码来源:test_settings.py

示例2: test_edit_form

    def test_edit_form(self):
        from ptah.manage.settings import SettingsModule, EditForm

        ptah.register_settings(
            'test',
            ptah.form.TextField('node1', default='test1', required=False),
            ptah.form.TextField('node2', default='test2', required=False),
            title = 'Test settings',
            ttw = True,
            ttw_skip_fields = ('node2',))

        self.init_ptah()

        mod = SettingsModule(None, self.request)
        grp = mod['test']
        settings = grp.group

        form = EditForm(grp, self.request)

        self.assertEqual(form.label, settings.__title__)
        self.assertEqual(form.description, settings.__description__)
        self.assertIs(form.form_content(), settings)

        fields = form.fields
        self.assertIn('node1', fields)
        self.assertNotIn('node2', fields)

        res = form.back_handler()
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '..')

        form.update_form()
        form.modify_handler()
        self.assertIn('Settings have been modified.',
                      self.request.render_messages())
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:35,代码来源:test_settings.py

示例3: test_settings_initialize_load_settings_include

    def test_settings_initialize_load_settings_include(self):
        from ptah.settings import init_settings

        path = os.path.join(self.dir, 'settings.cfg')
        f = open(path, 'wb')
        f.write(bytes_('[DEFAULT]\ngroup.node1 = value\n\n','ascii'))
        f.close()

        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.IntegerField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah()

        init_settings(self.config, {'include': path})

        group = ptah.get_settings('group', self.request.registry)

        self.assertEqual(group['node1'], 'value')
        self.assertEqual(group['node2'], 10)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:25,代码来源:test_settings.py

示例4: test_settings_export

    def test_settings_export(self):
        field1 = ptah.form.TextField(
            'node1',
            default = 'test')

        field2 = ptah.form.TextField(
            'node2',
            default = 'test1')

        ptah.register_settings('group4', field1, field2)
        self.init_ptah(initsettings=True)

        settings = get_settings_ob()

        # changed settings
        self.assertEqual(settings.export(), {})

        # default settings
        data = settings.export(default=True)
        self.assertIn('group4.node1', data)
        self.assertIn('group4.node2', data)
        self.assertEqual(data['group4.node1'], '"test"')
        self.assertEqual(data['group4.node2'], '"test1"')

        # changed settings
        group = ptah.get_settings('group4', self.registry)

        group['node2'] = 'changed'
        data = dict(settings.export())
        self.assertEqual(data['group4.node2'], '"changed"')
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:30,代码来源:test_settings.py

示例5: test_settings_initialize_load_preparer

    def test_settings_initialize_load_preparer(self):
        node1 = ptah.form.TextField(
            'node',
            default = 'default1',
            preparer = lambda s: s.lower())

        ptah.register_settings('group', node1)
        self.init_ptah()

        ptah.init_settings(self.config, {'group.node': 'Test'})

        group = ptah.get_settings('group', self.request.registry)
        self.assertEqual(group['node'], 'test')
开发者ID:runyaga,项目名称:ptah,代码行数:13,代码来源:test_settings.py

示例6: test_settings_load_defaults_rawdata_with_errors_in_values

    def test_settings_load_defaults_rawdata_with_errors_in_values(self):
        node = ptah.form.FloatField(
            'node1',
            default = ())

        ptah.register_settings('group', node)
        self.init_ptah(initsettings=True)

        self.assertRaises(
            ptah.config.StopException,
            get_settings_ob().init,
            self.config,
            {'group.node1': 'l,1'})
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:13,代码来源:test_settings.py

示例7: _create_default_group

    def _create_default_group(self):
        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.IntegerField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah(initsettings=True)

        return ptah.get_settings('group', self.registry)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:13,代码来源:test_settings.py

示例8: test_settings_group_uninitialized

    def test_settings_group_uninitialized(self):
        node = ptah.form.TextField(
            'node',
            default = 'test')

        ptah.register_settings(
            'group1', node,
            title = 'Section title',
            description = 'Section description',
            )
        self.init_ptah()

        group = ptah.get_settings('group1', self.registry)
        self.assertEqual(group.get('node'), 'test')
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:14,代码来源:test_settings.py

示例9: _make_grp

    def _make_grp(self):
        node1 = ptah.form.TextField(
            'node1',
            default = 'test')

        node2 = ptah.form.IntegerField(
            'node2',
            default = 50)

        ptah.register_settings(
            'group', node1, node2,
            title = 'Section title',
            description = 'Section description',
            )
        self.init_ptah()

        return ptah.get_settings('group', self.registry)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:17,代码来源:test_settings.py

示例10: test_settings_get_settings_pyramid

    def test_settings_get_settings_pyramid(self):
        node = ptah.form.TextField(
            'node',
            default = 'test')

        ptah.register_settings(
            'group1', node,
            title = 'Section title',
            description = 'Section description',
            )

        self.init_ptah()

        grp = self.config.ptah_get_settings('group1')
        self.assertIsNotNone(grp)
        self.assertEqual(grp.__name__, 'group1')
        self.assertIn(node, grp.__fields__.values())
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:17,代码来源:test_settings.py

示例11: test_settings_uri_resolver

    def test_settings_uri_resolver(self):
        node = ptah.form.TextField(
            'node',
            default = 'test')

        ptah.register_settings(
            'group', node,
            title = 'Section title',
            description = 'Section description',
            )
        self.init_ptah()

        grp1 = ptah.get_settings('group', self.registry)
        self.assertEqual(grp1.__uri__, 'settings:group')

        grp2 = ptah.resolve('settings:group')
        self.assertIs(grp1, grp2)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:17,代码来源:test_settings.py

示例12: test_settings_initialize_load_partly_defaults

    def test_settings_initialize_load_partly_defaults(self):
        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.TextField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah()

        ptah.init_settings(self.config, {'group.node1': 'setting from ini'})

        group = ptah.get_settings('group', self.request.registry)
        self.assertEqual(group['node1'], 'setting from ini')
        self.assertEqual(group['node2'], 10)
开发者ID:runyaga,项目名称:ptah,代码行数:17,代码来源:test_settings.py

示例13: test_settings_group_validation

    def test_settings_group_validation(self):
        def validator(node, appstruct):
            raise ptah.form.Invalid('Error', node['node'])

        node = ptah.form.TextField(
            'node',
            default = 'test')

        ptah.register_settings(
            'group2', node, validator=validator)

        self.init_ptah()

        group = ptah.get_settings('group2', self.registry)

        data, err = group.extract({'group2.node': 'value'})

        self.assertEqual(err.msg, {'group2': text_type(['Error'])})
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:18,代码来源:test_settings.py

示例14: test_settings_group_basics

    def test_settings_group_basics(self):
        node = ptah.form.TextField(
            'node',
            default = 'test')

        ptah.register_settings(
            'group1', node,
            title = 'Section title',
            description = 'Section description',
            )
        self.init_ptah()

        group = ptah.get_settings('group1', self.registry)
        self.assertEqual(group.keys(), ['node'])
        self.assertEqual(group.items(), [('node', 'test')])

        group.update({'node': '12345'})
        self.assertEqual(group.get('node'), '12345')
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:18,代码来源:test_settings.py

示例15: test_settings_initialize_load_defaults

    def test_settings_initialize_load_defaults(self):
        from ptah.settings import init_settings

        node1 = ptah.form.TextField(
            'node1',
            default = 'default1')

        node2 = ptah.form.TextField(
            'node2',
            default = 10)

        ptah.register_settings('group', node1, node2)
        self.init_ptah()

        init_settings(self.config, None)

        group = ptah.get_settings('group', self.request.registry)
        self.assertEqual(group['node1'], 'default1')
        self.assertEqual(group['node2'], 10)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:19,代码来源:test_settings.py


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