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


Python db.Setting类代码示例

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


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

示例1: get_managed_fields

 def get_managed_fields(self):
     fields = ['username', 'password']
     if(Setting.get_by_name('auth_container_email_header').app_settings_value):
         fields.append('email')
     if(Setting.get_by_name('auth_container_firstname_header').app_settings_value):
         fields.append('firstname')
     if(Setting.get_by_name('auth_container_lastname_header').app_settings_value):
         fields.append('lastname')
     return fields
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:9,代码来源:auth_container.py

示例2: _set_settings

def _set_settings(*kvtseq):
    session = Session()
    for kvt in kvtseq:
        assert len(kvt) in (2, 3)
        k = kvt[0]
        v = kvt[1]
        t = kvt[2] if len(kvt) == 3 else 'unicode'
        Setting.create_or_update(k, v, t)
    session.commit()
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:9,代码来源:conftest.py

示例3: settings_global

    def settings_global(self):
        """GET /admin/settings/global: All items in the collection"""
        # url('admin_settings_global')
        c.active = 'global'
        if request.POST:
            application_form = ApplicationSettingsForm()()
            try:
                form_result = application_form.to_python(dict(request.POST))
            except formencode.Invalid, errors:
                return htmlfill.render(
                    render('admin/settings/settings.html'),
                    defaults=errors.value,
                    errors=errors.error_dict or {},
                    prefix_error=False,
                    encoding="UTF-8",
                    force_defaults=False)

            try:
                sett1 = Setting.create_or_update('title',
                                            form_result['title'])
                Session().add(sett1)

                sett2 = Setting.create_or_update('realm',
                                            form_result['realm'])
                Session().add(sett2)

                sett3 = Setting.create_or_update('ga_code',
                                            form_result['ga_code'])
                Session().add(sett3)

                sett4 = Setting.create_or_update('captcha_public_key',
                                    form_result['captcha_public_key'])
                Session().add(sett4)

                sett5 = Setting.create_or_update('captcha_private_key',
                                    form_result['captcha_private_key'])
                Session().add(sett5)

                Session().commit()
                set_app_settings(config)
                h.flash(_('Updated application settings'), category='success')

            except Exception:
                log.error(traceback.format_exc())
                h.flash(_('Error occurred during updating '
                          'application settings'),
                          category='error')

            return redirect(url('admin_settings_global'))
开发者ID:msabramo,项目名称:kallithea,代码行数:49,代码来源:settings.py

示例4: settings_system_update

    def settings_system_update(self):
        """GET /admin/settings/system/updates: All items in the collection"""
        # url('admin_settings_system_update')
        import json
        import urllib2
        from kallithea.lib.verlib import NormalizedVersion
        from kallithea import __version__

        defaults = Setting.get_app_settings()
        defaults.update(self._get_hg_ui_settings())
        _update_url = defaults.get('update_url', '')
        _update_url = "" # FIXME: disabled

        _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">%s</div>' % (s)
        try:
            import kallithea
            ver = kallithea.__version__
            log.debug('Checking for upgrade on `%s` server' % _update_url)
            opener = urllib2.build_opener()
            opener.addheaders = [('User-agent', 'Kallithea-SCM/%s' % ver)]
            response = opener.open(_update_url)
            response_data = response.read()
            data = json.loads(response_data)
        except urllib2.URLError, e:
            log.error(traceback.format_exc())
            return _err('Failed to contact upgrade server: %r' % e)
开发者ID:msabramo,项目名称:kallithea,代码行数:26,代码来源:settings.py

示例5: auth_settings

    def auth_settings(self):
        """POST create and store auth settings"""
        self.__load_defaults()
        _form = AuthSettingsForm(c.enabled_plugins)()
        log.debug("POST Result: %s" % formatted_json(dict(request.POST)))

        try:
            form_result = _form.to_python(dict(request.POST))
            for k, v in form_result.items():
                if k == 'auth_plugins':
                    # we want to store it comma separated inside our settings
                    v = ','.join(v)
                log.debug("%s = %s" % (k, str(v)))
                setting = Setting.create_or_update(k, v)
                Session().add(setting)
            Session().commit()
            h.flash(_('Auth settings updated successfully'),
                       category='success')
        except formencode.Invalid, errors:
            log.error(traceback.format_exc())
            e = errors.error_dict or {}
            return self.index(
                defaults=errors.value,
                errors=e,
                prefix_error=False)
开发者ID:msabramo,项目名称:kallithea,代码行数:25,代码来源:auth_settings.py

