Mercurial > kallithea
changeset 381:55377fdc1fc6
cleared global application settings.
Made it much more extensible by keeping it key/value in the database.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 01 Aug 2010 18:36:00 +0200 |
parents | ca54622e39a1 |
children | e0ef325cbdea |
files | pylons_app/controllers/admin/settings.py pylons_app/lib/auth.py pylons_app/lib/base.py pylons_app/lib/db_manage.py pylons_app/lib/middleware/simplehg.py pylons_app/lib/utils.py pylons_app/model/db.py pylons_app/model/forms.py pylons_app/templates/admin/settings/settings.html |
diffstat | 9 files changed, 46 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/pylons_app/controllers/admin/settings.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/controllers/admin/settings.py Sun Aug 01 18:36:00 2010 +0200 @@ -32,7 +32,7 @@ HasPermissionAnyDecorator from pylons_app.lib.base import BaseController, render from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \ - set_hg_app_config + set_hg_app_config, get_hg_settings from pylons_app.model.db import User, UserLog, HgAppSettings from pylons_app.model.forms import UserForm, ApplicationSettingsForm from pylons_app.model.hg_model import HgModel @@ -64,8 +64,8 @@ """GET /admin/settings: All items in the collection""" # url('admin_settings') - hgsettings = self.sa.query(HgAppSettings).scalar() - defaults = hgsettings.__dict__ if hgsettings else {} + defaults = get_hg_settings() + return htmlfill.render( render('admin/settings/settings.html'), defaults=defaults, @@ -106,15 +106,17 @@ application_form = ApplicationSettingsForm()() try: form_result = application_form.to_python(dict(request.POST)) - title = form_result['app_title'] - realm = form_result['app_auth_realm'] try: - hgsettings = self.sa.query(HgAppSettings).get(1) - hgsettings.app_auth_realm = realm - hgsettings.app_title = title + hgsettings1 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'title').one() + hgsettings1.app_settings_value = form_result['hg_app_title'] - self.sa.add(hgsettings) + hgsettings2 = self.sa.query(HgAppSettings).filter(HgAppSettings.app_settings_name == 'realm').one() + hgsettings2.app_settings_value = form_result['hg_app_realm'] + + + self.sa.add(hgsettings1) + self.sa.add(hgsettings2) self.sa.commit() set_hg_app_config(config) h.flash(_('Updated application settings'), @@ -122,7 +124,7 @@ except: log.error(traceback.format_exc()) - h.flash(_('error occured during chaning application settings'), + h.flash(_('error occured during updating application settings'), category='error') self.sa.rollback()
--- a/pylons_app/lib/auth.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/lib/auth.py Sun Aug 01 18:36:00 2010 +0200 @@ -17,6 +17,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +""" +Created on April 4, 2010 + +@author: marcink +""" from beaker.cache import cache_region from pylons import config, session, url, request from pylons.controllers.util import abort, redirect @@ -28,11 +33,6 @@ import crypt from decorator import decorator import logging -""" -Created on April 4, 2010 - -@author: marcink -""" log = logging.getLogger(__name__) @@ -186,7 +186,6 @@ user = fill_perms(user) session['hg_app_user'] = user session.save() - print user.permissions return user #===============================================================================
--- a/pylons_app/lib/base.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/lib/base.py Sun Aug 01 18:36:00 2010 +0200 @@ -16,7 +16,7 @@ def __before__(self): c.hg_app_version = __version__ - c.hg_app_name = config['hg_app_name'] + c.hg_app_name = config['hg_app_title'] c.repo_name = get_repo_slug(request) c.cached_repo_list = _get_repos_cached() c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
--- a/pylons_app/lib/db_manage.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/lib/db_manage.py Sun Aug 01 18:36:00 2010 +0200 @@ -121,9 +121,14 @@ paths.ui_value = os.path.join(path, '*') - hgsettings = HgAppSettings() - hgsettings.app_auth_realm = 'hg-app authentication' - hgsettings.app_title = 'hg-app' + hgsettings1 = HgAppSettings() + + hgsettings1.app_settings_name = 'realm' + hgsettings1.app_settings_value = 'hg-app authentication' + + hgsettings2 = HgAppSettings() + hgsettings2.app_settings_name = 'title' + hgsettings2.app_settings_value = 'hg-app' try: #self.sa.add(hooks) @@ -132,7 +137,8 @@ self.sa.add(web3) self.sa.add(web4) self.sa.add(paths) - self.sa.add(hgsettings) + self.sa.add(hgsettings1) + self.sa.add(hgsettings2) self.sa.commit() except: self.sa.rollback()
--- a/pylons_app/lib/middleware/simplehg.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/lib/middleware/simplehg.py Sun Aug 01 18:36:00 2010 +0200 @@ -63,7 +63,7 @@ #=================================================================== username = REMOTE_USER(environ) if not username: - self.authenticate.realm = self.config['hg_app_auth_realm'] + self.authenticate.realm = self.config['hg_app_realm'] result = self.authenticate(environ) if isinstance(result, str): AUTH_TYPE.update(environ, 'basic')
--- a/pylons_app/lib/utils.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/lib/utils.py Sun Aug 01 18:36:00 2010 +0200 @@ -100,13 +100,17 @@ def get_hg_settings(): try: sa = meta.Session - ret = sa.query(HgAppSettings).scalar() + ret = sa.query(HgAppSettings).all() finally: meta.Session.remove() if not ret: raise Exception('Could not get application settings !') - return ret + settings = {} + for each in ret: + settings['hg_app_' + each.app_settings_name] = each.app_settings_value + + return settings def make_ui(read_from='file', path=None, checkpaths=True): """ @@ -155,8 +159,9 @@ def set_hg_app_config(config): hgsettings = get_hg_settings() - config['hg_app_auth_realm'] = hgsettings.app_auth_realm - config['hg_app_name'] = hgsettings.app_title + + for k, v in hgsettings.items(): + config[k] = v def invalidate_cache(name, *args): """Invalidates given name cache"""
--- a/pylons_app/model/db.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/model/db.py Sun Aug 01 18:36:00 2010 +0200 @@ -5,10 +5,10 @@ class HgAppSettings(Base): __tablename__ = 'hg_app_settings' - __table_args__ = {'useexisting':True} + __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True}) app_settings_id = Column("app_settings_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) - app_title = Column("app_title", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) - app_auth_realm = Column("auth_realm", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) + app_settings_name = Column("app_settings_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) + app_settings_value = Column("app_settings_value", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) class HgAppUi(Base): __tablename__ = 'hg_app_ui'
--- a/pylons_app/model/forms.py Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/model/forms.py Sun Aug 01 18:36:00 2010 +0200 @@ -297,8 +297,8 @@ class _ApplicationSettingsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False - app_title = UnicodeString(strip=True, min=3, not_empty=True) - app_auth_realm = UnicodeString(strip=True, min=3, not_empty=True) + hg_app_title = UnicodeString(strip=True, min=3, not_empty=True) + hg_app_realm = UnicodeString(strip=True, min=3, not_empty=True) return _ApplicationSettingsForm
--- a/pylons_app/templates/admin/settings/settings.html Sun Aug 01 17:08:58 2010 +0200 +++ b/pylons_app/templates/admin/settings/settings.html Sun Aug 01 18:36:00 2010 +0200 @@ -5,8 +5,6 @@ ${_('Settings administration')} </%def> - - <%def name="breadcrumbs_links()"> ${h.link_to(_('Admin'),h.url('admin_home'))} » ${_('Settings')} </%def> @@ -30,7 +28,7 @@ <div class="fields"> <div class="field"> <div class="label label-checkbox"> - <label for="-button">${_('rescan option')}:</label> + <label for="destroy">${_('rescan option')}:</label> </div> <div class="checkboxes"> <div class="checkbox"> @@ -60,7 +58,7 @@ <label for="input-small">${_('Application name')}:</label> </div> <div class="input"> - ${h.text('app_title',size=30)} + ${h.text('hg_app_title',size=30)} </div> </div> @@ -69,7 +67,7 @@ <label for="input-small">${_('Realm text')}:</label> </div> <div class="input"> - ${h.text('app_auth_realm',size=30)} + ${h.text('hg_app_realm',size=30)} </div> </div>