diff mbox

Make the submitter name link to a query for that submitter

Message ID 1427093782-20096-1-git-send-email-mpe@ellerman.id.au
State Accepted
Headers show

Commit Message

Michael Ellerman March 23, 2015, 6:56 a.m. UTC
Currently the submitter name is rendered as a mailto: link. This is
possibly useful in some circumstances, but in my experience is not
usually what I want. Although it opens a mail to the submitter, it
doesn't include any of the patch context, so is not very helpful.

Instead the submitter link can be a link to a query for patches by that
submitter. In my experience that is more useful, ie. when looking at a
single patch for a submitter you can then quickly get the list of all
patches by them.

So do that conversion.

In order to do it we need to know the current project, so that becomes a
parameter to personify. I believe the url reversal is correct, though
it's not pretty, and pulling SubmitterFilter.param out feels a little
wrong, but is the best solution I could come up with.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 apps/patchwork/templatetags/person.py | 9 ++++++---
 templates/patchwork/patch-list.html   | 2 +-
 templates/patchwork/patch.html        | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)

Comments

Bjorn Helgaas March 23, 2015, 2:14 p.m. UTC | #1
On Mon, Mar 23, 2015 at 1:56 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Currently the submitter name is rendered as a mailto: link. This is
> possibly useful in some circumstances, but in my experience is not
> usually what I want. Although it opens a mail to the submitter, it
> doesn't include any of the patch context, so is not very helpful.
>
> Instead the submitter link can be a link to a query for patches by that
> submitter. In my experience that is more useful, ie. when looking at a
> single patch for a submitter you can then quickly get the list of all
> patches by them.

I agree, this would definitely be more useful to me.

> So do that conversion.
>
> In order to do it we need to know the current project, so that becomes a
> parameter to personify. I believe the url reversal is correct, though
> it's not pretty, and pulling SubmitterFilter.param out feels a little
> wrong, but is the best solution I could come up with.
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  apps/patchwork/templatetags/person.py | 9 ++++++---
>  templates/patchwork/patch-list.html   | 2 +-
>  templates/patchwork/patch.html        | 4 ++--
>  3 files changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/apps/patchwork/templatetags/person.py b/apps/patchwork/templatetags/person.py
> index 07c356a9633d..c337c7442de7 100644
> --- a/apps/patchwork/templatetags/person.py
> +++ b/apps/patchwork/templatetags/person.py
> @@ -20,20 +20,23 @@
>  from django import template
>  from django.utils.html import escape
>  from django.utils.safestring import mark_safe
> +from django.core.urlresolvers import reverse
> +from patchwork.filters import SubmitterFilter
>  import re
>
>  register = template.Library()
>
>  @register.filter
> -def personify(person):
> +def personify(person, project):
>
>      if person.name:
>          linktext = escape(person.name)
>      else:
>          linktext = escape(person.email)
>
> -    str = '<a href="mailto:%s">%s</a>' % \
> -                (escape(person.email), linktext)
> +    url = reverse('patchwork.views.patch.list', kwargs = {'project_id' : project.linkname})
> +    str = '<a href="%s?%s=%s">%s</a>' % \
> +                (url, SubmitterFilter.param, escape(person.id), linktext)
>
>      return mark_safe(str)
>
> diff --git a/templates/patchwork/patch-list.html b/templates/patchwork/patch-list.html
> index 59adbe301721..f8049f7bcabb 100644
> --- a/templates/patchwork/patch-list.html
> +++ b/templates/patchwork/patch-list.html
> @@ -146,7 +146,7 @@
>     <td><a href="{% url 'patchwork.views.patch.patch' patch_id=patch.id %}"
>       >{{ patch.name|default:"[no subject]" }}</a></td>
>     <td>{{ patch.date|date:"Y-m-d" }}</td>
> -   <td>{{ patch.submitter|personify }}</td>
> +   <td>{{ patch.submitter|personify:project }}</td>
>     <td>{{ patch.delegate.username }}</td>
>     <td>{{ patch.state }}</td>
>    </tr>
> diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html
> index c04e32b4dda2..be831e9c31f5 100644
> --- a/templates/patchwork/patch.html
> +++ b/templates/patchwork/patch.html
> @@ -30,7 +30,7 @@ function toggle_headers(link_id, headers_id)
>  <table class="patchmeta">
>   <tr>
>    <th>Submitter</th>
> -  <td>{{ patch.submitter|personify }}</td>
> +  <td>{{ patch.submitter|personify:project }}</td>
>   </tr>
>   <tr>
>    <th>Date</th>
> @@ -179,7 +179,7 @@ function toggle_headers(link_id, headers_id)
>  <h2>Comments</h2>
>  {% for comment in patch.comments %}
>  <div class="comment">
> -<div class="meta">{{ comment.submitter|personify }} - {{comment.date}}</div>
> +<div class="meta">{{ comment.submitter|personify:project }} - {{comment.date}}</div>
>  <pre class="content">
>  {{ comment|commentsyntax }}
>  </pre>
> --
> 2.1.0
>
> _______________________________________________
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
diff mbox

