changeset 282:237470e64bb8

switched filters into webhelpers for easy of usage. Rewrite of html to use predefined templates from branches shortlog tags, for DRY usage. Added info messages about empty branches/tags etc.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 13 Jun 2010 23:56:16 +0200
parents cd2ee462fc2c
children 0cf49c29c846
files pylons_app/controllers/changelog.py pylons_app/controllers/graph.py pylons_app/controllers/summary.py pylons_app/lib/filters.py pylons_app/lib/helpers.py pylons_app/templates/branches/branches.html pylons_app/templates/branches/branches_data.html pylons_app/templates/changelog/changelog.html pylons_app/templates/changeset/changeset.html pylons_app/templates/errors/error_404.html pylons_app/templates/index.html pylons_app/templates/login.html pylons_app/templates/shortlog/shortlog_data.html pylons_app/templates/summary/summary.html pylons_app/templates/tags/tags.html pylons_app/templates/tags/tags_data.html
diffstat 16 files changed, 119 insertions(+), 225 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/controllers/changelog.py	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/controllers/changelog.py	Sun Jun 13 23:56:16 2010 +0200
@@ -49,12 +49,13 @@
             session['changelog_size'] = c.size
             session.save()
         else:
-            c.size = session.get('changelog_size', default)
+            c.size = int(session.get('changelog_size', default))
 
         changesets = HgModel().get_repo(c.repo_name)
             
         p = int(request.params.get('page', 1))
