changeset 56:bf1b64046c79

Added last change translation to 'time ago', added generation of enabled zip archives
author Marcin Kuzminski <marcin@python-blog.com>
date Fri, 09 Apr 2010 00:30:42 +0200
parents e00dccb6f211
children e96bc5a01490
files development.ini production.ini pylons_app/controllers/hg.py pylons_app/lib/app_globals.py pylons_app/templates/index.html
diffstat 5 files changed, 32 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/development.ini	Thu Apr 08 22:59:49 2010 +0200
+++ b/development.ini	Fri Apr 09 00:30:42 2010 +0200
@@ -29,7 +29,7 @@
 static_files = true
 lang=en
 cache_dir = %(here)s/data
-repos_name = etelko
+repos_name = Etelko
 
 ####################################
 ###         BEAKER CACHE        ####
--- a/production.ini	Thu Apr 08 22:59:49 2010 +0200
+++ b/production.ini	Fri Apr 09 00:30:42 2010 +0200
@@ -29,7 +29,7 @@
 static_files = true
 lang=en
 cache_dir = %(here)s/data
-repos_name = etelko
+repos_name = Etelko
 
 ####################################
 ###         BEAKER CACHE        ####
--- a/pylons_app/controllers/hg.py	Thu Apr 08 22:59:49 2010 +0200
+++ b/pylons_app/controllers/hg.py	Fri Apr 09 00:30:42 2010 +0200
@@ -14,7 +14,7 @@
     print 'You have to import vcs module'
 from mercurial.util import matchdate, Abort, makedate
 from mercurial.hgweb.common import get_contact
-
+from mercurial.templatefilters import age
 log = logging.getLogger(__name__)
 
 class HgController(BaseController):
@@ -32,18 +32,28 @@
                 return os.stat(cl_path).st_mtime
             else:
                 return os.stat(spath).st_mtime   
-                
+        
+        def archivelist(ui, nodeid, url):
+            allowed = g.baseui.configlist("web", "allow_archive", untrusted=True)
+            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
+                if i[0] in allowed or ui.configbool("web", "allow" + i[0],
+                                                    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])
-            tmp = {}
-            tmp['name'] = name
-            tmp['desc'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
-            tmp['last_change'] = last_change,
             tip = r.changectx('tip')
-            tmp['tip'] = tip.__str__(),
-            tmp['rev'] = tip.rev()
-            tmp['contact'] = get_contact(r.ui.config)
-            c.repos_list.append(tmp)
+            tmp_d = {}
+            tmp_d['name'] = name
+            tmp_d['desc'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
+            tmp_d['last_change'] = age(last_change)
+            tmp_d['tip'] = str(tip)
+            tmp_d['rev'] = tip.rev()
+            tmp_d['contact'] = get_contact(r.ui.config)
+            tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa')
+            
+            c.repos_list.append(tmp_d)
         return render('/index.html')
 
     def view(self, *args, **kwargs):
--- a/pylons_app/lib/app_globals.py	Thu Apr 08 22:59:49 2010 +0200
+++ b/pylons_app/lib/app_globals.py	Fri Apr 09 00:30:42 2010 +0200
@@ -43,7 +43,7 @@
             baseui.setconfig('web', k, v)
         #magic trick to make our custom template dir working
         templater.path.append(cfg.get('web', 'templates', None))
-
+        self.baseui = baseui
         #baseui.setconfig('web', 'description', '')
         #baseui.setconfig('web', 'name', '')
         #baseui.setconfig('web', 'contact', '')
--- a/pylons_app/templates/index.html	Thu Apr 08 22:59:49 2010 +0200
+++ b/pylons_app/templates/index.html	Fri Apr 09 00:30:42 2010 +0200
@@ -13,7 +13,11 @@
 </%def>
 <%def name="main()">
 	<%def name="get_sort(name)">
-		<a href="?sort=${name.lower().replace(' ','-')}">${name}</a>
+		<%name_slug = name.lower().replace(' ','-') %>
+		%if not name_slug.startswith('-') and c.current_sort:
+			<%name_slug = '-'+name_slug%> 
+		%endif
+		<a href="?sort=${name_slug}">${name}</a>
 	</%def>
 	<table>
 	  <tr>
@@ -28,12 +32,12 @@
 		    <td><a href="/${repo['name']}">${repo['name']}</a></td>
 		    <td>${repo['desc']}</td>
 	        <td>${repo['last_change']}</td>
-	        <td>r${repo['rev']}:${repo['tip']}</td>
+	        <td>r${repo['rev']}:<a href="/${repo['name']}/rev/${repo['tip']}/">${repo['tip']}</a></td>
 	        <td>${repo['contact']}</td>
 	        <td class="indexlinks">
-	        	<a href="/${repo['name']}/archive/tip.zip">zip</a> 
-	        	<a href="/${repo['name']}/archive/tip.tar.gz">gz</a> 
-	        	<a href="/${repo['name']}/archive/tip.tar.bz2">bz2</a> 
+	        	%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">