示例6: password_reset

    def password_reset(self):
        settings = Setting.get_app_settings()
        captcha_private_key = settings.get('captcha_private_key')
        c.captcha_active = bool(captcha_private_key)
        c.captcha_public_key = settings.get('captcha_public_key')

        if request.POST:
            password_reset_form = PasswordResetForm()()
            try:
                form_result = password_reset_form.to_python(dict(request.POST))
                if c.captcha_active:
                    from kallithea.lib.recaptcha import submit
                    response = submit(request.POST.get('recaptcha_challenge_field'),
                                      request.POST.get('recaptcha_response_field'),
                                      private_key=captcha_private_key,
                                      remoteip=self.ip_addr)
                    if c.captcha_active and not response.is_valid:
                        _value = form_result
                        _msg = _('bad captcha')
                        error_dict = {'recaptcha_field': _msg}
                        raise formencode.Invalid(_msg, _value, None,
                                                 error_dict=error_dict)
                UserModel().reset_password_link(form_result)
                h.flash(_('Your password reset link was sent'),
                            category='success')
                return redirect(url('login_home'))

            except formencode.Invalid, errors:
                return htmlfill.render(
                    render('/password_reset.html'),
                    defaults=errors.value,
                    errors=errors.error_dict or {},
                    prefix_error=False,
                    encoding="UTF-8",
                    force_defaults=False)
开发者ID:msabramo,项目名称:kallithea,代码行数:35,代码来源:login.py

