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

Python ptah.get_settings函数代码示例

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

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



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

示例1: initialized

def initialized(ev):
    PTAH = ptah.get_settings(ptah.CFG_ID_PTAH, ev.registry)

    # mail
    PTAH['Mailer'] = DummyMailer()
    PTAH['full_email_address'] = formataddr(
        (PTAH['email_from_name'], PTAH['email_from_address']))

    # sqla
    SQLA = ptah.get_settings(ptah.CFG_ID_SQLA, ev.registry)
    url = SQLA['url']
    if url:
        engine_args = {}
        if SQLA['cache']:
            cache = {}
            engine_args['execution_options'] = \
                {'compiled_cache': cache}
            SQLA['sqlalchemy_cache'] = cache
        try:
            engine = sqlahelper.get_engine()
        except: # pragma: no cover
            engine = sqlalchemy.engine_from_config(
                {'sqlalchemy.url': url}, 'sqlalchemy.', **engine_args)
            sqlahelper.add_engine(engine)

    # ptah manage
    if PTAH['manage']:
        ev.config.add_route(
            'ptah-manage', '/ptah-manage/*traverse',
            factory=ptah.manage.PtahManageRoute, use_global_views=True)
        ptah.manage.set_access_manager(
            ptah.manage.PtahAccessManager())
开发者ID:runyaga,项目名称:ptah,代码行数:32,代码来源:ptahsettings.py


示例2: initialized

def initialized(ev):
    global maintence
    PLOUD = ptah.get_settings("ploud", ev.registry)
    APACHE = ptah.get_settings("apache", ev.registry)
    if PLOUD["maintenance"]:
        maintence = Maintenance(APACHE["host"])
        logger.info("Maintenance worker has been started.")
    else:
        maintence = None
开发者ID:enfold,项目名称:ploud.utils,代码行数:9,代码来源:maintenance.py


示例3: send_activation

def send_activation(email, token):
    mail_template = renderers.get_renderer(
        'newui/validate_email.txt').implementation()

    MAIL = ptah.get_settings(ptah.CFG_ID_PTAH)
    FRONTEND = ptah.get_settings('frontend')

    data = dict(host=FRONTEND['host'], email=email, token=token)
    msg = MIMEText(str(mail_template(**data)))
    msg['Subject'] = 'Activate Your Ploud Account'
    msg['From'] = FRONTEND['email_from']
    msg['To'] = email

    MAIL['Mailer'].send(FRONTEND['email_from'], email, msg)
开发者ID:enfold,项目名称:ploud.frontend,代码行数:14,代码来源:signup.py


示例4: send_new_password_email

def send_new_password_email(email, token):
    MAIL = ptah.get_settings(ptah.CFG_ID_PTAH)
    FRONTEND = ptah.get_settings('frontend')

    data = dict(host=FRONTEND['host'], email=email, token=token)

    text = renderers.render('ploud.frontend:newui/reset_password.txt', data)

    msg = MIMEText(text.encode('utf-8'))
    msg['Subject'] = "You've Reset Your Ploud Password"
    msg['From'] = FRONTEND['email_from']
    msg['To'] = email

    MAIL['Mailer'].send(FRONTEND['email_from'], email, msg)
开发者ID:enfold,项目名称:ploud.frontend,代码行数:14,代码来源:login.py


示例5: create

    def create(self):
        data, errors = self.extract()

        if errors:
            self.message(errors, "form-error")
            return

        # create user
        cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.request.registry)
        tp = cfg["type"]
        if not tp.startswith("type:"):
            tp = "type:{0}".format(tp)

        tinfo = ptah.resolve(tp)

        user = tinfo.create(
            name=data["name"],
            login=data["login"],
            email=data["login"],
            validated=data["validated"],
            suspended=data["suspended"],
        )
        user.password = ptah.pwd_tool.encode(data["password"])

        tinfo.add(user)

        # notify system
        self.request.registry.notify(ptah.events.PrincipalAddedEvent(user))

        self.message("User has been created.", "success")
        return HTTPFound(location=".")
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:31,代码来源:user.py


