本文整理汇总了Python中kallithea.model.db.Setting.create_or_update方法的典型用法代码示例。如果您正苦于以下问题:Python Setting.create_or_update方法的具体用法?Python Setting.create_or_update怎么用?Python Setting.create_or_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.db.Setting
的用法示例。
在下文中一共展示了Setting.create_or_update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_settings
# 需要导入模块: from kallithea.model.db import Setting [as 别名]
# 或者: from kallithea.model.db.Setting import create_or_update [as 别名]
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()
示例2: settings_visual
# 需要导入模块: from kallithea.model.db import Setting [as 别名]
# 或者: from kallithea.model.db.Setting import create_or_update [as 别名]
def settings_visual(self):
c.active = 'visual'
if request.POST:
application_form = ApplicationVisualisationForm()()
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:
settings = [
('show_public_icon', 'show_public_icon', 'bool'),
('show_private_icon', 'show_private_icon', 'bool'),
('stylify_metatags', 'stylify_metatags', 'bool'),
('repository_fields', 'repository_fields', 'bool'),
('dashboard_items', 'dashboard_items', 'int'),
('admin_grid_items', 'admin_grid_items', 'int'),
('show_version', 'show_version', 'bool'),
('use_gravatar', 'use_gravatar', 'bool'),
('gravatar_url', 'gravatar_url', 'unicode'),
('clone_uri_tmpl', 'clone_uri_tmpl', 'unicode'),
]
for setting, form_key, type_ in settings:
Setting.create_or_update(setting, form_result[form_key], type_)
Session().commit()
set_app_settings(config)
h.flash(_('Updated visualisation settings'),
category='success')
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during updating '
'visualisation settings'),
category='error')
raise HTTPFound(location=url('admin_settings_visual'))
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)
示例3: update
# 需要导入模块: from kallithea.model.db import Setting [as 别名]
# 或者: from kallithea.model.db.Setting import create_or_update [as 别名]
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'))
示例4: auth_settings
# 需要导入模块: from kallithea.model.db import Setting [as 别名]
# 或者: from kallithea.model.db.Setting import create_or_update [as 别名]
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)
示例5: set_test_settings
# 需要导入模块: from kallithea.model.db import Setting [as 别名]
# 或者: from kallithea.model.db.Setting import create_or_update [as 别名]
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()