##// END OF EJS Templates
makefiles: synced makefiles
makefiles: synced makefiles

File last commit:

r5093:525812a8 default
r5419:887a9753 default
Show More
defaults.py
101 lines | 3.5 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2016-2023 RhodeCode GmbH
admin-defaults: ported views to pyramid.
r2076 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
import formencode
import formencode.htmlfill
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render
from pyramid.response import Response
from rhodecode.apps._base import BaseAppView
from rhodecode.lib.auth import (
LoginRequired, HasPermissionAllDecorator, CSRFRequired)
from rhodecode.lib import helpers as h
from rhodecode.model.forms import DefaultsForm
from rhodecode.model.meta import Session
from rhodecode import BACKENDS
from rhodecode.model.settings import SettingsModel
log = logging.getLogger(__name__)
class AdminDefaultSettingsView(BaseAppView):
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
admin-defaults: ported views to pyramid.
r2076 def load_default_context(self):
c = self._get_local_tmpl_context()
return c
@LoginRequired()
@HasPermissionAllDecorator('hg.admin')
def defaults_repository_show(self):
c = self.load_default_context()
c.backends = BACKENDS.keys()
c.active = 'repositories'
defaults = SettingsModel().get_default_repo_settings()
data = render(
'rhodecode:templates/admin/defaults/defaults.mako',
self._get_template_context(c), self.request)
html = formencode.htmlfill.render(
data,
defaults=defaults,
encoding="UTF-8",
force_defaults=False
)
return Response(html)
@LoginRequired()
@HasPermissionAllDecorator('hg.admin')
@CSRFRequired()
def defaults_repository_update(self):
_ = self.request.translate
c = self.load_default_context()
c.active = 'repositories'
pylons: remove pylons as dependency...
r2351 form = DefaultsForm(self.request.translate)()
admin-defaults: ported views to pyramid.
r2076
try:
form_result = form.to_python(dict(self.request.POST))
python3: removed usage of .iteritems()
r4932 for k, v in form_result.items():
admin-defaults: ported views to pyramid.
r2076 setting = SettingsModel().create_or_update_setting(k, v)
Session().add(setting)
Session().commit()
h.flash(_('Default settings updated successfully'),
category='success')
except formencode.Invalid as errors:
data = render(
'rhodecode:templates/admin/defaults/defaults.mako',
self._get_template_context(c), self.request)
html = formencode.htmlfill.render(
data,
defaults=errors.value,
forms: fixed error handling in forms
r5018 errors=errors.unpack_errors() or {},
admin-defaults: ported views to pyramid.
r2076 prefix_error=False,
encoding="UTF-8",
force_defaults=False
)
return Response(html)
except Exception:
log.exception('Exception in update action')
h.flash(_('Error occurred during update of default values'),
category='error')
raise HTTPFound(h.route_path('admin_defaults_repositories'))