Changeset - 670713507d03
[Not reviewed]
default
0 4 3
Marcin Kuzminski - 16 years ago 2010-04-18 00:31:58
marcin@python-blog.com
Moved summary to seperate controller,
little cleanups in templates.
added archives to summary
7 files changed with 80 insertions and 47 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -30,7 +30,7 @@ def make_map(config):
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', action='add_repo')
 
    
 
    
 
    map.connect('summary_home', '/{repo_name}/_summary', controller='hg', action='view')
 
    map.connect('summary_home', '/{repo_name}/_summary', controller='summary')
 
    
 
    map.connect('hg', '/{path_info:.*}', controller='hg',
 
                action="view", path_info='/')
pylons_app/controllers/hg.py
Show inline comments
 
@@ -6,7 +6,7 @@ from pylons_app.lib import helpers as h
 
from pylons_app.lib.base import BaseController, render
 
from mako.template import Template
 
from pylons.controllers.util import abort
 

	
 
from pylons_app.lib.utils import get_repo_slug
 
from operator import itemgetter
 
from pylons_app.model.hg_model import HgModel
 
log = logging.getLogger(__name__)
 
@@ -16,7 +16,8 @@ class HgController(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()
 
        c.repos_list = list(hg_model.get_repos())
 
@@ -37,13 +38,7 @@ class HgController(BaseController):
 

	
 
    def view(self, *args, **kwargs):
 
        #TODO: reimplement this not tu use hgwebdir
 
        
 
        #patch for replacing mercurial servings with hg_app servings
 
        vcs_impl = self._get_vcs_impl(request.environ) 
 
        if vcs_impl:
 
            return vcs_impl
 
        
 
        
 
    
 
        response = g.hgapp(request.environ, self.start_response)
 
        
 
        http_accept = request.environ.get('HTTP_ACCEPT', False)
 
@@ -68,21 +63,3 @@ class HgController(BaseController):
 

	
 

	
 
        return template.render(g=g, c=c, session=session, h=h)
 
    
 
    
 
    
 
    
 
    def _get_vcs_impl(self, environ):
 
        path_info = environ['PATH_INFO']
 
        c.repo_name = path_info.split('/')[-2]
 
        action = path_info.split('/')[-1]
 
        if not action.startswith('_'):
 
            return False
 
        else:
 
            hg_model = HgModel()
 
            c.repo_info = hg_model.get_repo(c.repo_name)
 
            c.repo_changesets = c.repo_info.get_changesets(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/controllers/summary.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
 
log = logging.getLogger(__name__)
 

	
 
class SummaryController(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()
 
        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)
 
        return render('/summary.html')
pylons_app/lib/utils.py
Show inline comments
 
new file 100644
 
   
 
def get_repo_slug(request):
 
    path_info = request.environ.get('PATH_INFO')
 
    repo_name = path_info.split('/')[-2]
 
    action = path_info.split('/')[-1]
 
    
 
    return repo_name
pylons_app/model/hg_model.py
Show inline comments
 
@@ -49,7 +49,7 @@ class HgModel(object):
 
            tmp_d['rev'] = tip.rev()
 
            tmp_d['contact'] = mercurial_repo.contact
 
            tmp_d['contact_sort'] = tmp_d['contact']
 
            tmp_d['repo_archives'] = mercurial_repo._get_archive_list()
 
            tmp_d['repo_archives'] = mercurial_repo._get_archives()
 
            
 
            yield tmp_d
 

	
pylons_app/templates/summary.html
Show inline comments
 
@@ -11,8 +11,7 @@
 
    ${_('summary')}
 
</%def>
 
<%def name="page_nav()">
 
        <form action="{url}log">
 
            {sessionvars%hiddenformentry}
 
        <form action="log">
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
@@ -21,29 +20,40 @@
 

	
 
        <ul class="page-nav">
 
            <li class="current">summary</li>
 
            <li><a href="{url}shortlog{sessionvars%urlparameter}">shortlog</a></li>
 
            <li><a href="{url}log{sessionvars%urlparameter}">changelog</a></li>
 
            <li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
 
            <li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
 
            <li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
 
            <li><a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a></li>
 
        </ul>
 
            <li><a href="shortlog">shortlog</a></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>
 
        <dt>${_('name')}</dt>
 
        <dd>${c.repo_info.name}</dd>
 
        <dt>description</dt>
 
        <dt>${_('description')}</dt>
 
        <dd>${c.repo_info.description}</dd>
 
        <dt>contact</dt>
 
        <dt>${_('contact')}</dt>
 
        <dd>${c.repo_info.contact}</dd>
 
        <dt>last change</dt>
 
        <dt>${_('last change')}</dt>
 
        <dd>${c.repo_info.last_change|n,self.f.rfc822date} - ${c.repo_info.last_change|n,self.f.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{sessionvars%urlparameter}">Changes</a></h2>
 
    <h2><a href="{url}shortlog">Changes</a></h2>
 
    <table>
 
	%for cnt,cs in enumerate(c.repo_changesets):
 
		<tr class="parity${cnt%2}">
 
@@ -58,17 +68,17 @@
 
		</tr>
 
	%endfor
 
        <tr class="light">
 
            <td colspan="4"><a class="list" href="{url}shortlog{sessionvars%urlparameter}">...</a></td>
 
            <td colspan="4"><a class="list" href="shortlog">...</a></td>
 
        </tr>
 
    </table>
 

	
 
    <h2><a href="{url}tags{sessionvars%urlparameter}">${_('Tags')}</a></h2>
 
    <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="{url}tags{sessionvars%urlparameter}">...</a></td>
 
            <td colspan="3"><a class="list" href="tags">...</a></td>
 
        </tr>
 
    </table>
 

	
 
@@ -78,7 +88,7 @@
 
			${branch}
 
		%endfor
 
        <tr class="light">
 
          <td colspan="4"><a class="list"  href="#">...</a></td>
 
          <td colspan="4"><a class="list"  href="branches">...</a></td>
 
        </tr>
 
    </table>
 

	
pylons_app/tests/functional/test_summary.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestSummaryController(TestController):
 

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