Mercurial > kallithea
changeset 388:3bcf9529d221
Added new application settings,Push ssl and repositories path
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 05 Aug 2010 22:31:23 +0200 |
parents | 2a18192fbd1e |
children | 174785aa5dc4 |
files | pylons_app/config/environment.py pylons_app/controllers/admin/settings.py pylons_app/lib/utils.py pylons_app/model/forms.py pylons_app/templates/admin/settings/settings.html |
diffstat | 5 files changed, 142 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/pylons_app/config/environment.py Thu Aug 05 01:31:01 2010 +0200 +++ b/pylons_app/config/environment.py Thu Aug 05 22:31:23 2010 +0200 @@ -61,6 +61,7 @@ sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') init_model(sa_engine_db1) + #init baseui config['pylons.app_globals'].baseui = make_ui('db') repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial))
--- a/pylons_app/controllers/admin/settings.py Thu Aug 05 01:31:01 2010 +0200 +++ b/pylons_app/controllers/admin/settings.py Thu Aug 05 22:31:23 2010 +0200 @@ -32,9 +32,10 @@ HasPermissionAnyDecorator from pylons_app.lib.base import BaseController, render from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \ - set_hg_app_config, get_hg_settings -from pylons_app.model.db import User, UserLog, HgAppSettings -from pylons_app.model.forms import UserForm, ApplicationSettingsForm + set_hg_app_config, get_hg_settings, get_hg_ui_settings, make_ui +from pylons_app.model.db import User, UserLog, HgAppSettings, HgAppUi +from pylons_app.model.forms import UserForm, ApplicationSettingsForm, \ + ApplicationUiSettingsForm from pylons_app.model.hg_model import HgModel from pylons_app.model.user_model import UserModel import formencode @@ -65,7 +66,7 @@ # url('admin_settings') defaults = get_hg_settings() - + defaults.update(get_hg_ui_settings()) return htmlfill.render( render('admin/settings/settings.html'), defaults=defaults, @@ -108,10 +109,12 @@ form_result = application_form.to_python(dict(request.POST)) try: - hgsettings1 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'title').one() + hgsettings1 = self.sa.query(HgAppSettings)\ + .filter(HgAppSettings.app_settings_name == 'title').one() hgsettings1.app_settings_value = form_result['hg_app_title'] - hgsettings2 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'realm').one() + hgsettings2 = self.sa.query(HgAppSettings)\ + .filter(HgAppSettings.app_settings_name == 'realm').one() hgsettings2.app_settings_value = form_result['hg_app_realm'] @@ -137,6 +140,46 @@ errors=errors.error_dict or {}, prefix_error=False, encoding="UTF-8") + + if setting_id == 'mercurial': + application_form = ApplicationUiSettingsForm()() + try: + form_result = application_form.to_python(dict(request.POST)) + + try: + + hgsettings1 = self.sa.query(HgAppUi)\ + .filter(HgAppUi.ui_key == 'push_ssl').one() + hgsettings1.ui_value = form_result['web_push_ssl'] + + hgsettings2 = self.sa.query(HgAppUi)\ + .filter(HgAppUi.ui_key == '/').one() + hgsettings2.ui_value = form_result['paths_root_path'] + + self.sa.add(hgsettings1) + self.sa.add(hgsettings2) + self.sa.commit() + + h.flash(_('Updated application settings'), + category='success') + + except: + log.error(traceback.format_exc()) + h.flash(_('error occured during updating application settings'), + category='error') + + self.sa.rollback() + + + 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") + + return redirect(url('admin_settings'))
--- a/pylons_app/lib/utils.py Thu Aug 05 01:31:01 2010 +0200 +++ b/pylons_app/lib/utils.py Thu Aug 05 22:31:23 2010 +0200 @@ -112,6 +112,23 @@ return settings +def get_hg_ui_settings(): + try: + sa = meta.Session + ret = sa.query(HgAppUi).all() + finally: + meta.Session.remove() + + if not ret: + raise Exception('Could not get application ui settings !') + settings = {} + for each in ret: + k = each.ui_key if each.ui_key != '/' else 'root_path' + settings[each.ui_section + '_' + k] = each.ui_value + + return settings + +#propagated from mercurial documentation ui_sections = ['alias', 'auth', 'decode/encode', 'defaults', 'diff', 'email', @@ -132,27 +149,27 @@ @param checkpaths: check the path @param read_from: read from 'file' or 'db' """ - #propagated from mercurial documentation baseui = ui.ui() - if read_from == 'file': if not os.path.isfile(path): log.warning('Unable to read config file %s' % path) return False - + log.debug('reading hgrc from %s', path) cfg = config.config() cfg.read(path) for section in ui_sections: for k, v in cfg.items(section): baseui.setconfig(section, k, v) + log.debug('settings ui from file[%s]%s:%s', section, k, v) if checkpaths:check_repo_dir(cfg.items('paths')) elif read_from == 'db': hg_ui = get_hg_ui_cached() for ui_ in hg_ui: + log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value) baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
--- a/pylons_app/model/forms.py Thu Aug 05 01:31:01 2010 +0200 +++ b/pylons_app/model/forms.py Thu Aug 05 22:31:23 2010 +0200 @@ -25,7 +25,6 @@ from pylons import session from pylons.i18n.translation import _ from pylons_app.lib.auth import get_crypt_password -import pylons_app.lib.helpers as h from pylons_app.model import meta from pylons_app.model.db import User, Repository from sqlalchemy.exc import OperationalError @@ -34,6 +33,8 @@ import datetime import formencode import logging +import os +import pylons_app.lib.helpers as h log = logging.getLogger(__name__) @@ -218,7 +219,21 @@ if value.has_key('user'): del['value']['user'] - return value + return value + +class ValidPath(formencode.validators.FancyValidator): + def to_python(self, value, state): + isdir = os.path.isdir(value.replace('*', '')) + if (value.endswith('/*') or value.endswith('/**')) and isdir: + return value + elif not isdir: + msg = _('This is not a valid path') + else: + msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)') + + raise formencode.Invalid(msg, value, state, + error_dict={'paths_root_path':msg}) + #=============================================================================== # FORMS #=============================================================================== @@ -302,5 +317,12 @@ return _ApplicationSettingsForm +def ApplicationUiSettingsForm(): + class _ApplicationUiSettingsForm(formencode.Schema): + allow_extra_fields = True + filter_extra_fields = False + web_push_ssl = OneOf(['true', 'false'], if_missing='false') + paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=3, not_empty=True)) + + return _ApplicationUiSettingsForm -
--- a/pylons_app/templates/admin/settings/settings.html Thu Aug 05 01:31:01 2010 +0200 +++ b/pylons_app/templates/admin/settings/settings.html Thu Aug 05 22:31:23 2010 +0200 @@ -57,7 +57,7 @@ <div class="field"> <div class="label"> - <label for="input-small">${_('Application name')}:</label> + <label for="hg_app_title">${_('Application name')}:</label> </div> <div class="input"> ${h.text('hg_app_title',size=30)} @@ -66,7 +66,7 @@ <div class="field"> <div class="label"> - <label for="input-small">${_('Realm text')}:</label> + <label for="hg_app_realm">${_('Realm text')}:</label> </div> <div class="input"> ${h.text('hg_app_realm',size=30)} @@ -79,6 +79,51 @@ </div> </div> ${h.end_form()} + + <h3>${_('Mercurial settings')}</h3> + ${h.form(url('admin_setting', setting_id='mercurial'),method='put')} + <div class="form"> + <!-- fields --> + + <div class="fields"> + + <div class="field"> + <div class="label label-checkbox"> + <label for="web_push_ssl">${_('Push ssl')}:</label> + </div> + <div class="checkboxes"> + <div class="checkbox"> + ${h.checkbox('web_push_ssl','true')} + <label for="web_push_ssl">${_('require ssl for pushing')}</label> + </div> + </div> + </div> + + <div class="field"> + <div class="label"> + <label for="paths_root_path">${_('Repositories location')}:</label> + </div> + <div class="input"> + ${h.text('paths_root_path',size=30,disabled="disabled")} + <span id="path_unlock" class="tooltip" tooltip_title="${h.tooltip(_('This a crucial application setting. If You really sure you need to change this, you must restart application in order to make this settings take effect. Click this label to unlock.'))}"> + ${_('unlock')}</span> + </div> + </div> + + <div class="buttons"> + ${h.submit('save','save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")} + </div> + </div> + </div> + ${h.end_form()} + + <script type="text/javascript"> + YAHOO.util.Event.onDOMReady(function(){ + YAHOO.util.Event.addListener('path_unlock','click',function(){ + YAHOO.util.Dom.get('paths_root_path').disabled=false; + }); + }); + </script> </div> </%def>