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

Python ptah.register_settings函数代码示例

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

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



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


示例16: test_settings_group_extract

    def test_settings_group_extract(self):
        node1 = ptah.form.TextField(
            'node1', default = 'test1')

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

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

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

        data, errors = group.extract({'group.node1': 'test-extract'})

        self.assertEqual(data['node1'], 'test-extract')
        self.assertEqual(data['node2'], 'test2')

        group['node2'] = 'value'
        data, errors = group.extract({'group.node1': 'test-extract'})
        self.assertEqual(data['node2'], 'value')
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:20,代码来源:test_settings.py


示例17: test_traverse_ttw

    def test_traverse_ttw(self):
        from ptah.manage.settings import SettingsModule, SettingsWrapper

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

        self.init_ptah()

        grp = ptah.get_settings('test', self.registry)
        mod = SettingsModule(None, self.request)

        self.assertRaises(
            KeyError,
            mod.__getitem__, 'test')

        grp.__ttw__ = True

        tgrp = mod['test']
        self.assertIs(tgrp.group, grp)
        self.assertIsInstance(tgrp, SettingsWrapper)
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:23,代码来源:test_settings.py


示例18: test_settings_register_simple

    def test_settings_register_simple(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(len(group.__fields__), 1)
        self.assertIn(node, group.__fields__.values())
        self.assertEqual(group['node'], 'test')
        self.assertRaises(
            KeyError,
            group.__getitem__, 'unknown')

        group.node = 'test2'
        self.assertFalse(group.node == group['node'])
开发者ID:rainerwahnsinn,项目名称:ptah,代码行数:24,代码来源:test_settings.py


示例19:

import ptah

ptah.register_settings(
    'ptah-minicms',

    ptah.form.TextField(
        'band',
        default = 'Primus',
        title = 'Favorite band',
        description = 'This is your favorite band.'),

    ptah.form.TextField(
        'happy',
        default = True,
        title = 'Are you happy?',
        description = 'Does Ptah bring you happiness?'),

    title = 'ptah_minicms settings',
    description = 'Configuration settings for ptah_minicms.'
    )
开发者ID:cguardia,项目名称:examples,代码行数:20,代码来源:settings.py


示例20: HTTPFound

        except:
            self.message(
                "Can't connect to target host. Please try again later.",'warning')
            token.service.remove(tid)
            return

        if data == 'success':
            return HTTPFound(location='http://%s/authToken?token=%s'%(host, tid))

        token.service.remove(tid)
        self.message("Login or password are wrong.")

    @form.button('Cancel')
    def cancelHandler(self):
        site = self.request.matchdict['site']
        return HTTPFound(location='http://%s'%site)


ptah.register_settings(
    'ploud-login',

    form.TextField(
        'backend',
        required = True,
        title = 'Backend server host.',
        default = '',
        ),

    title = 'Ploud login service'
)
开发者ID:enfold,项目名称:ploud.frontend,代码行数:30,代码来源:ssologin.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ptah.resolve函数代码示例发布时间:2022-05-25
下一篇:
Python ptah.get_settings函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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