-        c.pagination = Page(changesets, page=p, item_count=len(changesets),
+        c.total_cs = len(changesets)
+        c.pagination = Page(changesets, page=p, item_count=c.total_cs,
                             items_per_page=c.size)
             
         #self._graph(c.repo, c.size,p)
--- a/pylons_app/controllers/graph.py	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/controllers/graph.py	Sun Jun 13 23:56:16 2010 +0200
@@ -25,9 +25,9 @@
 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
 from mercurial.node import short
 from pylons import request, tmpl_context as c
+import pylons_app.lib.helpers as h
 from pylons_app.lib.auth import LoginRequired
 from pylons_app.lib.base import BaseController, render
-from pylons_app.lib.filters import age as _age, person
 from pylons_app.model.hg_model import HgModel
 from simplejson import dumps
 from webhelpers.paginate import Page
@@ -74,9 +74,9 @@
             if type != CHANGESET:
                 continue
             node = short(ctx.node())
-            age = _age(ctx.date())
+            age = h.age(ctx.date())
             desc = ctx.description()
-            user = person(ctx.user())
+            user = h.person(ctx.user())
             branch = ctx.branch()
             branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
             data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
--- a/pylons_app/controllers/summary.py	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/controllers/summary.py	Sun Jun 13 23:56:16 2010 +0200
@@ -25,7 +25,8 @@
 from pylons import tmpl_context as c, request
 from pylons_app.lib.auth import LoginRequired
 from pylons_app.lib.base import BaseController, render
-from pylons_app.model.hg_model import HgModel, _full_changelog_cached
+from pylons_app.model.hg_model import HgModel
+from webhelpers.paginate import Page
 import logging
 
 log = logging.getLogger(__name__)
@@ -39,7 +40,7 @@
     def index(self):
         hg_model = HgModel()
         c.repo_info = hg_model.get_repo(c.repo_name)
-        c.repo_changesets = _full_changelog_cached(c.repo_name)[:10]
+        c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
         e = request.environ
         uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
                                         'protocol': e.get('wsgi.url_scheme'),
--- a/pylons_app/lib/filters.py	Sun Jun 13 23:14:04 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#!/usr/bin/env python
-# encoding: utf-8
-# simple filters for hg apps html templates
-# Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
- 
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; version 2
-# of the License or (at your opinion) any later version of the license.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA  02110-1301, USA.
-
-"""
-Created on April 12, 2010
-simple filters for hg apps html templates
-@author: marcink
-"""
-
-from mercurial import util
-from mercurial.templatefilters import age as _age, person as _person
-
-age = lambda  x:_age(x)
-capitalize = lambda x: x.capitalize()
-date = lambda x: util.datestr(x)
-email = util.email
-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")
--- a/pylons_app/lib/helpers.py	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/lib/helpers.py	Sun Jun 13 23:56:16 2010 +0200
@@ -203,3 +203,29 @@
     return slug
 
 flash = _Flash()
+
+
+#===============================================================================
+# MERCURIAL FILTERS available via h.
+#===============================================================================
+
+
+from mercurial import util
+from mercurial.templatefilters import age as _age, person as _person
+
+age = lambda  x:_age(x)
+capitalize = lambda x: x.capitalize()
+date = lambda x: util.datestr(x)
+email = util.email
+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")
+
+
+
+
--- a/pylons_app/templates/branches/branches.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/branches/branches.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,5 +1,4 @@
 <%inherit file="/base/base.html"/>
-<%! from pylons_app.lib import filters %>
 <%def name="title()">
     ${_('Branches')}
 </%def>
@@ -14,33 +13,6 @@
 	${self.menu('branches')}    
 </%def>
 <%def name="main()">
-
     <h2 class="no-link no-border">${_('Branches')}</h2>
-
-    <table class="table_disp">
-    	<tr class="header">
-			<td>${_('date')}</td>
-			<td>${_('revision')}</td>
-			<td>${_('name')}</td>
-			<td>${_('links')}</td>
-    	</tr>
-		%for cnt,branch in enumerate(c.repo_branches.items()):
-		<tr class="parity${cnt%2}">
-			<td>${branch[1]._ctx.date()|n,filters.age}</td>
-			<td>r${branch[1].revision}:${branch[1].raw_id}</td>
-			<td>
-				<span class="logtags">
-					<span class="branchtag">${h.link_to(branch[0],
-					h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}</span>
-				</span>			
-			</td>
-			<td class="nowrap">
-			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
-			|
-			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
-			</td>
-		</tr>	
-		%endfor
-    </table>
-
+	<%include file='branches_data.html'/>
 </%def>    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/branches/branches_data.html	Sun Jun 13 23:56:16 2010 +0200
@@ -0,0 +1,30 @@
+% if c.repo_branches:
+    <table class="table_disp">
+    	<tr class="header">
+			<td>${_('date')}</td>
+			<td>${_('revision')}</td>
+			<td>${_('name')}</td>
+			<td>${_('links')}</td>
+    	</tr>
+		%for cnt,branch in enumerate(c.repo_branches.items()):
+		<tr class="parity${cnt%2}">
+			<td>${h.age(branch[1]._ctx.date())}</td>
+			<td>r${branch[1].revision}:${branch[1].raw_id}</td>
+			<td>
+				<span class="logtags">
+					<span class="branchtag">${h.link_to(branch[0],
+					h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}</span>
+				</span>			
+			</td>
+			<td class="nowrap">
+			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
+			|
+			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
+			</td>
+		</tr>	
+		%endfor
+    </table>
+%else:
+	${_('There are no branches yet')}
+%endif
+
--- a/pylons_app/templates/changelog/changelog.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/changelog/changelog.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,6 +1,3 @@
-<%!
-from pylons_app.lib import filters
-%>
 <%inherit file="/base/base.html"/>
 
 <%def name="title()">
@@ -19,8 +16,12 @@
 
 <%def name="main()">
 
-    <h2 class="no-link no-border">${_('Changelog')} - ${_('showing last ')} ${c.size} ${_('revisions')}</h2>
+    <h2 class="no-link no-border">${_('Changelog')} - ${_('showing ')} 
+    	${c.size if c.size <= c.total_cs else c.total_cs}
+    	${_('out of')} ${c.total_cs} ${_('revisions')}
+    </h2>
 	<noscript>${_('The revision graph only works with JavaScript-enabled browsers.')}</noscript>
+% if c.pagination:
 
 <div id="graph">
 	##<div id="graph_nodes" style="height:1000px">
@@ -89,4 +90,7 @@
 <div>
 	<h2>${c.pagination.pager('$link_previous ~2~ $link_next')}</h2>
 </div>	
+%else:
+	${_('There are no changes yet')}
+%endif
 </%def>    
\ No newline at end of file
--- a/pylons_app/templates/changeset/changeset.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/changeset/changeset.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,6 +1,3 @@
-<%!
-from pylons_app.lib import filters
-%>
 <%inherit file="/base/base.html"/>
 
 <%def name="title()">
--- a/pylons_app/templates/errors/error_404.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/errors/error_404.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,4 @@
 ## -*- coding: utf-8 -*-
-<%!
-from pylons_app.lib import filters
-%>
 <%inherit file="./../base/base.html"/>
             
 <%def name="title()">
--- a/pylons_app/templates/index.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/index.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,4 @@
 ## -*- coding: utf-8 -*-
-<%!
-from pylons_app.lib import filters
-%>
 <%inherit file="base/base.html"/>
 <%def name="title()">
     ${c.repos_prefix} Mercurial Repositories
@@ -38,12 +35,12 @@
 		    <td>${h.link_to(repo['name'],
 		    	h.url('summary_home',repo_name=repo['name']))}</td>
 		    <td title="${repo['description']}">${h.truncate(repo['description'],60)}</td>
-	        <td>${repo['last_change']|n,filters.age}</td>
+	        <td>${h.age(repo['last_change'])}</td>
 	        <td>${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),
 		        h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']),
 	        	class_="tooltip",
 		    	tooltip_title=h.tooltip(repo['last_msg']))}</td>
-	        <td title="${repo['contact']}">${repo['contact']|n,filters.person}</td>
+	        <td title="${repo['contact']}">${h.person(repo['contact'])}</td>
 			<td>
 				<a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_logo"  href="${h.url('rss_feed_home',repo_name=repo['name'])}"></a>
 			</td>        
--- a/pylons_app/templates/login.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/login.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,4 @@
 ## -*- coding: utf-8 -*-
-<%!
-from pylons_app.lib import filters
-%>
 <%inherit file="base/base.html"/>
 <%def name="title()">
     ${c.repos_prefix} Mercurial Repositories
--- a/pylons_app/templates/shortlog/shortlog_data.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/shortlog/shortlog_data.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,6 @@
 ## -*- coding: utf-8 -*-
-<%!
-from pylons_app.lib import filters
-%>
+% if c.repo_changesets:
+
 <table class="table_disp">
 	<tr class="header">
 		<td>${_('date')}</td>
@@ -15,8 +14,8 @@
 	</tr>
 %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.age(cs._ctx.date())}</td>
