@@ -22,17 +22,23 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import logging
import traceback
import formencode
from operator import itemgetter
from formencode import htmlfill
from pylons import request, session, tmpl_context as c, url, app_globals as g, \
config
from pylons.controllers.util import abort, redirect
from pylons.i18n.translation import _
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
HasPermissionAnyDecorator, NotAnonymous
from rhodecode.lib.base import BaseController, render
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \
@@ -40,16 +46,15 @@ from rhodecode.lib.utils import repo2db_
from rhodecode.model.db import RhodeCodeUi, Repository
from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \
ApplicationUiSettingsForm
from rhodecode.model.scm import ScmModel
from rhodecode.model.settings import SettingsModel
from rhodecode.model.user import UserModel
from sqlalchemy import func
log = logging.getLogger(__name__)
class SettingsController(BaseController):
"""REST Controller styled on the Atom Publishing Protocol"""
@@ -120,22 +125,28 @@ class SettingsController(BaseController)
if setting_id == 'global':
application_form = ApplicationSettingsForm()()
try:
form_result = application_form.to_python(dict(request.POST))
settings_model = SettingsModel()
hgsettings1 = settings_model.get('title')
hgsettings1.app_settings_value = form_result['rhodecode_title']
hgsettings2 = settings_model.get('realm')
hgsettings2.app_settings_value = form_result['rhodecode_realm']
hgsettings3 = settings_model.get('ga_code')
hgsettings3.app_settings_value = form_result['ga_code']
self.sa.add(hgsettings1)
self.sa.add(hgsettings2)
self.sa.add(hgsettings3)
self.sa.commit()
set_rhodecode_config(config)
h.flash(_('Updated application settings'),
category='success')
except:
@@ -13,17 +13,18 @@ from rhodecode.model.scm import ScmModel
from rhodecode import BACKENDS
class BaseController(WSGIController):
def __before__(self):
c.rhodecode_version = __version__
c.rhodecode_name = config['rhodecode_title']
c.rhodecode_name = config.get('rhodecode_title')
c.ga_code = config.get('rhodeocode_ga_code')
c.repo_name = get_repo_slug(request)
c.cached_repo_list = ScmModel().get_repos()
c.backends = BACKENDS.keys()
self.cut_off_limit = int(config['cut_off_limit'])
self.cut_off_limit = int(config.get('cut_off_limit'))
self.sa = meta.Session()
scm_model = ScmModel(self.sa)
#c.unread_journal = scm_model.get_unread_journal()
if c.repo_name:
cached_repo = scm_model.get(c.repo_name)
@@ -163,12 +163,15 @@ class DbManage(object):
print ('Patching default user of RhodeCode')
self.klass.fix_default_user()
log.info('Changing ui settings')
self.klass.create_ui_settings()
def step_3(self):
print ('Adding additional settings into RhodeCode db')
self.klass.fix_settings()
upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
#CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
for step in upgrade_steps:
print ('performing upgrade step %s' % step)
@@ -209,13 +212,23 @@ class DbManage(object):
self.sa.add(def_user)
self.sa.rollback()
raise
def fix_settings(self):
"""Fixes rhodecode settings adds ga_code key for google analytics
"""
hgsettings3 = RhodeCodeSettings('ga_code', '')
def admin_prompt(self, second=False):
if not self.tests:
import getpass
@@ -357,22 +370,24 @@ class DbManage(object):
paths.ui_key = '/'
paths.ui_value = path
hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
self.sa.add(web1)
self.sa.add(web2)
self.sa.add(web3)
self.sa.add(web4)
self.sa.add(paths)
@@ -435,12 +435,13 @@ def RepoSettingsForm(edit=False, old_dat
def ApplicationSettingsForm():
class _ApplicationSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
ga_code = UnicodeString(strip=True, min=1, not_empty=False)
return _ApplicationSettingsForm
def ApplicationUiSettingsForm():
class _ApplicationUiSettingsForm(formencode.Schema):
@@ -43,12 +43,17 @@ class SettingsModel(BaseModel):
if cache:
r = r.options(FromCache("sql_cache_short",
"get_setting_%s" % settings_key))
return r
def get_app_settings(self):
"""Get's config from database, each config key is prefixed with
'rhodecode_' prefix, than global pylons config is updated with such
keys
ret = self.sa.query(RhodeCodeSettings)\
.options(FromCache("sql_cache_short",
"get_hg_settings")).all()
if not ret:
raise Exception('Could not get application settings !')
@@ -94,13 +94,22 @@
<label for="rhodecode_realm">${_('Realm text')}:</label>
</div>
<div class="input">
${h.text('rhodecode_realm',size=30)}
<div class="field">
<div class="label">
<label for="ga_code">${_('Google analytics code')}:</label>
${h.text('ga_code',size=30)}
<div class="buttons">
${h.submit('save','Save settings',class_="ui-button")}
${h.reset('reset','Reset',class_="ui-button")}
@@ -7,12 +7,28 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="robots" content="index, nofollow"/>
<!-- stylesheets -->
${self.css()}
<!-- scripts -->
${self.js()}
%if c.ga_code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '${c.ga_code}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
%endif
</head>
<body>
<!-- header -->
<div id="header">
<!-- user -->
<ul id="logged-user">
Status change: