# HG changeset patch # User Marcin Kuzminski # Date 1281040283 -7200 # Node ID 3bcf9529d22145664c0a4f121199e8eae484ff6b # Parent 2a18192fbd1e87c8d0ac0fb218faabbed9ad154e Added new application settings,Push ssl and repositories path diff -r 2a18192fbd1e -r 3bcf9529d221 pylons_app/config/environment.py --- 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)) diff -r 2a18192fbd1e -r 3bcf9529d221 pylons_app/controllers/admin/settings.py --- 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')) diff -r 2a18192fbd1e -r 3bcf9529d221 pylons_app/lib/utils.py --- 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) diff -r 2a18192fbd1e -r 3bcf9529d221 pylons_app/model/forms.py --- 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 - diff -r 2a18192fbd1e -r 3bcf9529d221 pylons_app/templates/admin/settings/settings.html --- 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 @@
- +
${h.text('hg_app_title',size=30)} @@ -66,7 +66,7 @@
- +
${h.text('hg_app_realm',size=30)} @@ -79,6 +79,51 @@
${h.end_form()} + +

${_('Mercurial settings')}

+ ${h.form(url('admin_setting', setting_id='mercurial'),method='put')} +
+ + +
+ +
+
+ +
+
+
+ ${h.checkbox('web_push_ssl','true')} + +
+
+
+ +
+
+ +
+
+ ${h.text('paths_root_path',size=30,disabled="disabled")} + + ${_('unlock')} +
+
+ +
+ ${h.submit('save','save settings',class_="ui-button ui-widget ui-state-default ui-corner-all")} +
+
+
+ ${h.end_form()} + +