Changeset - e96bc5a01490
[Not reviewed]
default
0 2 0
Marcin Kuzminski - 16 years ago 2010-04-09 01:42:48
marcin@python-blog.com
Implemented main page sorting
2 files changed with 34 insertions and 8 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/hg.py
Show inline comments
 
@@ -15,6 +15,7 @@ except ImportError:
 
from mercurial.util import matchdate, Abort, makedate
 
from mercurial.hgweb.common import get_contact
 
from mercurial.templatefilters import age
 
from operator import itemgetter
 
log = logging.getLogger(__name__)
 

	
 
class HgController(BaseController):
 
@@ -25,6 +26,7 @@ class HgController(BaseController):
 

	
 
    def index(self):
 
        c.repos_list = []
 
        c.current_sort = request.GET.get('sort', 'name')
 
        
 
        def get_mtime(spath):
 
            cl_path = os.path.join(spath, "00changelog.i")
 
@@ -40,20 +42,37 @@ class HgController(BaseController):
 
                                                    untrusted=True):
 
                    yield {"type" : i[0], "extension": i[1],
 
                           "node": nodeid, "url": url}
 
                                    
 

	
 
        for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items():
 
            last_change = (get_mtime(r.spath), makedate()[1])
 
            tip = r.changectx('tip')
 
            tmp_d = {}
 
            tmp_d['name'] = name
 
            tmp_d['desc'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
 
            tmp_d['name_sort'] = tmp_d['name']
 
            tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
 
            tmp_d['description_sort'] = tmp_d['description']
 
            tmp_d['last_change'] = age(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'] = get_contact(r.ui.config)
 
            tmp_d['contact_sort'] = get_contact(r.ui.config)
 
            tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa')
 
            
 
            c.repos_list.append(tmp_d)
 
        
 
        cs = c.current_sort
 
        c.cs_slug = cs.replace('-', '')
 
        sortables = ['name', 'description', 'last_change', 'tip', 'contact']
 
        
 
        if cs and c.cs_slug in sortables:
 
            sort_key = c.cs_slug + '_sort'
 
            if cs.startswith('-'):
 
                c.repos_list.sort(key=itemgetter(sort_key), reverse=True)
 
            else:
 
                c.repos_list.sort(key=itemgetter(sort_key), reverse=False)
 
            
 
        return render('/index.html')
 

	
 
    def view(self, *args, **kwargs):
pylons_app/templates/index.html
Show inline comments
 
@@ -5,7 +5,7 @@
 
    ${c.repos_prefix} Mercurial Repositories
 
</%def>
 
<%def name="breadcrumbs()">
 
<h1>${c.repos_prefix} Mercurial Repositories</h1>
 
	${c.repos_prefix} Mercurial Repositories
 
</%def>
 
<%def name="page_nav()">
 
	<li class="current">${_('Home')}</li>
 
@@ -13,11 +13,16 @@
 
</%def>
 
<%def name="main()">
 
	<%def name="get_sort(name)">
 
		<%name_slug = name.lower().replace(' ','-') %>
 
		%if not name_slug.startswith('-') and c.current_sort:
 
			<%name_slug = '-'+name_slug%> 
 
		<%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}">${name}</a>
 
		
 
		<a href="?sort=${name_slug}">&darr;</a>
 
		<a href="?sort=-${name_slug}">&uarr;</a>
 
		
 
	</%def>
 
	<table>
 
	  <tr>
 
@@ -26,11 +31,13 @@
 
	    <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><a href="/${repo['name']}">${repo['name']}</a></td>
 
		    <td>${repo['desc']}</td>
 
		    <td>${repo['description']}</td>
 
	        <td>${repo['last_change']}</td>
 
	        <td>r${repo['rev']}:<a href="/${repo['name']}/rev/${repo['tip']}/">${repo['tip']}</a></td>
 
	        <td>${repo['contact']}</td>
0 comments (0 inline, 0 general)