##// END OF EJS Templates
Implemented fancier top menu for logged and anonymous users...
marcink -
r784:30d3161c beta
parent child Browse files
Show More
@@ -21,10 +21,12 b' class BaseController(WSGIController):'
21 c.cached_repo_list = ScmModel().get_repos()
21 c.cached_repo_list = ScmModel().get_repos()
22 c.backends = BACKENDS.keys()
22 c.backends = BACKENDS.keys()
23
23
24 self.sa = meta.Session()
25 scm_model = ScmModel(self.sa)
26 #c.unread_journal = scm_model.get_unread_journal()
27
24 if c.repo_name:
28 if c.repo_name:
25 scm_model = ScmModel()
26 cached_repo = scm_model.get(c.repo_name)
29 cached_repo = scm_model.get(c.repo_name)
27
28 if cached_repo:
30 if cached_repo:
29 c.repository_tags = cached_repo.tags
31 c.repository_tags = cached_repo.tags
30 c.repository_branches = cached_repo.branches
32 c.repository_branches = cached_repo.branches
@@ -36,7 +38,6 b' class BaseController(WSGIController):'
36 c.repository_followers = 0
38 c.repository_followers = 0
37 c.repository_forks = 0
39 c.repository_forks = 0
38
40
39 self.sa = meta.Session()
40
41
41 def __call__(self, environ, start_response):
42 def __call__(self, environ, start_response):
42 """Invoke the Controller"""
43 """Invoke the Controller"""
@@ -55,11 +55,11 b' class CachingQuery(Query):'
55 the "public" method of configuring this state upon the CachingQuery.
55 the "public" method of configuring this state upon the CachingQuery.
56
56
57 """
57 """
58
58
59 def __init__(self, manager, *args, **kw):
59 def __init__(self, manager, *args, **kw):
60 self.cache_manager = manager
60 self.cache_manager = manager
61 Query.__init__(self, *args, **kw)
61 Query.__init__(self, *args, **kw)
62
62
63 def __iter__(self):
63 def __iter__(self):
64 """override __iter__ to pull results from Beaker
64 """override __iter__ to pull results from Beaker
65 if particular attributes have been configured.
65 if particular attributes have been configured.
@@ -101,7 +101,7 b' class CachingQuery(Query):'
101 """Set the value in the cache for this query."""
101 """Set the value in the cache for this query."""
102
102
103 cache, cache_key = _get_cache_parameters(self)
103 cache, cache_key = _get_cache_parameters(self)
104 cache.put(cache_key, value)
104 cache.put(cache_key, value)
105
105
106 def query_callable(manager):
106 def query_callable(manager):
107 def query(*arg, **kw):
107 def query(*arg, **kw):
@@ -110,11 +110,11 b' def query_callable(manager):'
110
110
111 def get_cache_region(name, region):
111 def get_cache_region(name, region):
112 if region not in beaker.cache.cache_regions:
112 if region not in beaker.cache.cache_regions:
113 raise BeakerException('Cache region not configured: %s'
113 raise BeakerException('Cache region `%s` not configured '
114 'Check if proper cache settings are in the .ini files' % region)
114 'Check if proper cache settings are in the .ini files' % region)
115 kw = beaker.cache.cache_regions[region]
115 kw = beaker.cache.cache_regions[region]
116 return beaker.cache.Cache._get_cache(name, kw)
116 return beaker.cache.Cache._get_cache(name, kw)
117
117
118 def _get_cache_parameters(query):
118 def _get_cache_parameters(query):
119 """For a query with cache_region and cache_namespace configured,
119 """For a query with cache_region and cache_namespace configured,
120 return the correspoinding Cache instance and cache key, based
120 return the correspoinding Cache instance and cache key, based
@@ -125,7 +125,7 b' def _get_cache_parameters(query):'
125 raise ValueError("This Query does not have caching parameters configured.")
125 raise ValueError("This Query does not have caching parameters configured.")
126
126
127 region, namespace, cache_key = query._cache_parameters
127 region, namespace, cache_key = query._cache_parameters
128
128
129 namespace = _namespace_from_query(namespace, query)
129 namespace = _namespace_from_query(namespace, query)
130
130
131 if cache_key is None:
131 if cache_key is None:
@@ -153,15 +153,15 b' def _namespace_from_query(namespace, que'
153 return namespace
153 return namespace
154
154
155 def _set_cache_parameters(query, region, namespace, cache_key):
155 def _set_cache_parameters(query, region, namespace, cache_key):
156
156
157 if hasattr(query, '_cache_parameters'):
157 if hasattr(query, '_cache_parameters'):
158 region, namespace, cache_key = query._cache_parameters
158 region, namespace, cache_key = query._cache_parameters
159 raise ValueError("This query is already configured "
159 raise ValueError("This query is already configured "
160 "for region %r namespace %r" %
160 "for region %r namespace %r" %
161 (region, namespace)
161 (region, namespace)
162 )
162 )
163 query._cache_parameters = region, namespace, cache_key
163 query._cache_parameters = region, namespace, cache_key
164
164
165 class FromCache(MapperOption):
165 class FromCache(MapperOption):
166 """Specifies that a Query should load results from a cache."""
166 """Specifies that a Query should load results from a cache."""
167
167
@@ -187,10 +187,10 b' class FromCache(MapperOption):'
187 self.region = region
187 self.region = region
188 self.namespace = namespace
188 self.namespace = namespace
189 self.cache_key = cache_key
189 self.cache_key = cache_key
190
190
191 def process_query(self, query):
191 def process_query(self, query):
192 """Process a Query during normal loading operation."""
192 """Process a Query during normal loading operation."""
193
193
194 _set_cache_parameters(query, self.region, self.namespace, self.cache_key)
194 _set_cache_parameters(query, self.region, self.namespace, self.cache_key)
195
195
196 class RelationshipCache(MapperOption):
196 class RelationshipCache(MapperOption):
@@ -263,13 +263,13 b' def _params_from_query(query):'
263 v = []
263 v = []
264 def visit_bindparam(bind):
264 def visit_bindparam(bind):
265 value = query._params.get(bind.key, bind.value)
265 value = query._params.get(bind.key, bind.value)
266
266
267 # lazyloader may dig a callable in here, intended
267 # lazyloader may dig a callable in here, intended
268 # to late-evaluate params after autoflush is called.
268 # to late-evaluate params after autoflush is called.
269 # convert to a scalar value.
269 # convert to a scalar value.
270 if callable(value):
270 if callable(value):
271 value = value()
271 value = value()
272
272
273 v.append(value)
273 v.append(value)
274 if query._criterion is not None:
274 if query._criterion is not None:
275 visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam})
275 visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam})
@@ -46,7 +46,7 b' from rhodecode.model import BaseModel'
46 from rhodecode.model.user import UserModel
46 from rhodecode.model.user import UserModel
47
47
48 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
48 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
49 UserFollowing
49 UserFollowing, UserLog
50 from rhodecode.model.caching_query import FromCache
50 from rhodecode.model.caching_query import FromCache
51
51
52 from sqlalchemy.orm import joinedload
52 from sqlalchemy.orm import joinedload
@@ -333,6 +333,11 b' class ScmModel(BaseModel):'
333 return self.sa.query(Repository)\
333 return self.sa.query(Repository)\
334 .filter(Repository.fork_id == repo_id).count()
334 .filter(Repository.fork_id == repo_id).count()
335
335
336
337 def get_unread_journal(self):
338 return self.sa.query(UserLog).count()
339
340
336 def _should_invalidate(self, repo_name):
341 def _should_invalidate(self, repo_name):
337 """
342 """
338 Looks up database for invalidation signals for this repo_name
343 Looks up database for invalidation signals for this repo_name
@@ -190,18 +190,32 b' margin:0;'
190 padding:0 30px;
190 padding:0 30px;
191 }
191 }
192
192
193
194 #header ul#logged-user{
195 margin-bottom:5px !important;
196 -webkit-border-radius: 0px 0px 8px 8px;
197 -khtml-border-radius: 0px 0px 8px 8px;
198 -moz-border-radius: 0px 0px 8px 8px;
199 border-radius: 0px 0px 8px 8px;
200 height:37px;
201 background:url("../images/header_inner.png") repeat-x scroll 0 0 #003367
202 }
203
193 #header ul#logged-user li {
204 #header ul#logged-user li {
194 list-style:none;
205 list-style:none;
195 float:left;
206 float:left;
196 border-left:1px solid #bbb;
207 margin:8px 0 0;
197 border-right:1px solid #a5a5a5;
208 padding:4px 12px;
198 margin:-2px 0 0;
209 border-left: 1px solid #316293;
199 padding:10px 12px;
200 }
210 }
201
211
202 #header ul#logged-user li.first {
212 #header ul#logged-user li.first {
203 border-left:none;
213 border-left:none;
204 margin:-6px;
214 margin:4px;
215 }
216
217 #header ul#logged-user li.first div.gravatar {
218 margin-top:-2px;
205 }
219 }
206
220
207 #header ul#logged-user li.first div.account {
221 #header ul#logged-user li.first div.account {
@@ -214,13 +228,12 b' border-right:none;'
214 }
228 }
215
229
216 #header ul#logged-user li a {
230 #header ul#logged-user li a {
217 color:#4e4e4e;
231 color:#fff;
218 font-weight:700;
232 font-weight:700;
219 text-decoration:none;
233 text-decoration:none;
220 }
234 }
221
235
222 #header ul#logged-user li a:hover {
236 #header ul#logged-user li a:hover {
223 color:#376ea6;
224 text-decoration:underline;
237 text-decoration:underline;
225 }
238 }
226
239
@@ -229,7 +242,7 b' color:#fff;'
229 }
242 }
230
243
231 #header ul#logged-user li.highlight a:hover {
244 #header ul#logged-user li.highlight a:hover {
232 color:#376ea6;
245 color:#FFF;
233 }
246 }
234
247
235 #header #header-inner {
248 #header #header-inner {
@@ -16,26 +16,34 b''
16 <div id="header">
16 <div id="header">
17 <!-- user -->
17 <!-- user -->
18 <ul id="logged-user">
18 <ul id="logged-user">
19 %if c.rhodecode_user.username == 'default':
20 <li class="first">
21 <div class="account">
22 ## ${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('#'))}<br/>
23 ## ${h.link_to(c.rhodecode_user.username,h.url('#'))}
24 </div>
25 </li>
26 <li class="last highlight">${h.link_to(u'Login',h.url('login_home'))}</li>
27 %else:
28 <li class="first">
19 <li class="first">
29 <div class="gravatar">
20 <div class="gravatar">
30 <img alt="gravatar" src="${h.gravatar_url(c.rhodecode_user.email,24)}" />
21 <img alt="gravatar" src="${h.gravatar_url(c.rhodecode_user.email,20)}" />
31 </div>
22 </div>
32 <div class="account">
23 <div class="account">
33 ${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('admin_settings_my_account'))}<br/>
24 %if c.rhodecode_user.username == 'default':
25 ##${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('register'))}<br/>
26 ${h.link_to('anonymous',h.url('register'))}
27 %else:
28 ##${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('admin_settings_my_account'))}<br/>
34 ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'))}
29 ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'))}
30 %endif
35 </div>
31 </div>
36 </li>
32 </li>
37 <li class="last highlight">${h.link_to(u'Logout',h.url('logout_home'))}</li>
33 <li>
38 %endif
34 <a href="${h.url('home')}">${_('Home')}</a>
35 </li>
36 <li>
37 <a href="${h.url('journal')}">${_('Journal')}</a>
38 ##(${c.unread_journal})</a>
39 </li>
40 %if c.rhodecode_user.username == 'default':
41 <li class="last highlight">${h.link_to(u'Login',h.url('login_home'))}</li>
42 %else:
43 <li class="last highlight">${h.link_to(u'Log Out',h.url('logout_home'))}</li>
44 %endif
45
46
39 </ul>
47 </ul>
40 <!-- end user -->
48 <!-- end user -->
41 <div id="header-inner" class="title top-left-rounded-corner top-right-rounded-corner">
49 <div id="header-inner" class="title top-left-rounded-corner top-right-rounded-corner">
General Comments 0
You need to be logged in to leave comments. Login now