示例6: test_manage_disable_modules_traverse

    def test_manage_disable_modules_traverse(self):
        from ptah.manage.manage import \
            module, PtahModule, PtahManageRoute, set_access_manager

        @module('test-module')
        class TestModule(PtahModule):
            """ module description """

            title = 'Test module'

        def accessManager(id, request):
            return True

        self.init_ptah()

        set_access_manager(accessManager)
        ptah.auth_service.set_userid('test-user')

        cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry)
        cfg['disable_modules'] = ('test-module',)

        request = DummyRequest()
        route = PtahManageRoute(request)

        self.assertRaises(KeyError, route.__getitem__, 'test-module')
开发者ID:runyaga,项目名称:ptah,代码行数:25,代码来源:test_manage.py


示例7: test_validation_auth_checker_validation

    def test_validation_auth_checker_validation(self):
        from ptahcrowd.validation import validationAndSuspendedChecker

        principal = Principal('1', 'user', '[email protected]')

        cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD)

        # validation disabled
        info = AuthInfo(principal, True)
        cfg['validation'] = False
        self.assertTrue(validationAndSuspendedChecker(info))

        info = AuthInfo(principal, True)
        cfg['allow-unvalidated'] = False
        self.assertTrue(validationAndSuspendedChecker(info))

        # validation enabled
        info = AuthInfo(principal, True)
        cfg['validation'] = True
        cfg['allow-unvalidated'] = False
        self.assertFalse(validationAndSuspendedChecker(info))
        self.assertEqual(info.message, 'Account is not validated.')

        info = AuthInfo(principal, True)
        cfg['allow-unvalidated'] = True
        self.assertTrue(validationAndSuspendedChecker(info))

        # validated
        principal.validated = True

        info = AuthInfo(principal, True)
        cfg['validation'] = True
        self.assertTrue(validationAndSuspendedChecker(info))
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:33,代码来源:test_validation.py


示例8: register_handler

    def register_handler(self):
        data, errors = self.extract()
        if errors:
            self.add_error_message(errors)
            return

        user = self.create(data)
        self.request.registry.notify(PrincipalRegisteredEvent(user))
        self.cfg = ptah.get_settings(CFG_ID_CROWD, self.request.registry)
        # validation
        if self.cfg['validation']:
            initiate_email_validation(user, self.request)
            self.request.add_message('Validation email has been sent.')
            if not self.cfg['allow-unvalidated']:
                return HTTPFound(location=self.request.application_url)

        # authenticate
        info = ptah.auth_service.authenticate(
            {'login': user.username, 'password': user.password})
        if info.status:
            headers = security.remember(self.request, info.__uri__)
            return HTTPFound(
                location='%s/login-success.html'%self.request.application_url,
                headers = headers)
        else:
            self.request.add_message(info.message) # pragma: no cover
开发者ID:djedproject,项目名称:ptahcrowd,代码行数:26,代码来源:registration.py


示例9: 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


示例10: create

    def create(self):
        data, errors = self.extract()

        if errors:
            self.add_error_message(errors)
            return

        # create user
        cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.request.registry)
        tp = cfg['type']
        if not tp.startswith('type:'):
            tp = 'type:{0}'.format(tp)

        tinfo = ptah.resolve(tp)

        user = tinfo.create(
            fullname=data['fullname'], username=data['username'], email=data['email'],
            validated=data['validated'], suspended=data['suspended'])
        user.password = ptah.pwd_tool.encode(data['password'])

        tinfo.add(user)

        # notify system
        self.request.registry.notify(ptah.events.PrincipalAddedEvent(user))

        self.request.add_message('User has been created.', 'success')
        return HTTPFound(location='.')
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:27,代码来源:user.py


示例11: test_manage_disable_modules

    def test_manage_disable_modules(self):
        from ptah.manage.manage import module, PtahModule, PtahManageRoute, ManageView, set_access_manager

        @module("test-module")
        class TestModule(PtahModule):
            """ module description """

            title = "Test module"

        def accessManager(id, request):
            return True

        self.init_ptah()

        set_access_manager(accessManager)
        ptah.auth_service.set_userid("test-user")

        cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry)
        cfg["disable_modules"] = ("test-module",)

        request = DummyRequest()
        route = PtahManageRoute(request)

        view = ManageView(route, request)
        view.update()

        for mod in view.modules:
            self.assertFalse(isinstance(mod, TestModule))
