Show More
@@ -25,11 +25,17 b'' | |||
|
25 | 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
26 | 26 | # MA 02110-1301, USA. |
|
27 | 27 | |
|
28 | import logging | |
|
29 | import traceback | |
|
30 | import formencode | |
|
31 | ||
|
32 | from operator import itemgetter | |
|
28 | 33 | from formencode import htmlfill |
|
29 | 34 | from pylons import request, session, tmpl_context as c, url, app_globals as g, \ |
|
30 | 35 | config |
|
31 | 36 | from pylons.controllers.util import abort, redirect |
|
32 | 37 | from pylons.i18n.translation import _ |
|
38 | ||
|
33 | 39 | from rhodecode.lib import helpers as h |
|
34 | 40 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
|
35 | 41 | HasPermissionAnyDecorator, NotAnonymous |
@@ -43,10 +49,9 b' from rhodecode.model.forms import UserFo' | |||
|
43 | 49 | from rhodecode.model.scm import ScmModel |
|
44 | 50 | from rhodecode.model.settings import SettingsModel |
|
45 | 51 | from rhodecode.model.user import UserModel |
|
52 | ||
|
46 | 53 | from sqlalchemy import func |
|
47 | import formencode | |
|
48 | import logging | |
|
49 | import traceback | |
|
54 | ||
|
50 | 55 | |
|
51 | 56 | log = logging.getLogger(__name__) |
|
52 | 57 | |
@@ -123,6 +128,7 b' class SettingsController(BaseController)' | |||
|
123 | 128 | try: |
|
124 | 129 | form_result = application_form.to_python(dict(request.POST)) |
|
125 | 130 | settings_model = SettingsModel() |
|
131 | ||
|
126 | 132 | try: |
|
127 | 133 | hgsettings1 = settings_model.get('title') |
|
128 | 134 | hgsettings1.app_settings_value = form_result['rhodecode_title'] |
@@ -130,9 +136,14 b' class SettingsController(BaseController)' | |||
|
130 | 136 | hgsettings2 = settings_model.get('realm') |
|
131 | 137 | hgsettings2.app_settings_value = form_result['rhodecode_realm'] |
|
132 | 138 | |
|
139 | hgsettings3 = settings_model.get('ga_code') | |
|
140 | hgsettings3.app_settings_value = form_result['ga_code'] | |
|
141 | ||
|
142 | ||
|
133 | 143 | |
|
134 | 144 | self.sa.add(hgsettings1) |
|
135 | 145 | self.sa.add(hgsettings2) |
|
146 | self.sa.add(hgsettings3) | |
|
136 | 147 | self.sa.commit() |
|
137 | 148 | set_rhodecode_config(config) |
|
138 | 149 | h.flash(_('Updated application settings'), |
@@ -16,11 +16,12 b' class BaseController(WSGIController):' | |||
|
16 | 16 | |
|
17 | 17 | def __before__(self): |
|
18 | 18 | c.rhodecode_version = __version__ |
|
19 |
c.rhodecode_name = config |
|
|
19 | c.rhodecode_name = config.get('rhodecode_title') | |
|
20 | c.ga_code = config.get('rhodeocode_ga_code') | |
|
20 | 21 | c.repo_name = get_repo_slug(request) |
|
21 | 22 | c.cached_repo_list = ScmModel().get_repos() |
|
22 | 23 | c.backends = BACKENDS.keys() |
|
23 |
self.cut_off_limit = int(config |
|
|
24 | self.cut_off_limit = int(config.get('cut_off_limit')) | |
|
24 | 25 | self.sa = meta.Session() |
|
25 | 26 | scm_model = ScmModel(self.sa) |
|
26 | 27 | #c.unread_journal = scm_model.get_unread_journal() |
@@ -166,6 +166,9 b' class DbManage(object):' | |||
|
166 | 166 | log.info('Changing ui settings') |
|
167 | 167 | self.klass.create_ui_settings() |
|
168 | 168 | |
|
169 | def step_3(self): | |
|
170 | print ('Adding additional settings into RhodeCode db') | |
|
171 | self.klass.fix_settings() | |
|
169 | 172 | |
|
170 | 173 | upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) |
|
171 | 174 | |
@@ -212,7 +215,17 b' class DbManage(object):' | |||
|
212 | 215 | self.sa.rollback() |
|
213 | 216 | raise |
|
214 | 217 | |
|
218 | def fix_settings(self): | |
|
219 | """Fixes rhodecode settings adds ga_code key for google analytics | |
|
220 | """ | |
|
215 | 221 | |
|
222 | hgsettings3 = RhodeCodeSettings('ga_code', '') | |
|
223 | try: | |
|
224 | self.sa.add(hgsettings3) | |
|
225 | self.sa.commit() | |
|
226 | except: | |
|
227 | self.sa.rollback() | |
|
228 | raise | |
|
216 | 229 | |
|
217 | 230 | def admin_prompt(self, second=False): |
|
218 | 231 | if not self.tests: |
@@ -360,6 +373,7 b' class DbManage(object):' | |||
|
360 | 373 | |
|
361 | 374 | hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication') |
|
362 | 375 | hgsettings2 = RhodeCodeSettings('title', 'RhodeCode') |
|
376 | hgsettings3 = RhodeCodeSettings('ga_code', '') | |
|
363 | 377 | |
|
364 | 378 | |
|
365 | 379 | try: |
@@ -370,6 +384,7 b' class DbManage(object):' | |||
|
370 | 384 | self.sa.add(paths) |
|
371 | 385 | self.sa.add(hgsettings1) |
|
372 | 386 | self.sa.add(hgsettings2) |
|
387 | self.sa.add(hgsettings3) | |
|
373 | 388 | |
|
374 | 389 | self.sa.commit() |
|
375 | 390 | except: |
@@ -438,6 +438,7 b' def ApplicationSettingsForm():' | |||
|
438 | 438 | filter_extra_fields = False |
|
439 | 439 | rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True) |
|
440 | 440 | rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True) |
|
441 | ga_code = UnicodeString(strip=True, min=1, not_empty=False) | |
|
441 | 442 | |
|
442 | 443 | return _ApplicationSettingsForm |
|
443 | 444 |
@@ -46,6 +46,11 b' class SettingsModel(BaseModel):' | |||
|
46 | 46 | return r |
|
47 | 47 | |
|
48 | 48 | def get_app_settings(self): |
|
49 | """Get's config from database, each config key is prefixed with | |
|
50 | 'rhodecode_' prefix, than global pylons config is updated with such | |
|
51 | keys | |
|
52 | """ | |
|
53 | ||
|
49 | 54 | ret = self.sa.query(RhodeCodeSettings)\ |
|
50 | 55 | .options(FromCache("sql_cache_short", |
|
51 | 56 | "get_hg_settings")).all() |
@@ -98,6 +98,15 b'' | |||
|
98 | 98 | </div> |
|
99 | 99 | </div> |
|
100 | 100 | |
|
101 | <div class="field"> | |
|
102 | <div class="label"> | |
|
103 | <label for="ga_code">${_('Google analytics code')}:</label> | |
|
104 | </div> | |
|
105 | <div class="input"> | |
|
106 | ${h.text('ga_code',size=30)} | |
|
107 | </div> | |
|
108 | </div> | |
|
109 | ||
|
101 | 110 | <div class="buttons"> |
|
102 | 111 | ${h.submit('save','Save settings',class_="ui-button")} |
|
103 | 112 | ${h.reset('reset','Reset',class_="ui-button")} |
@@ -10,6 +10,22 b'' | |||
|
10 | 10 | ${self.css()} |
|
11 | 11 | <!-- scripts --> |
|
12 | 12 | ${self.js()} |
|
13 | %if c.ga_code: | |
|
14 | <script type="text/javascript"> | |
|
15 | ||
|
16 | var _gaq = _gaq || []; | |
|
17 | _gaq.push(['_setAccount', '${c.ga_code}']); | |
|
18 | _gaq.push(['_trackPageview']); | |
|
19 | ||
|
20 | (function() { | |
|
21 | var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
|
22 | ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
|
23 | var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
|
24 | })(); | |
|
25 | ||
|
26 | ||
|
27 | </script> | |
|
28 | %endif | |
|
13 | 29 | </head> |
|
14 | 30 | <body> |
|
15 | 31 | <!-- header --> |
General Comments 0
You need to be logged in to leave comments.
Login now