Changeset - 928416088790
[Not reviewed]
default
0 7 0
Marcin Kuzminski - 16 years ago 2010-04-17 22:17:17
marcin@python-blog.com
reimplemented summary page,
added few filters, removed age from models and made it as filter.
7 files changed with 33 insertions and 23 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -27,11 +27,12 @@ def make_map(config):
 
    
 
    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='hg', action='view')    
 
    map.connect('summary_home', '/{repo_name}/_summary', controller='hg', action='view')
 
    
 
    map.connect('hg', '/{path_info:.*}', controller='hg',
 
                action="view", path_info='/')
 

	
 
    return map
pylons_app/controllers/hg.py
Show inline comments
 
@@ -35,15 +35,18 @@ class HgController(BaseController):
 
            
 
        return render('/index.html')
 

	
 
    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)
 
        if not http_accept:
 
            return abort(status_code=400, detail='no http accept in header')
 
        
 
@@ -76,7 +79,10 @@ class HgController(BaseController):
 
        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/lib/app_globals.py
Show inline comments
 
@@ -19,15 +19,12 @@ class Globals(object):
 
    def __init__(self, config):
 
        """One instance of Globals is created during application
 
        initialization and is available during requests via the
 
        'app_globals' variable
 

	
 
        """
 
        #two ways of building the merc app i don't know 
 
        #the fastest one but belive the wsgiapp is better
 
        #self.hgapp = self.make_web_app()
 
        self.cache = CacheManager(**parse_cache_config_options(config))
 
        self.hgapp = wsgiapplication(self.make_web_app)
 

	
 
    def make_web_app(self):
 
        repos = "hgwebdir.config"
 
        baseui = ui.ui()
pylons_app/lib/filters.py
Show inline comments
 
from mercurial import util
 
from mercurial.templatefilters import age as _age
 

	
 
age = lambda context, x:_age(x)
 
capitalize = lambda x: x.capitalize()
 
date = lambda x: util.datestr(x)
 
email = util.email
 
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])
 
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 x: util.datestr(x, "%Y-%m-%dT%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")
pylons_app/model/hg_model.py
Show inline comments
 
@@ -12,13 +12,12 @@ import os
 
from pylons import tmpl_context as c, app_globals as g, session, request, config
 
from pylons.controllers.util import abort
 
try:
 
    from vcs.backends.hg import get_repositories, MercurialRepository
 
except ImportError:
 
    print 'You have to import vcs module'
 
from mercurial.templatefilters import age
 

	
 
class HgModel(object):
 
    """
 
    Mercurial Model
 
    """
 

	
 
@@ -40,21 +39,21 @@ class HgModel(object):
 
            tip = mercurial_repo.repo.changectx('tip')
 
            tmp_d = {}
 
            tmp_d['name'] = mercurial_repo.name
 
            tmp_d['name_sort'] = tmp_d['name']
 
            tmp_d['description'] = mercurial_repo.description
 
            tmp_d['description_sort'] = tmp_d['description']
 
            tmp_d['last_change'] = age(last_change)
 
            tmp_d['last_change'] = last_change
 
            tmp_d['last_change_sort'] = last_change[1] - last_change[0]
 
            tmp_d['tip'] = str(tip)
 
            tmp_d['tip_sort'] = tip.rev()
 
            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()
 
            
 
            yield tmp_d
 

	
 
    def get_repo(self, repo_name):
 
        path = g.paths[0][1]
 
        repo = MercurialRepository(os.path.join(path, repo_name), g.baseui)
 
        path = g.paths[0][1].replace('*', '')
 
        repo = MercurialRepository(os.path.join(path, repo_name), baseui=g.baseui)
 
        return repo
pylons_app/templates/index.html
Show inline comments
 
@@ -33,15 +33,15 @@
 
	    <td>${get_sort(_('Contact'))}</td>
 
	    <td></td>
 
	    <td></td>
 
	  </tr>	
 
	%for cnt,repo in enumerate(c.repos_list):
 
 		<tr class="parity${cnt%2}">
 
		    <td><a href="/${repo['name']}">${repo['name']}</a></td>
 
		    <td>${h.link(repo['name'],h.url('summary_home',repo_name=repo['name']))}</td>
 
		    <td>${repo['description']}</td>
 
	        <td>${repo['last_change']}</td>
 
	        <td>${repo['last_change']|n,self.f.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
pylons_app/templates/summary.html
Show inline comments
 
@@ -37,45 +37,49 @@
 
        <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}</dd>
 
        <dd>${c.repo_info.last_change|n,self.f.time_ago}</dd>
 
    </dl>
 

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

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

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

	
 
</%def>    
 
\ No newline at end of file
0 comments (0 inline, 0 general)