Changeset - 30d3161c6683
[Not reviewed]
beta
0 5 0
Marcin Kuzminski - 15 years ago 2010-11-28 05:26:26
marcin@python-works.com
Implemented fancier top menu for logged and anonymous users
little error fix for cached query
5 files changed with 65 insertions and 38 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/base.py
Show inline comments
 
@@ -21,10 +21,12 @@ class BaseController(WSGIController):
 
        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 @@ class BaseController(WSGIController):
 
                c.repository_followers = 0
 
                c.repository_forks = 0
 

	
 
        self.sa = meta.Session()
 

	
 
    def __call__(self, environ, start_response):
 
        """Invoke the Controller"""
rhodecode/model/caching_query.py
Show inline comments
 
@@ -55,11 +55,11 @@ class CachingQuery(Query):
 
    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 @@ class CachingQuery(Query):
 
        """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 query_callable(manager):
 

	
 
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 @@ def _get_cache_parameters(query):
 
        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 @@ def _namespace_from_query(namespace, que
 
    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 @@ class FromCache(MapperOption):
 
        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 @@ def _params_from_query(query):
 
    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})
rhodecode/model/scm.py
Show inline comments
 
@@ -46,7 +46,7 @@ from rhodecode.model import BaseModel
 
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 @@ class ScmModel(BaseModel):
 
        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
rhodecode/public/css/style.css
Show inline comments
 
@@ -190,18 +190,32 @@ margin:0;
 
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 @@ border-right:none;
 
}
 
 
#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 @@ color:#fff;
 
}
 
 
#header ul#logged-user li.highlight a:hover {
 
color:#376ea6;
 
color:#FFF;
 
}
 
 
#header #header-inner {
rhodecode/templates/base/base.html
Show inline comments
 
@@ -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">
0 comments (0 inline, 0 general)