Changeset - 716194520cc0
[Not reviewed]
default
0 6 0
Mads Kiilerich - 11 years ago 2015-01-06 00:54:36
madski@unity3d.com
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.
6 files changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/repo_groups.py
Show inline comments
 
@@ -143,13 +143,13 @@ class RepoGroupsController(BaseControlle
 
            repo_count = repo_gr.repositories.count()
 
            repo_groups_data.append({
 
                "raw_name": repo_gr.group_name,
 
                "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)
 
            })
 

	
 
        c.data = json.dumps({
 
            "totalRecords": total_records,
kallithea/lib/helpers.py
Show inline comments
 
@@ -516,12 +516,14 @@ def email_or_none(author):
 

	
 
    # No valid email, not a valid user in the system, none!
 
    return None
 

	
 

	
 
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)
 

	
 
    # if author is already an instance use it for extraction
 
    if isinstance(author, User):
 
        return person_getter(author)
kallithea/lib/vcs/utils/__init__.py
Show inline comments
 
@@ -155,12 +155,14 @@ def author_email(author):
 
    returns email address of given author.
 
    If any of <,> sign are found, it fallbacks to regex findall()
 
    and returns first found result or empty string
 

	
 
    Regex taken from http://www.regular-expressions.info/email.html
 
    """
 
    if not author:
 
        return ''
 
    import re
 
    r = author.find('>')
 
    l = author.find('<')
 

	
 
    if l == -1 or r == -1:
 
        # fallback to regex match of email out of a string
 
@@ -177,12 +179,12 @@ def author_email(author):
 
def author_name(author):
 
    """
 
    get name of author, or else username.
 
    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()
kallithea/model/repo.py
Show inline comments
 
@@ -238,23 +238,23 @@ class RepoModel(BaseModel):
 
                "name": repo_lnk(repo.repo_name, repo.repo_type,
 
                                 repo.repo_state, repo.private, repo.fork),
 
                "last_change": last_change(repo.last_db_change),
 
                "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),
 

	
 
            }
 
            if admin:
 
                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)
 

	
 
        return {
 
            "totalRecords": len(repos_list),
 
            "startIndex": 0,
kallithea/templates/admin/repo_groups/repo_group_edit_advanced.html
Show inline comments
 
@@ -4,13 +4,13 @@
 
<%
 
 elems = [
 
    (_('Top level repositories'), c.repo_group.repositories.count(), ''),
 
    (_('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:
 
  <dt style="width:150px; text-align: left">${dt}:</dt>
 
  <dd style="margin-left: 160px" title="${tt}">${dd}</dd>
 
%endfor
kallithea/templates/admin/user_groups/user_group_edit_advanced.html
Show inline comments
 
@@ -2,13 +2,13 @@
 

	
 
<dl class="dl-horizontal">
 
<%
 
 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:
 
  <dt style="width:150px; text-align: left">${dt}:</dt>
 
  <dd style="margin-left: 160px" title="${tt}">${dd}</dd>
 
%endfor
0 comments (0 inline, 0 general)