+		<td title="${cs.author}">${h.person(cs.author)}</td>
 		<td>r${cs.revision}:${cs.raw_id}</td>
 		<td>
 			${h.link_to(h.truncate(cs.message,60),
@@ -59,4 +58,7 @@
 				YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');});		
 		YAHOO.util.Dom.setStyle(data_div,'opacity','1');}},null); return false;""")}
 		</h2>
-	</div>	
\ No newline at end of file
+	</div>	
+%else:
+	${_('There are no commits yet')}
+%endif
\ No newline at end of file
--- a/pylons_app/templates/summary/summary.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/summary/summary.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,4 @@
 <%inherit file="/base/base.html"/>
-<%!
-from pylons_app.lib import filters
-%>
 <%def name="title()">
     ${_('Repository managment')}
 </%def>
@@ -41,7 +38,7 @@
         <dt>${_('contact')}</dt>
         <dd>${c.repo_info.contact}</dd>
         <dt>${_('last change')}</dt>
-        <dd>${c.repo_info.last_change|n,filters.age} - ${c.repo_info.last_change|n,filters.rfc822date}</dd>
+        <dd>${h.age(c.repo_info.last_change)} - ${h.rfc822date(c.repo_info.last_change)}</dd>
         <dt>${_('clone url')}</dt>
         <dd><input type="text" id="clone_url"  readonly="readonly" value="hg clone ${c.clone_repo_url}" size="70"/></dd>
         <dt>${_('download')}</dt>
@@ -63,100 +60,12 @@
     </dl>
 
     <h2>${h.link_to(_('Last ten changes'),h.url('changelog_home',repo_name=c.repo_name))}</h2>
-<table class="table_disp">
-	<tr class="header">
-		<td>${_('date')}</td>
-		<td>${_('author')}</td>
-		<td>${_('revision')}</td>
-		<td>${_('commit message')}</td>
-		<td>${_('branch')}</td>
-		<td>${_('tags')}</td>
-		<td>${_('links')}</td>
-		
-	</tr>
-	%for cnt,cs in enumerate(c.repo_changesets):
-		<tr class="parity${cnt%2}">
-			<td>${cs._ctx.date()|n,filters.age}</td>
-			<td>${cs.author|n,filters.person}</td>
-			<td>r${cs.revision}:${cs.raw_id}</td>
-			<td>
-				${h.link_to(h.truncate(cs.message,60),
-				h.url('changeset_home',repo_name=c.repo_name,revision=cs._short),
-				title=cs.message)}
-			</td>
-			<td>
-				<span class="logtags">
-					<span class="branchtag">${cs.branch}</span>
-				</span>
-			</td>
-			<td>
-				<span class="logtags">
-					%for tag in cs.tags:
-						<span class="tagtag">${tag}</span>
-					%endfor
-				</span>
-			</td>
-			<td class="nowrap">
-			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=cs._short))}
-			|
-			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=cs._short))}
-			</td>
-		</tr>
-	%endfor
-    </table>
+	<%include file='../shortlog/shortlog_data.html'/>
 
     <h2>${h.link_to(_('Last ten tags'),h.url('tags_home',repo_name=c.repo_name))}</h2>
-    <table class="table_disp">
-    	<tr class="header">
-			<td>${_('date')}</td>
-			<td>${_('revision')}</td>
-			<td>${_('name')}</td>
-			<td>${_('links')}</td>
-    	</tr>
-		%for cnt,tag in enumerate(c.repo_tags.items()):
-		<tr class="parity${cnt%2}">
-			<td>${tag[1]._ctx.date()|n,filters.age}</td>
-			<td>r${tag[1].revision}:${tag[1].raw_id}</td>
-			<td>
-				<span class="logtags">
-					<span class="tagtag">${h.link_to(tag[0],
-					h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}</span>
-				</span>
-			</td>
-			<td class="nowrap">
-			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
-			|
-			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
-			</td>
-		</tr>	
-		%endfor
-    </table>
-
+	<%include file='../tags/tags_data.html'/>
+    
     <h2>${h.link_to(_('Last ten branches'),h.url('branches_home',repo_name=c.repo_name))}</h2>
-    <table class="table_disp">
-    	<tr class="header">
-			<td>${_('date')}</td>
-			<td>${_('revision')}</td>
-			<td>${_('name')}</td>
-			<td>${_('links')}</td>
-    	</tr>
-		%for cnt,branch in enumerate(c.repo_branches.items()):
-		<tr class="parity${cnt%2}">
-			<td>${branch[1]._ctx.date()|n,filters.age}</td>
-			<td>r${branch[1].revision}:${branch[1].raw_id}</td>
-			<td>
-				<span class="logtags">
-					<span class="branchtag">${h.link_to(branch[0],
-					h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}</span>
-				</span>			
-			</td>
-			<td class="nowrap">
-			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
-			|
-			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))}
-			</td>
-		</tr>	
-		%endfor
-    </table>
+	<%include file='../branches/branches_data.html'/>
 
 </%def>    
\ No newline at end of file
--- a/pylons_app/templates/tags/tags.html	Sun Jun 13 23:14:04 2010 +0200
+++ b/pylons_app/templates/tags/tags.html	Sun Jun 13 23:56:16 2010 +0200
@@ -1,7 +1,4 @@
 <%inherit file="/base/base.html"/>
-<%!
-from pylons_app.lib import filters
-%>
 <%def name="title()">
     ${_('Tags')}
 </%def>
@@ -18,30 +15,6 @@
 <%def name="main()">
 
     <h2 class="no-link no-border">${_('Tags')}</h2>
-    <table class="table_disp">
-    	<tr class="header">
-			<td>${_('date')}</td>
-			<td>${_('revision')}</td>
-			<td>${_('name')}</td>
-			<td>${_('links')}</td>
-    	</tr>
-		%for cnt,tag in enumerate(c.repo_tags.items()):
-		<tr class="parity${cnt%2}">
-			<td>${tag[1]._ctx.date()|n,filters.age}</td>
-			<td>r${tag[1].revision}:${tag[1].raw_id}</td>
-			<td>
-				<span class="logtags">
-					<span class="tagtag">${h.link_to(tag[0],
-					h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}</span>
-				</span>
-			</td>
-			<td class="nowrap">
-			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
-			|
-			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
-			</td>
-		</tr>	
-		%endfor
-    </table>
+	<%include file='tags_data.html'/>
 
 </%def>    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pylons_app/templates/tags/tags_data.html	Sun Jun 13 23:56:16 2010 +0200
@@ -0,0 +1,29 @@
+%if c.repo_tags:    
+    <table class="table_disp">
+    	<tr class="header">
+			<td>${_('date')}</td>
+			<td>${_('revision')}</td>
+			<td>${_('name')}</td>
+			<td>${_('links')}</td>
+    	</tr>
+		%for cnt,tag in enumerate(c.repo_tags.items()):
+		<tr class="parity${cnt%2}">
+			<td>${h.age(tag[1]._ctx.date())}</td>
+			<td>r${tag[1].revision}:${tag[1].raw_id}</td>
+			<td>
+				<span class="logtags">
+					<span class="tagtag">${h.link_to(tag[0],
+					h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}</span>
+				</span>
+			</td>
+			<td class="nowrap">
+			${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
+			|
+			${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))}
+			</td>
+		</tr>	
+		%endfor
+    </table>
+%else:
+	${_('There are no tags yet')}
+%endif    
\ No newline at end of file