开发者ID:webmaven,项目名称:ptah,代码行数:28,代码来源:test_manage.py


示例12: render_amd_includes

def render_amd_includes(request, spec='', bundles=()):
    registry = request.registry
    cfg = ptah.get_settings(ptah.CFG_ID_PTAH, request.registry)

    ptah.include(request, 'curl')

    c_tmpls = []
    if spec and cfg['amd-spec-enabled']:
        specstorage = request.registry.get(ID_AMD_SPEC, {})
        specdata = specstorage.get(spec)
        if specdata is None:
            raise RuntimeError("Spec '%s' is not found."%spec)
    else:
        spec = '_'
        specdata = ()

    for name in (bundles if not isinstance(bundles, str) else (bundles,)):
        name = '%s.js'%name
        if name in specdata:
            c_tmpls.append(
                '<script src="%s"></script>'%
                request.route_url('ptah-amd-spec',specname=spec,name=name))

    return amd_incl%{'app_url': request.application_url,
                     'specname': spec,
                     'components': '\n'.join(c_tmpls)}
开发者ID:webmaven,项目名称:ptah,代码行数:26,代码来源:amd.py


示例13: rebalance

def rebalance():
    ploud_config.initializeConfig()
    APACHE = ptah.get_settings('apache')
    file = APACHE['lbfile']
    processes = APACHE['processes']

    conn = ploud_config.PLOUD_POOL.getconn()
    c1 = conn.cursor()

    c1.execute("SELECT vhost.host,sites.bwin,sites.bwout,sites.site_name FROM vhost, sites "
               "WHERE vhost.id = sites.id and sites.disabled = %s ORDER by sites.id",(False,))

    db = bsddb.hashopen(file, 'w')

    data = [(bwin+bwout, host, name) for host, bwin, bwout, name in c1.fetchall()]
    data.sort()

    i = 1
    for size, host, name in data:
        db[host] = str(i)
        db[name] = str(i)
        i = i + 1
        if i > processes:
            i = 1

    print 'Rebalancing is done.'

    db.close()

    c1.close()
    conn.close()
开发者ID:enfold,项目名称:ploud.utils,代码行数:31,代码来源:routing.py


示例14: initialized

def initialized(ev):
    global PLOUD_DSN, CLIENTS_DSN
    global PLOUD_POOL, CLIENTS_POOL
    def parse_dsn(s):
        params = {}
        s = s.split('//', 1)[-1]

        if '@' in s:
            head, tail = s.split('@', 1)
            user, passwd = head.split(':', 1)
            host, dbname = tail.split('/', 1)
        else:
            user = passwd = host = dbname = ''

        params['user'] = user
        params['password'] = passwd
        params['host'] = host
        params['database'] = dbname
        return params

    PLOUD = ptah.get_settings('ploud', ev.registry)
    PLOUD_DSN = parse_dsn(PLOUD['dsn'])
    CLIENTS_DSN = parse_dsn(PLOUD['clientsdsn'])

    # Init ploud connections pool
    PLOUD_POOL = psycopg2.pool.ThreadedConnectionPool(0, 8, **PLOUD_DSN)
    CLIENTS_POOL = psycopg2.pool.ThreadedConnectionPool(0, 10, **CLIENTS_DSN)
开发者ID:enfold,项目名称:ploud.utils,代码行数:27,代码来源:ploud_config.py


示例15: get_user_type

def get_user_type(registry=None):
    cfg = ptah.get_settings(CFG_ID_CROWD, registry)
    tp = cfg["type"]
    if not tp.startswith("type:"):
        tp = "type:{0}".format(tp)

    return ptah.resolve(tp)
开发者ID:rainerwahnsinn,项目名称:ptahcrowd,代码行数:7,代码来源:provider.py


示例16: test_join_unvalidated

    def test_join_unvalidated(self):
        import ptahcrowd
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        CROWD = ptah.get_settings(ptahcrowd.CFG_ID_CROWD)
        CROWD['allow-unvalidated'] = False

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        form = Registration(None, request)
        form.update_form()
        res = form.register_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], 'http://example.com')

        user = ptah.auth_service.get_principal_bylogin('[email protected]')
        self.assertIsInstance(user, CrowdUser)
        self.assertEqual(user.username, 'test')

        self.assertIn('Validation email has been sent.',
                      request.render_messages())
