changeset 4760:716194520cc0

user: use h.person(obj.user) instead of h.person(obj.user.username) - don't fail if user is None h.person prefer a user object anyway - just pass it obj.user and make sure h.person doesn't crash on getting a None user.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 06 Jan 2015 00:54:36 +0100
parents 1a2e7a8d144c
children 9b3063e16d9a
files kallithea/controllers/admin/repo_groups.py kallithea/lib/helpers.py kallithea/lib/vcs/utils/__init__.py kallithea/model/repo.py kallithea/templates/admin/repo_groups/repo_group_edit_advanced.html kallithea/templates/admin/user_groups/user_group_edit_advanced.html
diffstat 6 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/controllers/admin/repo_groups.py	Tue Jan 06 00:54:36 2015 +0100
@@ -146,7 +146,7 @@
                 "group_name": repo_group_name(repo_gr.group_name, children_groups),
                 "desc": repo_gr.group_description,
                 "repos": repo_count,
-                "owner": h.person(repo_gr.user.username),
+                "owner": h.person(repo_gr.user),
                 "action": repo_group_actions(repo_gr.group_id, repo_gr.group_name,
                                              repo_count)
             })
--- a/kallithea/lib/helpers.py	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/lib/helpers.py	Tue Jan 06 00:54:36 2015 +0100
@@ -519,6 +519,8 @@
 
 
 def person(author, show_attr="username"):
+    """Find the user identified by 'author', return one of the users attributes,
+    default to the username attribute, None if there is no user"""
     # attr to return from fetched user
     person_getter = lambda usr: getattr(usr, show_attr)
 
--- a/kallithea/lib/vcs/utils/__init__.py	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/lib/vcs/utils/__init__.py	Tue Jan 06 00:54:36 2015 +0100
@@ -158,6 +158,8 @@
 
     Regex taken from http://www.regular-expressions.info/email.html
     """
+    if not author:
+        return ''
     import re
     r = author.find('>')
     l = author.find('<')
@@ -180,9 +182,9 @@
     It'll try to find an email in the author string and just cut it off
     to get the username
     """
-
+    if not author:
+        return ''
     if not '@' in author:
         return author
-    else:
-        return author.replace(author_email(author), '').replace('<', '')\
-            .replace('>', '').strip()
+    return author.replace(author_email(author), '').replace('<', '')\
+        .replace('>', '').strip()
--- a/kallithea/model/repo.py	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/model/repo.py	Tue Jan 06 00:54:36 2015 +0100
@@ -241,7 +241,7 @@
                 "last_changeset": last_rev(repo.repo_name, cs_cache),
                 "last_rev_raw": cs_cache.get('revision'),
                 "desc": desc(repo.description),
-                "owner": h.person(repo.user.username),
+                "owner": h.person(repo.user),
                 "state": state(repo.repo_state),
                 "rss": rss_lnk(repo.repo_name),
                 "atom": atom_lnk(repo.repo_name),
@@ -251,7 +251,7 @@
                 row.update({
                     "action": repo_actions(repo.repo_name),
                     "owner": owner_actions(repo.user.user_id,
-                                           h.person(repo.user.username))
+                                           h.person(repo.user))
                 })
             repos_data.append(row)
 
--- a/kallithea/templates/admin/repo_groups/repo_group_edit_advanced.html	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/templates/admin/repo_groups/repo_group_edit_advanced.html	Tue Jan 06 00:54:36 2015 +0100
@@ -7,7 +7,7 @@
     (_('Total repositories'), c.repo_group.repositories_recursive_count, ''),
     (_('Children groups'), c.repo_group.children.count(), ''),
     (_('Created on'), h.fmt_date(c.repo_group.created_on), ''),
-    (_('Owner'), h.person(c.repo_group.user.username), '')
+    (_('Owner'), h.person(c.repo_group.user), '')
  ]
 %>
 %for dt, dd, tt in elems:
--- a/kallithea/templates/admin/user_groups/user_group_edit_advanced.html	Tue Jan 06 00:54:36 2015 +0100
+++ b/kallithea/templates/admin/user_groups/user_group_edit_advanced.html	Tue Jan 06 00:54:36 2015 +0100
@@ -5,7 +5,7 @@
  elems = [
     (_('Members'), len(c.group_members_obj), ''),
     (_('Created on'), h.fmt_date(c.user_group.created_on), ''),
-    (_('Owner'), h.person(c.user_group.user.username), '')
+    (_('Owner'), h.person(c.user_group.user), '')
     ]
 %>
 %for dt, dd, tt in elems: