Changeset - 5e2470ebdbc6
[Not reviewed]
default
0 7 0
Marcin Kuzminski - 16 years ago 2010-04-26 00:38:53
marcin@python-works.com
Added repo switcher, in base and long term caching for this.
7 files changed with 59 insertions and 12 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
@@ -36,28 +36,30 @@ port = 5000
 
use = egg:pylons_app
 
full_stack = true
 
static_files = true
 
lang=en
 
cache_dir = %(here)s/data
 
repos_name = Python-works
 

	
 
####################################
 
###         BEAKER CACHE        ####
 
####################################
 
beaker.cache.data_dir=/tmp/cache/data
 
beaker.cache.lock_dir=/tmp/cache/lock
 
beaker.cache.regions=short_term
 
beaker.cache.regions=short_term,long_term
 
beaker.cache.short_term.type=file
 
beaker.cache.short_term.expire=3600
 
beaker.cache.short_term.type=memory
 
beaker.cache.short_term.expire=60
 
    
 

	
 
################################################################################
 
## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*  ##
 
## Debug mode will enable the interactive debugging tool, allowing ANYONE to  ##
 
## execute malicious code after an exception is raised.                       ##
 
################################################################################
 
#set debug = false
 

	
 
##################################
 
###       LOGVIEW CONFIG       ###
 
##################################
 
logview.sqlalchemy = #faa
 
logview.pylons.templating = #bfb
production.ini
Show inline comments
 
@@ -36,27 +36,29 @@ port = 8001
 
use = egg:pylons_app
 
full_stack = true
 
static_files = true
 
lang=en
 
cache_dir = %(here)s/data
 
repos_name = Python-works
 

	
 
####################################
 
###         BEAKER CACHE        ####
 
####################################
 
beaker.cache.data_dir=/tmp/cache/data
 
beaker.cache.lock_dir=/tmp/cache/lock
 
beaker.cache.regions=short_term
 
beaker.cache.regions=short_term,long_term
 
beaker.cache.short_term.type=file
 
beaker.cache.short_term.expire=3600
 
beaker.cache.short_term.type=memory
 
beaker.cache.short_term.expire=3600
 
beaker.cache.short_term.expire=60
 
    
 
################################################################################
 
## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*  ##
 
## Debug mode will enable the interactive debugging tool, allowing ANYONE to  ##
 
## execute malicious code after an exception is raised.                       ##
 
################################################################################
 
set debug = false
 

	
 
##################################
 
###       LOGVIEW CONFIG       ###
 
##################################
 
logview.sqlalchemy = #faa
pylons_app/config/environment.py
Show inline comments
 
@@ -39,25 +39,25 @@ def load_environment(global_conf, app_co
 
    pylons.cache._push_object(config['pylons.app_globals'].cache)
 
    
 

	
 
    # Create the Mako TemplateLookup, with the default auto-escaping
 
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
 
        directories=paths['templates'],
 
        error_handler=handle_mako_error,
 
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
 
        input_encoding='utf-8', default_filters=['escape'],
 
        imports=['from webhelpers.html import escape'])
 

	
 
    #sets the c attribute access when don't existing attribute ar accessed
 
    config['pylons.strict_tmpl_context'] = False
 
    config['pylons.strict_tmpl_context'] = True
 
    
 
    #MULTIPLE DB configs
 
    # Setup the SQLAlchemy database engine
 
    if config['debug']:
 
        #use query time debugging.
 
        from pylons_app.lib.timerproxy import TimerProxy
 
        sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
 
                                                            proxy=TimerProxy())
 
    else:
 
        sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
 

	
 
    init_model(sa_engine_db1)
pylons_app/controllers/summary.py
Show inline comments
 
@@ -18,15 +18,15 @@ class SummaryController(BaseController):
 
        hg_model = HgModel()
 
        c.repo_info = hg_model.get_repo(c.repo_name)
 
        c.repo_changesets = c.repo_info.get_changesets(10)
 
        
 
        e = request.environ
 
        uri = r'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
 
                                                'protocol': e.get('wsgi.url_scheme'),
 
                                                'user':e.get('REMOTE_USER'),
 
                                                'host':e.get('HTTP_HOST'),
 
                                                'repo_name':c.repo_name,
 
                                                }
 
        c.clone_repo_url = url(uri)
 
        #c.repo_tags = c.repo_info.get_tags(limit=10)
 
        #c.repo_branches = c.repo_info.get_branches(limit=10)
 
        c.repo_tags = []#c.repo_info.get_tags(limit=10)
 
        c.repo_branches = []#c.repo_info.get_branches(limit=10)
 
        return render('/summary.html')
pylons_app/lib/base.py
Show inline comments
 
"""The base Controller API
 

	
 
Provides the BaseController class for subclassing.
 
"""
 
from pylons.controllers import WSGIController
 
from pylons.templating import render_mako as render
 
from pylons_app.model import meta
 
from beaker.cache import cache_region
 
from pylons import tmpl_context as c
 
from pylons_app.model.hg_model import HgModel
 

	
 
class BaseController(WSGIController):
 

	
 
    def _load_repos(self):
 
                
 
        @cache_region('long_term', 'repo_list_2')
 
        def _get_repos():
 
            return [rep['name'] for rep in HgModel().get_repos()]
 
        
 
        c.repo_list = _get_repos()
 
        
 
    def __call__(self, environ, start_response):
 
        """Invoke the Controller"""
 
        # WSGIController.__call__ dispatches to the Controller method
 
        # the request is routed to. This routing information is
 
        # available in environ['pylons.routes_dict']
 
        self._load_repos()
 
        try:
 
            return WSGIController.__call__(self, environ, start_response)
 
        finally:
 
            meta.Session.remove()
pylons_app/public/css/monoblue_custom.css
Show inline comments
 
@@ -34,25 +34,25 @@ div#container {
 
  color: #666;
 
}
 

	
 
div.page-header {
 
  padding: 50px 20px 0;
 
  background: #556cb5 top left repeat-x;
 
  position: relative;
 
}
 
  div.page-header h1 {
 
    margin: 10px 0 30px;
 
    font-size: 1.8em;
 
    font-weight: bold;
 
    font-family: osaka,'MS P Gothic', Georgia, serif;
 
    font-family: sans-serif;
 
    letter-spacing: 1px;
 
    color: #DDD;
 
  }
 
  div.page-header h1 a {
 
    font-weight: bold;
 
    color: #FFF;
 
  }
 
  div.page-header a {
 
    text-decoration: none;
 
  }
 

	
 
  div.page-header form {
 
@@ -82,36 +82,39 @@ div.page-header {
 
    line-height: 20px;
 
  }
 

	
 
  ul.page-nav {
 
    margin: 10px 0 0 0;
 
    list-style-type: none;
 
    overflow: hidden;
 
    width: 800px;
 
  }
 
    ul.page-nav li {
 
      margin: 0 2px 0 0;
 
      float: left;
 
      width: 80px;
 
      height: 24px;
 
      font-size: 1.1em;
 
      line-height: 24px;
 
      text-align: center;
 
      text-align: center;    
 
    }
 
    ul.page-nav li.current {
 
      background: #FFF;
 
      padding-right:5px;
 
      padding-left:5px;
 
    }
 
    ul.page-nav li a {
 
      height: 24px;
 
      color: #666;
 
      padding-right:5px;
 
      padding-left:5px;        
 
      background: #DDD;
 
      display: block;
 
      text-decoration: none;
 
    }
 
    ul.page-nav li a:hover {
 
      color:#333;
 
      background: #FFF;
 
    }
 

	
 
ul.submenu {
 
  margin: 10px 0 -10px 20px;
 
  list-style-type: none;
pylons_app/templates/base/base.html
Show inline comments
 
@@ -42,25 +42,54 @@
 
</body>
 
</html>
 

	
 
<%def name="page_nav()">
 

	
 
	${self.menu()}
 

	
 
</%def>
 

	
 

	
 
<%def name="menu(current)">
 
        <ul class="page-nav">
 

	
 
        	<script>
 
        	YAHOO.util.Event.onDOMReady(function(){
 
				YAHOO.util.Event.addListener('repo_switcher','click',function(){
 
					if(YAHOO.util.Dom.hasClass('repo_switcher','selected')){
 
						YAHOO.util.Dom.setStyle('switch_repos','display','none');
 
						YAHOO.util.Dom.removeClass('repo_switcher','selected');
 
					}
 
					else{
 
						YAHOO.util.Dom.setStyle('switch_repos','display','');
 
						YAHOO.util.Dom.addClass('repo_switcher','selected');
 
					}
 
					});
 
				YAHOO.util.Event.addListener('repos_list','change',function(e){
 
		            var wa = YAHOO.util.Dom.get('repos_list').value;
 
		        	
 
		            var url = "${h.url('summary_home',repo_name='__REPLACE__')}".replace('__REPLACE__',wa);
 
			        window.location = url;
 
				})
 
            });
 
        	</script>
 
			<li>
 
				<a id="repo_switcher" title="${_('Switch repository')}" href="#">&darr;</a>
 
				<div id="switch_repos" style="display:none;position: absolute;width: 150px;height: 25px;background-color: #DDDDDD">
 
					<select id="repos_list">
 
					%for repo in c.repo_list:
 
						<option value="${repo}">${repo}</option>
 
					%endfor
 
					</select>
 
				</div>			
 
			</li>
 
            <li 
 
            %if current=='summary':
 
            	class='current' 
 
            %endif
 
            >${h.link_to_unless(current=='summary',_('summary'),h.url('summary_home',repo_name=c.repo_name))}</li>
 
            <li 
 
            %if current=='changelog':
 
            	class='current' 
 
            %endif
 
            >${h.link_to_unless(current=='changelog',_('changelog'),h.url('changelog_home',repo_name=c.repo_name))}</li>
 
            <li 
 
            %if current=='branches':
0 comments (0 inline, 0 general)