changeset 450:c3236d7febad

fixed, empty cs bug. Implemented as webhlepers function
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 03 Sep 2010 09:55:48 +0200
parents ac21f018f6be
children d726f62f886e
files pylons_app/lib/helpers.py pylons_app/model/hg_model.py pylons_app/templates/admin/users/user_edit_my_account.html
diffstat 3 files changed, 23 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/lib/helpers.py	Fri Sep 03 09:23:50 2010 +0200
+++ b/pylons_app/lib/helpers.py	Fri Sep 03 09:55:48 2010 +0200
@@ -219,7 +219,7 @@
     pygmentize function using pygments
     @param filenode:
     """
-    return literal(code_highlight(filenode.content, 
+    return literal(code_highlight(filenode.content,
                                   filenode.lexer, HtmlFormatter(**kwargs)))
 
 def pygmentize_annotation(filenode, **kwargs):
@@ -239,11 +239,11 @@
         h = 0.22717784590367374
         #generate 10k nice web friendly colors in the same order
         for c in xrange(n):
-            h +=golden_ratio
+            h += golden_ratio
             h %= 1
             HSV_tuple = [h, 0.95, 0.95]
             RGB_tuple = colorsys.hsv_to_rgb(*HSV_tuple)
-            yield map(lambda x:str(int(x*256)),RGB_tuple)           
+            yield map(lambda x:str(int(x * 256)), RGB_tuple)           
 
     cgenerator = gen_color()
         
@@ -255,7 +255,7 @@
         return "color: rgb(%s)! important;" % (', '.join(col))
         
     def url_func(changeset):
-        tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>"+\
+        tooltip_html = "<div style='font-size:0.8em'><b>Author:</b>" + \
         " %s<br/><b>Date:</b> %s</b><br/><b>Message:</b> %s<br/></div>" 
         
         tooltip_html = tooltip_html % (changeset.author,
@@ -286,6 +286,21 @@
     slug = recursive_replace(slug, '-')
     return slug
 
+def get_changeset_safe(repo, rev):
+    from vcs.backends.base import BaseRepository
+    from vcs.exceptions import RepositoryError
+    if not isinstance(repo, BaseRepository):
+        raise Exception('You must pass an Repository '
+                        'object as first argument got %s', type(repo))
+        
+    try:
+        cs = repo.get_changeset(rev)
+    except RepositoryError:
+        from pylons_app.lib.utils import EmptyChangeset
+        cs = EmptyChangeset()
+    return cs
+
+
 flash = _Flash()
 
 
@@ -351,4 +366,4 @@
             #incase we have a decode error just represent as byte string
             u_str = unicode(str(str).encode('string_escape'))
         
-    return u_str
\ No newline at end of file
+    return u_str
--- a/pylons_app/model/hg_model.py	Fri Sep 03 09:23:50 2010 +0200
+++ b/pylons_app/model/hg_model.py	Fri Sep 03 09:55:48 2010 +0200
@@ -29,7 +29,7 @@
 from pylons_app.lib.auth import HasRepoPermissionAny
 from pylons_app.model import meta
 from pylons_app.model.db import Repository, User
-from sqlalchemy.orm import joinedload
+from pylons_app.lib import helpers as h
 from vcs.exceptions import RepositoryError, VCSError
 import logging
 import os
@@ -151,11 +151,7 @@
                 continue
             
             last_change = repo.last_change
-            try:
-                tip = repo.get_changeset('tip')
-            except RepositoryError:
-                from pylons_app.lib.utils import EmptyChangeset
-                tip = EmptyChangeset()
+            tip = h.get_changeset_safe(repo, 'tip')
                 
             tmp_d = {}
             tmp_d['name'] = repo.name
--- a/pylons_app/templates/admin/users/user_edit_my_account.html	Fri Sep 03 09:23:50 2010 +0200
+++ b/pylons_app/templates/admin/users/user_edit_my_account.html	Fri Sep 03 09:55:48 2010 +0200
@@ -98,7 +98,7 @@
 	             %endif
 	                                             
 	            ${h.link_to(repo.name, h.url('summary_home',repo_name=repo.name))}</td> 
-	            <td>${_('revision')}: ${repo.revisions[-1]}</td>
+	            <td>${_('revision')}: ${h.get_changeset_safe(repo,'tip').revision}</td>
 	            <td>${_('last changed')}: ${h.age(repo.last_change)}</td>
 	            <td><img class="icon" alt="${_('private')}" src="/images/icons/application_form_edit.png"/> ${h.link_to(_('edit'),h.url('edit_repo',repo_name=repo.name))}</td>
 	        </tr>