當前位置: 首頁>>代碼示例>>Python>>正文


Python RhodeCodeSetting.get_by_name_or_create方法代碼示例

本文整理匯總了Python中rhodecode.model.db.RhodeCodeSetting.get_by_name_or_create方法的典型用法代碼示例。如果您正苦於以下問題:Python RhodeCodeSetting.get_by_name_or_create方法的具體用法?Python RhodeCodeSetting.get_by_name_or_create怎麽用?Python RhodeCodeSetting.get_by_name_or_create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rhodecode.model.db.RhodeCodeSetting的用法示例。


在下文中一共展示了RhodeCodeSetting.get_by_name_or_create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: from rhodecode.model.db import RhodeCodeSetting [as 別名]
# 或者: from rhodecode.model.db.RhodeCodeSetting import get_by_name_or_create [as 別名]
    def update(self, id):
        """PUT /defaults/id: Update an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="PUT" />
        # Or using helpers:
        #    h.form(url('default', id=ID),
        #           method='put')
        # url('default', id=ID)

        _form = DefaultsForm()()

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

        except formencode.Invalid, 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")
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:32,代碼來源:defaults.py

示例2: update

# 需要導入模塊: from rhodecode.model.db import RhodeCodeSetting [as 別名]
# 或者: from rhodecode.model.db.RhodeCodeSetting import get_by_name_or_create [as 別名]
    def update(self, setting_id):
        """PUT /admin/settings/setting_id: Update an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="PUT" />
        # Or using helpers:
        #    h.form(url('admin_setting', setting_id=ID),
        #           method='put')
        # url('admin_setting', setting_id=ID)

        if setting_id == 'mapping':
            rm_obsolete = request.POST.get('destroy', False)
            invalidate_cache = request.POST.get('invalidate', False)
            log.debug('rescanning repo location with destroy obsolete=%s'
                      % (rm_obsolete,))

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

            filesystem_repos = ScmModel().repo_scan()
            added, removed = repo2db_mapper(filesystem_repos, rm_obsolete)
            _repr = lambda l: ', '.join(map(safe_unicode, l)) or '-'
            h.flash(_('Repositories successfully '
                      'rescanned added: %s ; removed: %s') %
                    (_repr(added), _repr(removed)),
                    category='success')

        if setting_id == 'whoosh':
            repo_location = self._get_hg_ui_settings()['paths_root_path']
            full_index = request.POST.get('full_index', False)
            run_task(tasks.whoosh_index, repo_location, full_index)
            h.flash(_('Whoosh reindex task scheduled'), category='success')

        if setting_id == 'global':

            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"
                )

            try:
                sett1 = RhodeCodeSetting.get_by_name_or_create('title')
                sett1.app_settings_value = form_result['rhodecode_title']
                Session().add(sett1)

                sett2 = RhodeCodeSetting.get_by_name_or_create('realm')
                sett2.app_settings_value = form_result['rhodecode_realm']
                Session().add(sett2)

                sett3 = RhodeCodeSetting.get_by_name_or_create('ga_code')
                sett3.app_settings_value = form_result['rhodecode_ga_code']
                Session().add(sett3)

                Session().commit()
                set_rhodecode_config(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')
開發者ID:adamscieszko,項目名稱:rhodecode,代碼行數:72,代碼來源:settings.py


注:本文中的rhodecode.model.db.RhodeCodeSetting.get_by_name_or_create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。