Changeset - db39d0ca5308
[Not reviewed]
default
0 8 4
Marcin Kuzminski - 16 years ago 2010-04-18 11:23:10
marcin@python-blog.com
implemented Shortlog as seperate controller,
filters rewrite. Little html fixes
12 files changed with 148 insertions and 22 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
################################################################################
 
################################################################################
 
# pylons_app - Pylons environment configuration                                #
 
#                                                                              # 
 
# The %(here)s variable will be replaced with the parent directory of this file#
 
################################################################################
 

	
 
[DEFAULT]
 
debug = true
 
############################################
 
## Uncomment and replace with the address ##
 
## which should receive any error reports ##
 
############################################
 
#email_to = marcin.kuzminski@etelko.pl
 
#smtp_server = mail.etelko.pl
 
#error_email_from = paste_error@localhost
 
#smtp_username = 
 
#smtp_password = 
 
#error_message = 'mercurial crash !'
 

	
 
[server:main]
 
threadpool_workers = 5
 
use = egg:Paste#http
 
host = 127.0.0.1
 
port = 5000
 

	
 
[app:main]
 
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.short_term.type=memory
 
beaker.cache.short_term.expire=3600
 
    
 
################################################################################
 
## 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
 
logview.pylons.util = #eee
 

	
 
#########################################################
 
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 
#########################################################
 
sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db
 
#sqlalchemy.db1.echo = True
 
#sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.convert_unicode = true
 

	
 
################################
 
### LOGGING CONFIGURATION   ####
 
################################
 
[loggers]
 
keys = root, routes, pylons_app, sqlalchemy
production.ini
Show inline comments
 
################################################################################
 
################################################################################
 
# pylons_app - Pylons environment configuration                                #
 
#                                                                              # 
 
# The %(here)s variable will be replaced with the parent directory of this file#
 
################################################################################
 

	
 
[DEFAULT]
 
debug = true
 
############################################
 
## Uncomment and replace with the address ##
 
## which should receive any error reports ##
 
############################################
 
#email_to = marcin.kuzminski@etelko.pl
 
#smtp_server = mail.etelko.pl
 
#error_email_from = paste_error@localhost
 
#smtp_username = 
 
#smtp_password = 
 
#error_message = 'mercurial crash !'
 

	
 
[server:main]
 
threadpool_workers = 10
 
use = egg:Paste#http
 
host = 127.0.0.1
 
port = 8001
 

	
 
[app:main]
 
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.short_term.type=memory
 
beaker.cache.short_term.expire=3600
 
    
 
################################################################################
 
## 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
 
logview.pylons.util = #eee
 

	
 
#########################################################
 
### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG    ###
 
#########################################################
 
sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db
 
#sqlalchemy.db1.echo = True
 
#sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.convert_unicode = true
 

	
 
################################
 
### LOGGING CONFIGURATION   ####
 
################################
 
[loggers]
 
keys = root, routes, pylons_app, sqlalchemy
pylons_app/config/routing.py
Show inline comments
 
"""Routes configuration
 

	
 
The more specific and detailed routes should be defined first so they
 
may take precedent over the more generic routes. For more information
 
refer to the routes manual at http://routes.groovie.org/docs/
 
"""
 
from routes import Mapper
 

	
 
def make_map(config):
 
    """Create, configure and return the routes Mapper"""
 
    map = Mapper(directory=config['pylons.paths']['controllers'],
 
                 always_scan=config['debug'])
 
    map.minimization = False
 
    map.explicit = False
 

	
 
    # The ErrorController route (handles 404/500 error pages); it should
 
    # likely stay at the top, ensuring it can always be resolved
 
    map.connect('/error/{action}', controller='error')
 
    map.connect('/error/{action}/{id}', controller='error')
 

	
 
    # CUSTOM ROUTES HERE
 
    map.connect('hg_home', '/', controller='hg', action='index')
 
    
 
    map.resource('repo', 'repos', path_prefix='/_admin')
 
    map.resource('user', 'users', path_prefix='/_admin')
 
    
 
    
 
    with map.submapper(path_prefix='/_admin', controller='admin') as m:
 
        m.connect('admin_home', '/', action='index')#main page
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo')
 
    
 
    
 
    map.connect('summary_home', '/{repo_name}/_summary', controller='summary')
 
    map.connect('shortlog_home', '/{repo_name}/_shortlog', controller='shortlog')
 
    
 
    map.connect('hg', '/{path_info:.*}', controller='hg',
 
                action="view", path_info='/')
 

	
 
    return map
