From bea195bfd9364a437ccab97d3b112ce639b6069f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 20 2016 14:22:26 +0000 Subject: Create a dedicated jinja filter for showing the author in the commit list This creates two links on the author's info: * one link on the avatar pointing to the user's generic info page * one link on the user's name filtering the list of commits for this user --- diff --git a/pagure/templates/commits.html b/pagure/templates/commits.html index 8d6dd34..d0013da 100644 --- a/pagure/templates/commits.html +++ b/pagure/templates/commits.html @@ -148,7 +148,14 @@ - {{commit.author|author2user(cssclass="notblue")|safe}} + {{commit.author|author2user_commits( + link=url_for('view_commits', + repo=repo.name, + branchname=branchname, + username=username, + namespace=repo.namespace, + author=commit.author.email), + cssclass="notblue")|safe}}
{{ commit.hex|short }}
diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index 944a7c1..b05b17d 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -359,6 +359,26 @@ def author_to_avatar(author, size=32): return avatar(output.encode('utf-8'), size) +@APP.template_filter('author2user_commits') +def author_to_user_commits(author, link, size=16, cssclass=None): + """ Template filter transforming a pygit2 Author object into a text + either with just the username or linking to the user in pagure. + """ + output = author.name + if not author.email: + return output + user = pagure.lib.search_user(SESSION, email=author.email) + if user: + output = "%s %s" % ( + flask.url_for('view_user', username=user.username), + avatar(user.default_email, size), + link, + ('class="%s"' % cssclass) if cssclass else '', + author.name, + ) + + return output + @APP.template_filter('InsertDiv') def insert_div(content): """ Template filter inserting an opening
and closing