##// END OF EJS Templates
implemented #89 google analytics code
marcink -
r890:042d3868 beta
parent child Browse files
Show More
@@ -25,11 +25,17 b''
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import logging
29 import traceback
30 import formencode
31
32 from operator import itemgetter
28 from formencode import htmlfill
33 from formencode import htmlfill
29 from pylons import request, session, tmpl_context as c, url, app_globals as g, \
34 from pylons import request, session, tmpl_context as c, url, app_globals as g, \
30 config
35 config
31 from pylons.controllers.util import abort, redirect
36 from pylons.controllers.util import abort, redirect
32 from pylons.i18n.translation import _
37 from pylons.i18n.translation import _
38
33 from rhodecode.lib import helpers as h
39 from rhodecode.lib import helpers as h
34 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
40 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
35 HasPermissionAnyDecorator, NotAnonymous
41 HasPermissionAnyDecorator, NotAnonymous
@@ -43,10 +49,9 b' from rhodecode.model.forms import UserFo'
43 from rhodecode.model.scm import ScmModel
49 from rhodecode.model.scm import ScmModel
44 from rhodecode.model.settings import SettingsModel
50 from rhodecode.model.settings import SettingsModel
45 from rhodecode.model.user import UserModel
51 from rhodecode.model.user import UserModel
52
46 from sqlalchemy import func
53 from sqlalchemy import func
47 import formencode
54
48 import logging
49 import traceback
50
55
51 log = logging.getLogger(__name__)
56 log = logging.getLogger(__name__)
52
57
@@ -123,6 +128,7 b' class SettingsController(BaseController)'
123 try:
128 try:
124 form_result = application_form.to_python(dict(request.POST))
129 form_result = application_form.to_python(dict(request.POST))
125 settings_model = SettingsModel()
130 settings_model = SettingsModel()
131
126 try:
132 try:
127 hgsettings1 = settings_model.get('title')
133 hgsettings1 = settings_model.get('title')
128 hgsettings1.app_settings_value = form_result['rhodecode_title']
134 hgsettings1.app_settings_value = form_result['rhodecode_title']
@@ -130,9 +136,14 b' class SettingsController(BaseController)'
130 hgsettings2 = settings_model.get('realm')
136 hgsettings2 = settings_model.get('realm')
131 hgsettings2.app_settings_value = form_result['rhodecode_realm']
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 self.sa.add(hgsettings1)
144 self.sa.add(hgsettings1)
135 self.sa.add(hgsettings2)
145 self.sa.add(hgsettings2)
146 self.sa.add(hgsettings3)
136 self.sa.commit()
147 self.sa.commit()
137 set_rhodecode_config(config)
148 set_rhodecode_config(config)
138 h.flash(_('Updated application settings'),
149 h.flash(_('Updated application settings'),
@@ -16,11 +16,12 b' class BaseController(WSGIController):'
16
16
17 def __before__(self):
17 def __before__(self):
18 c.rhodecode_version = __version__
18 c.rhodecode_version = __version__
19 c.rhodecode_name = config['rhodecode_title']
19 c.rhodecode_name = config.get('rhodecode_title')
20 c.ga_code = config.get('rhodeocode_ga_code')
20 c.repo_name = get_repo_slug(request)
21 c.repo_name = get_repo_slug(request)
21 c.cached_repo_list = ScmModel().get_repos()
22 c.cached_repo_list = ScmModel().get_repos()
22 c.backends = BACKENDS.keys()
23 c.backends = BACKENDS.keys()
23 self.cut_off_limit = int(config['cut_off_limit'])
24 self.cut_off_limit = int(config.get('cut_off_limit'))
24 self.sa = meta.Session()
25 self.sa = meta.Session()
25 scm_model = ScmModel(self.sa)
26 scm_model = ScmModel(self.sa)
26 #c.unread_journal = scm_model.get_unread_journal()
27 #c.unread_journal = scm_model.get_unread_journal()
@@ -166,6 +166,9 b' class DbManage(object):'
166 log.info('Changing ui settings')
166 log.info('Changing ui settings')
167 self.klass.create_ui_settings()
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 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
173 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
171
174
@@ -212,7 +215,17 b' class DbManage(object):'
212 self.sa.rollback()
215 self.sa.rollback()
213 raise
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 def admin_prompt(self, second=False):
230 def admin_prompt(self, second=False):
218 if not self.tests:
231 if not self.tests:
@@ -360,6 +373,7 b' class DbManage(object):'
360
373
361 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
374 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
362 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
375 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
376 hgsettings3 = RhodeCodeSettings('ga_code', '')
363
377
364
378
365 try:
379 try:
@@ -370,6 +384,7 b' class DbManage(object):'
370 self.sa.add(paths)
384 self.sa.add(paths)
371 self.sa.add(hgsettings1)
385 self.sa.add(hgsettings1)
372 self.sa.add(hgsettings2)
386 self.sa.add(hgsettings2)
387 self.sa.add(hgsettings3)
373
388
374 self.sa.commit()
389 self.sa.commit()
375 except:
390 except:
@@ -438,6 +438,7 b' def ApplicationSettingsForm():'
438 filter_extra_fields = False
438 filter_extra_fields = False
439 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
439 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
440 rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
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 return _ApplicationSettingsForm
443 return _ApplicationSettingsForm
443
444
@@ -46,6 +46,11 b' class SettingsModel(BaseModel):'
46 return r
46 return r
47
47
48 def get_app_settings(self):
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 ret = self.sa.query(RhodeCodeSettings)\
54 ret = self.sa.query(RhodeCodeSettings)\
50 .options(FromCache("sql_cache_short",
55 .options(FromCache("sql_cache_short",
51 "get_hg_settings")).all()
56 "get_hg_settings")).all()
@@ -98,6 +98,15 b''
98 </div>
98 </div>
99 </div>
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 <div class="buttons">
110 <div class="buttons">
102 ${h.submit('save','Save settings',class_="ui-button")}
111 ${h.submit('save','Save settings',class_="ui-button")}
103 ${h.reset('reset','Reset',class_="ui-button")}
112 ${h.reset('reset','Reset',class_="ui-button")}
@@ -10,6 +10,22 b''
10 ${self.css()}
10 ${self.css()}
11 <!-- scripts -->
11 <!-- scripts -->
12 ${self.js()}
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 </head>
29 </head>
14 <body>
30 <body>
15 <!-- header -->
31 <!-- header -->
General Comments 0
You need to be logged in to leave comments. Login now