pylons_app/controllers/shortlog.py
Show inline comments
 
new file 100644
 
import logging
 

	
 
from pylons import tmpl_context as c, app_globals as g, session, request, config, url
 
from pylons.controllers.util import abort, redirect
 

	
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.utils import get_repo_slug
 
from pylons_app.model.hg_model import HgModel
 
from webhelpers.paginate import Page
 
log = logging.getLogger(__name__)
 

	
 
class ShortlogController(BaseController):
 
    def __before__(self):
 
        c.repos_prefix = config['repos_name']
 
        c.staticurl = g.statics
 
        c.repo_name = get_repo_slug(request)
 
        
 
        
 
    def index(self):
 
        hg_model = HgModel()
 
        lim = 20
 
        p = int(request.params.get('page', 1))
 
        repo = hg_model.get_repo(c.repo_name)
 
        cnt = repo.revisions[-1]
 
        gen = repo.get_changesets(None)
 
        repo_changesets = list(gen)
 
        repo_changesets2 = list(gen)
 
        repo_changesets3 = list(gen)
 
        repo_changesets4 = list(gen)
 
         
 
        c.repo_changesets = Page(repo_changesets, page=p, item_count=cnt, items_per_page=lim)
 
        c.shortlog_data = render('shortlog_data.html')
 
        if request.params.get('partial'):
 
            return c.shortlog_data
 
        return render('/shortlog.html')
pylons_app/lib/filters.py
Show inline comments
 
from mercurial import util
 
from mercurial.templatefilters import age as _age
 
from mercurial.templatefilters import age as _age, person as _person
 

	
 
age = lambda context, x:_age(x)
 
age = lambda  x:_age(x)
 
capitalize = lambda x: x.capitalize()
 
date = lambda x: util.datestr(x)
 
email = util.email
 
hgdate = lambda context, x: "%d %d" % x
 
isodate = lambda context, x: util.datestr(x, '%Y-%m-%d %H:%M %1%2')
 
isodatesec = lambda context, x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2')
 
localdate = lambda context, x: (x[0], util.makedate()[1])
 
rfc822date = lambda context, x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2")
 
rfc3339date = lambda context, x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2")
 
time_ago = lambda context, x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2")
 
person = lambda x: _person(x)
 
hgdate = lambda  x: "%d %d" % x
 
isodate = lambda  x: util.datestr(x, '%Y-%m-%d %H:%M %1%2')
 
isodatesec = lambda  x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2')
 
localdate = lambda  x: (x[0], util.makedate()[1])
 
rfc822date = lambda  x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2")
 
rfc3339date = lambda  x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2")
 
time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2")
pylons_app/templates/admin_log.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
%if c.users_log:
 