示例7: __render

    def __render(self, defaults, errors):
        c.defaults = {}
        c.plugin_settings = {}
        c.plugin_shortnames = {}

        for plugin in self.enabled_plugins:
            module = plugin.__class__.__module__
            c.plugin_shortnames[module] = plugin.name
            c.plugin_settings[module] = plugin.plugin_settings()
            for v in c.plugin_settings[module]:
                fullname = "auth_%s_%s" % (plugin.name, v["name"])
                if "default" in v:
                    c.defaults[fullname] = v["default"]
                # Current values will be the default on the form, if there are any
                setting = Setting.get_by_name(fullname)
                if setting is not None:
                    c.defaults[fullname] = setting.app_settings_value
        # we want to show , separated list of enabled plugins
        c.defaults['auth_plugins'] = ','.join(c.enabled_plugin_names)

        if defaults:
            c.defaults.update(defaults)

        log.debug(formatted_json(defaults))
        return formencode.htmlfill.render(
            render('admin/auth/auth_settings.html'),
            defaults=c.defaults,
            errors=errors,
            prefix_error=False,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:31,代码来源:auth_settings.py

示例8: test_ldap_save_settings

    def test_ldap_save_settings(self):
        self.log_user()

        params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
        params.update({'auth_ldap_host': u'dc.example.com',
                       'auth_ldap_port': '999',
                       'auth_ldap_tls_kind': 'PLAIN',
                       'auth_ldap_tls_reqcert': 'NEVER',
                       'auth_ldap_cacertdir': '',
                       'auth_ldap_dn_user': 'test_user',
                       'auth_ldap_dn_pass': 'test_pass',
                       'auth_ldap_base_dn': 'test_base_dn',
                       'auth_ldap_filter': 'test_filter',
                       'auth_ldap_search_scope': 'BASE',
                       'auth_ldap_attr_login': 'test_attr_login',
                       'auth_ldap_attr_firstname': 'ima',
                       'auth_ldap_attr_lastname': 'tester',
                       'auth_ldap_attr_email': '[email protected]'})

        test_url = url(controller='admin/auth_settings',
                       action='auth_settings')

        response = self.app.post(url=test_url, params=params)
        self.checkSessionFlash(response, 'Auth settings updated successfully')

        new_settings = Setting.get_auth_settings()
        assert new_settings['auth_ldap_host'] == u'dc.example.com', 'fail db write compare'
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:27,代码来源:test_admin_auth_settings.py

示例9: settings_mapping

    def settings_mapping(self):
        """GET /admin/settings/mapping: All items in the collection"""
        # url('admin_settings_mapping')
        c.active = 'mapping'
        if request.POST:
            rm_obsolete = request.POST.get('destroy', False)
            install_git_hooks = request.POST.get('hooks', False)
            invalidate_cache = request.POST.get('invalidate', False)
            log.debug('rescanning repo location with destroy obsolete=%s and '
                      'install git hooks=%s' % (rm_obsolete,install_git_hooks))

            if invalidate_cache:
                log.debug('invalidating all repositories cache')
                for repo in Repository.get_all():
                    ScmModel().mark_for_invalidation(repo.repo_name, delete=True)

            filesystem_repos = ScmModel().repo_scan()
            added, removed = repo2db_mapper(filesystem_repos, rm_obsolete,
                                            install_git_hook=install_git_hooks,
                                            user=c.authuser.username)
            h.flash(h.literal(_('Repositories successfully rescanned. Added: %s. Removed: %s.') %
                (', '.join(h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name))
                 for repo_name in added) or '-',
                 ', '.join(h.escape(safe_unicode(repo_name)) for repo_name in removed) or '-')),
                category='success')
            return redirect(url('admin_settings_mapping'))

        defaults = Setting.get_app_settings()
        defaults.update(self._get_hg_ui_settings())

        return htmlfill.render(
            render('admin/settings/settings.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:msabramo,项目名称:kallithea,代码行数:35,代码来源:settings.py

示例10: update

    def update(self, id):
        _form = DefaultsForm()()

        try:
            form_result = _form.to_python(dict(request.POST))
            for k, v in form_result.iteritems():
                setting = Setting.create_or_update(k, v)
            Session().commit()
            h.flash(_('Default settings updated successfully'),
                    category='success')

        except formencode.Invalid as errors:
            defaults = errors.value

            return htmlfill.render(
                render('admin/defaults/defaults.html'),
                defaults=defaults,
                errors=errors.error_dict or {},
                prefix_error=False,
                encoding="UTF-8",
                force_defaults=False)
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('Error occurred during update of defaults'),
                    category='error')

        raise HTTPFound(location=url('defaults'))
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:27,代码来源:defaults.py

示例11: get_settings

 def get_settings(self):
     """Get plugin settings values."""
     plugin_settings = {}
     for v in self.plugin_settings():
         conf_key = "auth_%s_%s" % (self.name, v["name"])
         setting = Setting.get_by_name(conf_key)
         plugin_settings[v["name"]] = setting.app_settings_value if setting else None
     return plugin_settings
开发者ID:andrewshadura,项目名称:kallithea-auth-google,代码行数:8,代码来源:auth_google.py

示例12: settings_global

    def settings_global(self):
        c.active = 'global'
        if request.POST:
            application_form = ApplicationSettingsForm()()
            try:
                form_result = application_form.to_python(dict(request.POST))
            except formencode.Invalid as errors:
                return htmlfill.render(
                    render('admin/settings/settings.html'),
                    defaults=errors.value,
                    errors=errors.error_dict or {},
                    prefix_error=False,
                    encoding="UTF-8",
                    force_defaults=False)

            try:
                for setting in (
                    'title',
                    'realm',
                    'ga_code',
                    'captcha_public_key',
                    'captcha_private_key',
                ):
                    Setting.create_or_update(setting, form_result[setting])

                Session().commit()
                set_app_settings(config)
                h.flash(_('Updated application settings'), category='success')

            except Exception:
                log.error(traceback.format_exc())
                h.flash(_('Error occurred while updating '
                          'application settings'),
                          category='error')

            raise HTTPFound(location=url('admin_settings_global'))

        defaults = Setting.get_app_settings()
        defaults.update(self._get_hg_ui_settings())

        return htmlfill.render(
            render('admin/settings/settings.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:45,代码来源:settings.py

示例13: settings_system

    def settings_system(self):
        c.active = 'system'

        defaults = Setting.get_app_settings()
        defaults.update(self._get_hg_ui_settings())

        import kallithea
        c.ini = kallithea.CONFIG
        c.update_url = defaults.get('update_url')
        server_info = Setting.get_server_info()
        for key, val in server_info.iteritems():
            setattr(c, key, val)

        return htmlfill.render(
            render('admin/settings/settings.html'),
            defaults=defaults,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:18,代码来源:settings.py

示例14: set_test_settings

def set_test_settings():
    """Restore settings after test is over."""
    # Save settings.
    settings_snapshot = [
        (s.app_settings_name, s.app_settings_value, s.app_settings_type)
        for s in Setting.query().all()]
    yield _set_settings
    # Restore settings.
    session = Session()
    keys = frozenset(k for (k, v, t) in settings_snapshot)
    for s in Setting.query().all():
        if s.app_settings_name not in keys:
            session.delete(s)
    for k, v, t in settings_snapshot:
        if t == 'list' and hasattr(v, '__iter__'):
            v = ','.join(v) # Quirk: must format list value manually.
        Setting.create_or_update(k, v, t)
    session.commit()
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:18,代码来源:conftest.py

示例15: index

    def index(self, defaults=None, errors=None, prefix_error=False):
        self.__load_defaults()
        _defaults = {}
        # default plugins loaded
        formglobals = {
            "auth_plugins": ["kallithea.lib.auth_modules.auth_internal"]
        }
        formglobals.update(Setting.get_auth_settings())
        formglobals["plugin_settings"] = {}
        formglobals["auth_plugins_shortnames"] = {}
        _defaults["auth_plugins"] = formglobals["auth_plugins"]

        for module in formglobals["auth_plugins"]:
            plugin = auth_modules.loadplugin(module)
            plugin_name = plugin.name
            formglobals["auth_plugins_shortnames"][module] = plugin_name
            formglobals["plugin_settings"][module] = plugin.plugin_settings()
            for v in formglobals["plugin_settings"][module]:
                fullname = ("auth_" + plugin_name + "_" + v["name"])
                if "default" in v:
                    _defaults[fullname] = v["default"]
                # Current values will be the default on the form, if there are any
                setting = Setting.get_by_name(fullname)
                if setting:
                    _defaults[fullname] = setting.app_settings_value
        # we want to show , separated list of enabled plugins
        _defaults['auth_plugins'] = ','.join(_defaults['auth_plugins'])
        if defaults:
            _defaults.update(defaults)

        formglobals["defaults"] = _defaults
        # set template context variables
        for k, v in formglobals.iteritems():
            setattr(c, k, v)

        log.debug(pprint.pformat(formglobals, indent=4))
        log.debug(formatted_json(defaults))
        return formencode.htmlfill.render(
            render('admin/auth/auth_settings.html'),
            defaults=_defaults,
            errors=errors,
            prefix_error=prefix_error,
            encoding="UTF-8",
            force_defaults=False)
开发者ID:msabramo,项目名称:kallithea,代码行数:44,代码来源:auth_settings.py


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