Patch

diff --git a/apps/patchwork/templatetags/person.py b/apps/patchwork/templatetags/person.py
index 07c356a9633d..c337c7442de7 100644
--- a/apps/patchwork/templatetags/person.py
+++ b/apps/patchwork/templatetags/person.py
@@ -20,20 +20,23 @@ 
 from django import template
 from django.utils.html import escape
 from django.utils.safestring import mark_safe
+from django.core.urlresolvers import reverse
+from patchwork.filters import SubmitterFilter
 import re
 
 register = template.Library()
 
 @register.filter
-def personify(person):
+def personify(person, project):
 
     if person.name:
         linktext = escape(person.name)
     else:
         linktext = escape(person.email)
 
-    str = '<a href="mailto:%s">%s</a>' % \
-                (escape(person.email), linktext)
+    url = reverse('patchwork.views.patch.list', kwargs = {'project_id' : project.linkname})
+    str = '<a href="%s?%s=%s">%s</a>' % \
+                (url, SubmitterFilter.param, escape(person.id), linktext)
 
     return mark_safe(str)
 
diff --git a/templates/patchwork/patch-list.html b/templates/patchwork/patch-list.html
index 59adbe301721..f8049f7bcabb 100644
--- a/templates/patchwork/patch-list.html
+++ b/templates/patchwork/patch-list.html
@@ -146,7 +146,7 @@ 
    <td><a href="{% url 'patchwork.views.patch.patch' patch_id=patch.id %}"
      >{{ patch.name|default:"[no subject]" }}</a></td>
    <td>{{ patch.date|date:"Y-m-d" }}</td>
-   <td>{{ patch.submitter|personify }}</td>
+   <td>{{ patch.submitter|personify:project }}</td>
    <td>{{ patch.delegate.username }}</td>
    <td>{{ patch.state }}</td>
   </tr>
diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html
index c04e32b4dda2..be831e9c31f5 100644
--- a/templates/patchwork/patch.html
+++ b/templates/patchwork/patch.html
@@ -30,7 +30,7 @@  function toggle_headers(link_id, headers_id)
 <table class="patchmeta">
  <tr>
   <th>Submitter</th>
-  <td>{{ patch.submitter|personify }}</td>
+  <td>{{ patch.submitter|personify:project }}</td>
  </tr>
  <tr>
   <th>Date</th>
@@ -179,7 +179,7 @@  function toggle_headers(link_id, headers_id)
 <h2>Comments</h2>
 {% for comment in patch.comments %}
 <div class="comment">
-<div class="meta">{{ comment.submitter|personify }} - {{comment.date}}</div>
+<div class="meta">{{ comment.submitter|personify:project }} - {{comment.date}}</div>
 <pre class="content">
 {{ comment|commentsyntax }}
 </pre>