<table>
 
	<tr>
 
		<td>${_('Username')}</td>
 
		<td>${_('Repository')}</td>
 
		<td>${_('Action')}</td>
 
		<td>${_('Date')}</td>
 
	</tr>
 

	
 
	%for cnt,l in enumerate(c.users_log):
 
	<tr class="parity${cnt%2}">
 
		<td>${l.user.username}</td>
 
		<td>${l.repository}</td>
 
		<td>${l.action}</td>
 
		<td>${l.action_date}</td>
 
	</tr>
 
	%endfor
 

	
 
	<tr>
 
	<script type="text/javascript">
 
	var data_div = 'user_log';
 
	YAHOO.util.Event.onDOMReady(function(){
 
		YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
				YAHOO.util.Dom.setStyle('shortlog_data','opacity','0.3');});});
 
	</script>
 
		<td>${c.users_log.pager('$link_previous ~2~ $link_next',
 
		onclick="""YAHOO.util.Connect.asyncRequest('GET','$partial_url',{
 
		success:function(o){YAHOO.util.Dom.get('user_log').innerHTML=o.responseText;}
 
		},null); return false;""")}</td>
 
	</tr>
 
		success:function(o){YAHOO.util.Dom.get(data_div).innerHTML=o.responseText;
 
		YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
				YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');});		
 
		YAHOO.util.Dom.setStyle(data_div,'opacity','1');}},null); return false;""")}</td>
 
	</tr>	
 
</table>
 

	
 
%else: 
 
	${_('No actions yet')} 
 
%endif
pylons_app/templates/base/base.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
##filters definition
 
<%namespace name="f" module="pylons_app.lib.filters" inheritable="True"/>
 

	
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
    <link rel="icon" href="${c.staticurl}hgicon.png" type="image/png" />
 
    <meta name="robots" content="index, nofollow"/>
 
    <link rel="stylesheet" href="${c.staticurl}style-monoblue.css" type="text/css" />
 
       <title>${next.title()}</title>
 
    ${self.js()}
 
</head>
 

	
 
<body>
 
<div id="container">
 
    <div class="page-header">
 
        <h1>
 
            ${next.breadcrumbs()}
 
        </h1>
 
        <ul class="page-nav">
 
            ${next.page_nav()}
 
        </ul>
 
    </div>
 
    ${next.main()}
 
    <div class="page-footer">
 
        Mercurial App &copy; 2010
 
    </div>   
 

	
 
    <div id="powered-by">
 
        <p>
 
        <a href="http://mercurial.selenic.com/" title="Mercurial">
 
            <img src="${c.staticurl}hglogo.png" width="75" height="90" alt="mercurial"/></a>
 
        </p>
 
    </div>
 

	
 
    <div id="corner-top-left"></div>
 
    <div id="corner-top-right"></div>
 
    <div id="corner-bottom-left"></div>
 
    <div id="corner-bottom-right"></div>
 

	
 
</div>
 
</body>
 
</html>
 

	
 

	
 
<%def name="js()">
 
<script type="text/javascript" src="/js/yui/utilities/utilities.js"></script>
 
</%def>
 
\ No newline at end of file
pylons_app/templates/index.html
Show inline comments
 
## -*- coding: utf-8 -*-
 

	
 
<%!
 
from pylons_app.lib import filters
 
%>
 
<%inherit file="base/base.html"/>
 
<%def name="title()">
 
    ${c.repos_prefix} Mercurial Repositories
 
</%def>
 
<%def name="breadcrumbs()">
 
	${c.repos_prefix} Mercurial Repositories
 
</%def>
 
<%def name="page_nav()">
 
	<li class="current">${_('Home')}</li>
 
	<li>${h.link_to(u'Admin',h.url('admin_home'))}</li>
 
</%def>
 
<%def name="main()">
 
	<%def name="get_sort(name)">
 
		<%name_slug = name.lower().replace(' ','_') %>
 
		%if name_slug == c.cs_slug:
 
			<span style="font-weight: bold;color:#006699">${name}</span>
 
		%else:
 
			<span style="font-weight: bold">${name}</span>
 
		%endif
 
		
 
		<a href="?sort=${name_slug}">&darr;</a>
 
		<a href="?sort=-${name_slug}">&uarr;</a>
 
		
 
	</%def>
 
	<table>
 
	  <tr>
 
	    <td>${get_sort(_('Name'))}</td>
 
	    <td>${get_sort(_('Description'))}</td>
 
	    <td>${get_sort(_('Last change'))}</td>
 
	    <td>${get_sort(_('Tip'))}</td>
 
	    <td>${get_sort(_('Contact'))}</td>
 
	    <td></td>
 
	    <td></td>
 
	  </tr>	
 
	%for cnt,repo in enumerate(c.repos_list):
 
 		<tr class="parity${cnt%2}">
 
		    <td>${h.link(repo['name'],h.url('summary_home',repo_name=repo['name']))}</td>
 
		    <td>${repo['description']}</td>
 
	        <td>${repo['last_change']|n,self.f.age}</td>
 
	        <td>${repo['last_change']|n,filters.age}</td>
 
	        <td>r${repo['rev']}:<a href="/${repo['name']}/rev/${repo['tip']}/">${repo['tip']}</a></td>
 
	        <td>${repo['contact']}</td>
 
	        <td class="indexlinks">
 
	        	%for archive in repo['repo_archives']:
 
					<a href="/${repo['name']}/archive/${archive['node']}${archive['extension']}">${archive['type']}</a>
 
				%endfor
 
	        </td>
 
			<td>
 
				<div class="rss_logo">
 
				<a href="/${repo['name']}/rss-log">RSS</a>
 
				<a href="/${repo['name']}/atom-log">Atom</a>
 
				</div>
 
			</td>        
 
		</tr>
 
	%endfor
 
	</table>
 
</%def>    
pylons_app/templates/shortlog.html
Show inline comments
 
new file 100644
 
<%inherit file="base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('shortlog_home',repo_name=c.repo_name))}
 
    /
 
    ${_('shortlog')}
 
</%def>
 
<%def name="page_nav()">
 
        <form action="log">
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
        <ul class="page-nav">
 
            <li>${h.link(_('summary'),h.url('summary_home',repo_name=c.repo_name))}</li>
 
            <li class="current">${_('shortlog')}</li>
 
            <li><a href="log">changelog</a></li>
 
            <li><a href="graph/{node|short}">graph</a></li>
 
            <li><a href="tags">tags</a></li>
 
            <li><a href="branches">branches</a></li>
 
            <li><a href="file/{node|short}">files</a></li>
 
        </ul>      
 
</%def>
 
<%def name="main()">
 

	
 
    <h2 class="no-link no-border">${_('Shortlog')}</h2>
 

	
 
	<div id="shortlog_data">
 
		${c.shortlog_data}
 
	</div>
 
</%def>    
 
\ No newline at end of file
pylons_app/templates/shortlog_data.html
Show inline comments
 
new file 100644
 
## -*- coding: utf-8 -*-
 
<%!
 
from pylons_app.lib import filters
 
%>
 
<table>
 
%for cnt,cs in enumerate(c.repo_changesets):
 
	<tr class="parity${cnt%2}">
 
		<td>${cs._ctx.date()|n,filters.age}</td>
 
		<td title="${cs.author}">${cs.author|n,filters.person}</td>
 
		<td>${h.link_to(cs.message,h.url('rev/'+str(cs._ctx)))}</td>
 
		<td class="nowrap">
 
		${h.link_to(_('changeset'),h.url('file/'+str(cs._ctx)))}
 
		|
 
		${h.link_to(_('files'),h.url('file/'+str(cs._ctx)))}
 
		</td>
 
	</tr>
 
%endfor
 
	<tr>
 
	<script type="text/javascript">
 
	var data_div = 'shortlog_data';
 
	YAHOO.util.Event.onDOMReady(function(){
 
		YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
				YAHOO.util.Dom.setStyle('shortlog_data','opacity','0.3');});});
 
	</script>
 
		<td>${c.repo_changesets.pager('$link_previous ~2~ $link_next',
 
		onclick="""YAHOO.util.Connect.asyncRequest('GET','$partial_url',{
 
		success:function(o){YAHOO.util.Dom.get(data_div).innerHTML=o.responseText;
 
		YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
				YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');});		
 
		YAHOO.util.Dom.setStyle(data_div,'opacity','1');}},null); return false;""")}</td>
 
	</tr>
 
</table>	
 
\ No newline at end of file
pylons_app/templates/summary.html
Show inline comments
 
<%inherit file="base/base.html"/>
 

	
 
<%!
 
from pylons_app.lib import filters
 
%>
 
<%def name="title()">
 
    ${_('Repository managment')}
 
</%def>
 
<%def name="breadcrumbs()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    / 
 
    ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
 
    /
 
    ${_('summary')}
 
</%def>
 
<%def name="page_nav()">
 
        <form action="log">
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
        <ul class="page-nav">
 
            <li class="current">summary</li>
 
            <li><a href="shortlog">shortlog</a></li>
 
            <li class="current">${_('summary')}</li>
 
            <li>${h.link(_('shortlog'),h.url('shortlog_home',repo_name=c.repo_name))}</li>
 
            <li><a href="log">changelog</a></li>
 
            <li><a href="graph/{node|short}">graph</a></li>
 
            <li><a href="tags">tags</a></li>
 
            <li><a href="branches">branches</a></li>
 
            <li><a href="file/{node|short}">files</a></li>
 
        </ul>      
 
</%def>
 
<%def name="main()">
 

	
 
    <h2 class="no-link no-border">${_('Mercurial Repository Overview')}</h2>
 
    <dl class="overview">
 
        <dt>${_('name')}</dt>
 
        <dd>${c.repo_info.name}</dd>
 
        <dt>${_('description')}</dt>
 
        <dd>${c.repo_info.description}</dd>
 
        <dt>${_('contact')}</dt>
 
        <dd>${c.repo_info.contact}</dd>
 
        <dt>${_('last change')}</dt>
 
        <dd>${c.repo_info.last_change|n,self.f.rfc822date} - ${c.repo_info.last_change|n,self.f.age}</dd>
 
        <dd>${c.repo_info.last_change|n,filters.rfc822date} - ${c.repo_info.last_change|n,filters.age}</dd>
 
        <dt>${_('url')}</dt>
 
        <dd><pre>$ hg clone <a href="${c.clone_repo_url}">${c.clone_repo_url}</a></pre></dd>
 
        <dt>${_('Download')}</dt>
 
        <dd>
 
       	%for archive in c.repo_info._get_archives():
 
				| <a href="/${c.repo_info.name}/archive/${archive['node']}${archive['extension']}">
 
				${c.repo_info.name}.${archive['type']}
 
				</a>
 
		%endfor
 
		| 
 
        </dd>
 
    </dl>
 

	
 
    <h2><a href="{url}shortlog">Changes</a></h2>
 
    <table>
 
	%for cnt,cs in enumerate(c.repo_changesets):
 
		<tr class="parity${cnt%2}">
 
			<td>${cs._ctx.date()|n,self.f.age}</td>
 
			<td>${cs._ctx.date()|n,filters.age}</td>
 
			<td>${cs.author}</td>
 
			<td>${h.link_to(cs.message,h.url('rev/'+str(cs._ctx)))}</td>
 
			<td class="nowrap">
 
			${h.link_to(_('changeset'),h.url('file/'+str(cs._ctx)))}
 
			|
 
			${h.link_to(_('files'),h.url('file/'+str(cs._ctx)))}
 
			</td>
 
		</tr>
 
	%endfor
 
        <tr class="light">
 
            <td colspan="4"><a class="list" href="shortlog">...</a></td>
 
        </tr>
 
    </table>
 

	
 
    <h2><a href="{url}tags">${_('Tags')}</a></h2>
 
    <table>
 
		%for tag in c.repo_tags:
 
			${tag}
 
		%endfor
 
        <tr class="light">
 
            <td colspan="3"><a class="list" href="tags">...</a></td>
 
        </tr>
 
    </table>
 

	
 
    <h2 class="no-link">Branches</h2>
 
    <table>
 
		%for branch in c.repo_branches:
 
			${branch}
 
		%endfor
 
        <tr class="light">
 
          <td colspan="4"><a class="list"  href="branches">...</a></td>
 
        </tr>
 
    </table>
 

	
 
</%def>    
 
\ No newline at end of file
pylons_app/tests/functional/test_shortlog.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestShortlogController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='shortlog', action='index'))
 
        # Test response...
0 comments (0 inline, 0 general)