Mercurial > kallithea
changeset 784:30d3161c6683 beta
Implemented fancier top menu for logged and anonymous users
little error fix for cached query
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 28 Nov 2010 05:26:26 +0100 |
parents | 71113f64b2d8 |
children | 277427ac29a9 |
files | rhodecode/lib/base.py rhodecode/model/caching_query.py rhodecode/model/scm.py rhodecode/public/css/style.css rhodecode/templates/base/base.html |
diffstat | 5 files changed, 65 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/base.py Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/lib/base.py Sun Nov 28 05:26:26 2010 +0100 @@ -21,10 +21,12 @@ c.cached_repo_list = ScmModel().get_repos() c.backends = BACKENDS.keys() + self.sa = meta.Session() + scm_model = ScmModel(self.sa) + #c.unread_journal = scm_model.get_unread_journal() + if c.repo_name: - scm_model = ScmModel() cached_repo = scm_model.get(c.repo_name) - if cached_repo: c.repository_tags = cached_repo.tags c.repository_branches = cached_repo.branches @@ -36,7 +38,6 @@ c.repository_followers = 0 c.repository_forks = 0 - self.sa = meta.Session() def __call__(self, environ, start_response): """Invoke the Controller"""
--- a/rhodecode/model/caching_query.py Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/model/caching_query.py Sun Nov 28 05:26:26 2010 +0100 @@ -55,11 +55,11 @@ the "public" method of configuring this state upon the CachingQuery. """ - + def __init__(self, manager, *args, **kw): self.cache_manager = manager Query.__init__(self, *args, **kw) - + def __iter__(self): """override __iter__ to pull results from Beaker if particular attributes have been configured. @@ -101,7 +101,7 @@ """Set the value in the cache for this query.""" cache, cache_key = _get_cache_parameters(self) - cache.put(cache_key, value) + cache.put(cache_key, value) def query_callable(manager): def query(*arg, **kw): @@ -110,11 +110,11 @@ def get_cache_region(name, region): if region not in beaker.cache.cache_regions: - raise BeakerException('Cache region not configured: %s' + raise BeakerException('Cache region `%s` not configured ' 'Check if proper cache settings are in the .ini files' % region) kw = beaker.cache.cache_regions[region] return beaker.cache.Cache._get_cache(name, kw) - + def _get_cache_parameters(query): """For a query with cache_region and cache_namespace configured, return the correspoinding Cache instance and cache key, based @@ -125,7 +125,7 @@ raise ValueError("This Query does not have caching parameters configured.") region, namespace, cache_key = query._cache_parameters - + namespace = _namespace_from_query(namespace, query) if cache_key is None: @@ -153,15 +153,15 @@ return namespace def _set_cache_parameters(query, region, namespace, cache_key): - + if hasattr(query, '_cache_parameters'): region, namespace, cache_key = query._cache_parameters raise ValueError("This query is already configured " - "for region %r namespace %r" % + "for region %r namespace %r" % (region, namespace) ) query._cache_parameters = region, namespace, cache_key - + class FromCache(MapperOption): """Specifies that a Query should load results from a cache.""" @@ -187,10 +187,10 @@ self.region = region self.namespace = namespace self.cache_key = cache_key - + def process_query(self, query): """Process a Query during normal loading operation.""" - + _set_cache_parameters(query, self.region, self.namespace, self.cache_key) class RelationshipCache(MapperOption): @@ -263,13 +263,13 @@ v = [] def visit_bindparam(bind): value = query._params.get(bind.key, bind.value) - + # lazyloader may dig a callable in here, intended # to late-evaluate params after autoflush is called. # convert to a scalar value. if callable(value): value = value() - + v.append(value) if query._criterion is not None: visitors.traverse(query._criterion, {}, {'bindparam':visit_bindparam})
--- a/rhodecode/model/scm.py Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/model/scm.py Sun Nov 28 05:26:26 2010 +0100 @@ -46,7 +46,7 @@ from rhodecode.model.user import UserModel from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \ - UserFollowing + UserFollowing, UserLog from rhodecode.model.caching_query import FromCache from sqlalchemy.orm import joinedload @@ -333,6 +333,11 @@ return self.sa.query(Repository)\ .filter(Repository.fork_id == repo_id).count() + + def get_unread_journal(self): + return self.sa.query(UserLog).count() + + def _should_invalidate(self, repo_name): """ Looks up database for invalidation signals for this repo_name
--- a/rhodecode/public/css/style.css Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/public/css/style.css Sun Nov 28 05:26:26 2010 +0100 @@ -190,18 +190,32 @@ padding:0 30px; } + +#header ul#logged-user{ +margin-bottom:5px !important; +-webkit-border-radius: 0px 0px 8px 8px; +-khtml-border-radius: 0px 0px 8px 8px; +-moz-border-radius: 0px 0px 8px 8px; +border-radius: 0px 0px 8px 8px; +height:37px; +background:url("../images/header_inner.png") repeat-x scroll 0 0 #003367 +} + #header ul#logged-user li { list-style:none; float:left; -border-left:1px solid #bbb; -border-right:1px solid #a5a5a5; -margin:-2px 0 0; -padding:10px 12px; +margin:8px 0 0; +padding:4px 12px; +border-left: 1px solid #316293; } #header ul#logged-user li.first { border-left:none; -margin:-6px; +margin:4px; +} + +#header ul#logged-user li.first div.gravatar { +margin-top:-2px; } #header ul#logged-user li.first div.account { @@ -214,13 +228,12 @@ } #header ul#logged-user li a { -color:#4e4e4e; +color:#fff; font-weight:700; text-decoration:none; } #header ul#logged-user li a:hover { -color:#376ea6; text-decoration:underline; } @@ -229,7 +242,7 @@ } #header ul#logged-user li.highlight a:hover { -color:#376ea6; +color:#FFF; } #header #header-inner {
--- a/rhodecode/templates/base/base.html Sat Nov 27 20:32:34 2010 +0100 +++ b/rhodecode/templates/base/base.html Sun Nov 28 05:26:26 2010 +0100 @@ -16,26 +16,34 @@ <div id="header"> <!-- user --> <ul id="logged-user"> - %if c.rhodecode_user.username == 'default': - <li class="first"> - <div class="account"> - ## ${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('#'))}<br/> - ## ${h.link_to(c.rhodecode_user.username,h.url('#'))} - </div> - </li> - <li class="last highlight">${h.link_to(u'Login',h.url('login_home'))}</li> - %else: <li class="first"> <div class="gravatar"> - <img alt="gravatar" src="${h.gravatar_url(c.rhodecode_user.email,24)}" /> + <img alt="gravatar" src="${h.gravatar_url(c.rhodecode_user.email,20)}" /> </div> <div class="account"> - ${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('admin_settings_my_account'))}<br/> + %if c.rhodecode_user.username == 'default': + ##${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('register'))}<br/> + ${h.link_to('anonymous',h.url('register'))} + %else: + ##${h.link_to('%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname),h.url('admin_settings_my_account'))}<br/> ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'))} + %endif </div> </li> - <li class="last highlight">${h.link_to(u'Logout',h.url('logout_home'))}</li> - %endif + <li> + <a href="${h.url('home')}">${_('Home')}</a> + </li> + <li> + <a href="${h.url('journal')}">${_('Journal')}</a> + ##(${c.unread_journal})</a> + </li> + %if c.rhodecode_user.username == 'default': + <li class="last highlight">${h.link_to(u'Login',h.url('login_home'))}</li> + %else: + <li class="last highlight">${h.link_to(u'Log Out',h.url('logout_home'))}</li> + %endif + + </ul> <!-- end user --> <div id="header-inner" class="title top-left-rounded-corner top-right-rounded-corner">