diff --git a/pylons_app/controllers/admin/settings.py b/pylons_app/controllers/admin/settings.py --- a/pylons_app/controllers/admin/settings.py +++ b/pylons_app/controllers/admin/settings.py @@ -32,7 +32,7 @@ from pylons_app.lib.auth import LoginReq 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 @@ class SettingsController(BaseController) """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 @@ class SettingsController(BaseController) 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 @@ class SettingsController(BaseController) 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() diff --git a/pylons_app/lib/auth.py b/pylons_app/lib/auth.py --- a/pylons_app/lib/auth.py +++ b/pylons_app/lib/auth.py @@ -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 @@ from sqlalchemy.orm.exc import NoResultF import crypt from decorator import decorator import logging -""" -Created on April 4, 2010 - -@author: marcink -""" log = logging.getLogger(__name__) @@ -186,7 +186,6 @@ def get_user(session): user = fill_perms(user) session['hg_app_user'] = user session.save() - print user.permissions return user #=============================================================================== diff --git a/pylons_app/lib/base.py b/pylons_app/lib/base.py --- a/pylons_app/lib/base.py +++ b/pylons_app/lib/base.py @@ -16,7 +16,7 @@ class BaseController(WSGIController): 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) diff --git a/pylons_app/lib/db_manage.py b/pylons_app/lib/db_manage.py --- a/pylons_app/lib/db_manage.py +++ b/pylons_app/lib/db_manage.py @@ -121,9 +121,14 @@ class DbManage(object): 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 @@ class DbManage(object): 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() diff --git a/pylons_app/lib/middleware/simplehg.py b/pylons_app/lib/middleware/simplehg.py --- a/pylons_app/lib/middleware/simplehg.py +++ b/pylons_app/lib/middleware/simplehg.py @@ -63,7 +63,7 @@ class SimpleHg(object): #=================================================================== 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') diff --git a/pylons_app/lib/utils.py b/pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py +++ b/pylons_app/lib/utils.py @@ -100,13 +100,17 @@ def get_hg_ui_cached(): 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 make_ui(read_from='file', path=None, 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""" diff --git a/pylons_app/model/db.py b/pylons_app/model/db.py --- a/pylons_app/model/db.py +++ b/pylons_app/model/db.py @@ -5,10 +5,10 @@ from vcs.utils.lazy import LazyProperty 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' diff --git a/pylons_app/model/forms.py b/pylons_app/model/forms.py --- a/pylons_app/model/forms.py +++ b/pylons_app/model/forms.py @@ -297,8 +297,8 @@ def ApplicationSettingsForm(): 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 diff --git a/pylons_app/templates/admin/settings/settings.html b/pylons_app/templates/admin/settings/settings.html --- a/pylons_app/templates/admin/settings/settings.html +++ b/pylons_app/templates/admin/settings/settings.html @@ -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 @@