开发者ID:djedproject,项目名称:ptahcrowd,代码行数:30,代码来源:test_join.py


示例17: test_join

    def test_join(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.registration import Registration

        user = CrowdUser(username='username', email='email')
        ptah.get_session().add(user)
        ptah.get_session().flush()

        class Stub(object):
            status = ''
            def send(self, frm, to, msg):
                Stub.status = 'Email has been sended'

        MAIL = ptah.get_settings(ptah.CFG_ID_PTAH)
        MAIL['mailer'] = Stub()

        request = self.make_request(
            POST = {'username': 'test',
                    'email': '[email protected]',
                    'password': '12345',
                    'confirm_password': '12345'})
        request.environ['HTTP_HOST'] = 'example.com'

        form = Registration(None, request)
        form.update_form()
        res = form.register_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'],
                         'http://example.com/login-success.html')

        user = ptah.auth_service.get_principal_bylogin('[email protected]')
        self.assertIsInstance(user, CrowdUser)
        self.assertEqual(user.name, 'test')
开发者ID:ptahproject,项目名称:ptahcrowd,代码行数:34,代码来源:test_join.py


示例18: test_manage_access_manager_role

    def test_manage_access_manager_role(self):
        from ptah.manage.manage import PtahAccessManager

        class Principal(object):
            id = "test-user"
            login = "[email protected]"

        principal = Principal()

        @ptah.resolver("test")
        def principalResolver(uri):
            return principal

        self.init_ptah()

        orig_lr = ptah.get_local_roles

        def get_lr(userid, request, context):
            if userid == "test:user":
                return ("Manager",)
            return ()

        ptah.get_local_roles = get_lr

        cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry)
        cfg["manager_role"] = "Manager"

        self.assertTrue(PtahAccessManager()("test:user", self.request))
        self.assertFalse(PtahAccessManager()("test:user2", self.request))

        ptah.get_local_roles = orig_lr
开发者ID:webmaven,项目名称:ptah,代码行数:31,代码来源:test_manage.py


示例19: test_manage_enable_modules_traverse

    def test_manage_enable_modules_traverse(self):
        from ptah.manage.manage import module, PtahModule, PtahManageRoute, set_access_manager

        @module("test-module1")
        class TestModule1(PtahModule):
            title = "Test module1"

        @module("test-module2")
        class TestModule2(PtahModule):
            title = "Test module2"

        def accessManager(id, request):
            return True

        self.init_ptah()

        set_access_manager(accessManager)
        ptah.auth_service.set_userid("test-user")

        cfg = ptah.get_settings(ptah.CFG_ID_PTAH, self.registry)
        cfg["enable_modules"] = ("test-module1",)

        request = DummyRequest()
        route = PtahManageRoute(request)

        self.assertIsNotNone(route["test-module1"])
        self.assertRaises(KeyError, route.__getitem__, "test-module2")
开发者ID:webmaven,项目名称:ptah,代码行数:27,代码来源:test_manage.py


示例20: list_models

    def list_models(self):
        cfg = ptah.get_settings(ptah.CFG_ID_PTAH)
        disabled = cfg['disable_models']

        types = []
        for ti in ptah.get_types().values():
            types.append(
                {'name': ti.__uri__,
                 'title': ti.title,
                 'description': ti.description,
                 'disabled': ti.__uri__ in disabled,
                 'cls': ti.cls})

        for ti in sorted(types, key=lambda item:item['name']):
            print (grpTitleWrap.fill(
                    '{name}: {title} (disabled: {disabled})'.format(**ti)))
            if ti['description']:
                print (grpDescriptionWrap.fill(ti['description']))
            print('')

            cls = ti['cls']
            print(grpDescriptionWrap.fill('class: {0}'.format(cls.__name__)))
            print(grpDescriptionWrap.fill('module: {0}'.format(cls.__module__)))
            print('    file: ', sys.modules[cls.__module__].__file__)
            print('\n')
开发者ID:carlicos,项目名称:ptah,代码行数:25,代码来源:manage.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ptah.register_settings函数代码示例发布时间:2022-05-25
下一篇:
Python ptah.get_session函数代码示例发布时间: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