[PATCH v6 6/8] templates: Generate and use a "handle"

Stephen Finucane stephen at that.guru
Sun Oct 16 23:50:52 AEDT 2016


In the absence of a name, the email is currently used. Some emails are
long and rather unreadable. The likelihood of someone's localpart (i.e.
the bit before the '@') conflicting with that of someone else on the
same patchwork instance and project is very low, so form a "handle"
from just this.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Reviewed-by: Andy Doan <andy.doan at linaro.org>
---
 patchwork/models.py              |  7 +++++++
 patchwork/templatetags/person.py | 10 +++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index 49572ec..22c9bf1 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -50,6 +50,13 @@ class Person(models.Model):
         self.name = user.profile.name
         self.user = user
 
+    @property
+    def handle(self):
+        if self.user:
+            return self.user.name
+        else:
+            return self.email.split('@')[0]
+
     def __str__(self):
         if self.name:
             return '%s <%s>' % (self.name, self.email)
diff --git a/patchwork/templatetags/person.py b/patchwork/templatetags/person.py
index adbabb0..8d12c03 100644
--- a/patchwork/templatetags/person.py
+++ b/patchwork/templatetags/person.py
@@ -33,14 +33,10 @@ register = template.Library()
 @register.filter
 def personify(person, project):
 
-    if person.name:
-        linktext = escape(person.name)
-    else:
-        linktext = escape(person.email)
-
     url = reverse('patch-list',
                   kwargs={'project_id': project.linkname})
-    out = '<a href="%s?%s=%s">%s</a>' % (
-        url, SubmitterFilter.param, escape(person.id), linktext)
+    out = '<a href="%s?%s=%s" title="%s">%s</a>' % (
+        url, SubmitterFilter.param, escape(person.id), str(person),
+        person.name or person.handle)
 
     return mark_safe(out)
-- 
2.7.4



More information about the Patchwork mailing list