[PATCH 06/10] templates: Generate and use a "handle"

Stephen Finucane stephen.finucane at intel.com
Mon Jun 13 20:41:38 AEST 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.finucane at intel.com>
---
 patchwork/bin/parsemail.py       |    2 +-
 patchwork/models.py              |    7 +++++++
 patchwork/templatetags/person.py |   12 ++++--------
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 8baacf6..ddcd9e7 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -284,7 +284,7 @@ def parse_version(subject, subject_prefixes):
     if m:
         return int(m.group(1))
 
-    m = re.search(r'\(([vV]\d+)\)', subject)
+    m = re.search(r'\([vV](\d+)\)', subject)
     if m:
         return int(m.group(1))
 
diff --git a/patchwork/models.py b/patchwork/models.py
index 67ea012..d2d4079 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -54,6 +54,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 7af021f..98c0f2b 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})
-    str = '<a href="%s?%s=%s">%s</a>' % (
-        url, SubmitterFilter.param, escape(person.id), linktext)
+    elem = '<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(str)
+    return mark_safe(elem)
-- 
1.7.4.1



More information about the Patchwork mailing list