diff mbox

[46/51] series: Always return a displayable name in submitter__name

Message ID 1441986924-26689-47-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Sept. 11, 2015, 3:55 p.m. UTC
submitter.name can be null when mails are sent with a From: field
populated with just an email address. Present something displayable in
the API.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 patchwork/models.py      | 5 ++++-
 patchwork/serializers.py | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index df9d85f..02763c5 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -38,12 +38,15 @@  class Person(models.Model):
     user = models.ForeignKey(User, null = True, blank = True,
             on_delete = models.SET_NULL)
 
-    def __unicode__(self):
+    def display_name(self):
         if self.name:
             return self.name
         else:
             return self.email
 
+    def __unicode__(self):
+        return self.display_name()
+
     def link_to_user(self, user):
         self.name = user.profile.name()
         self.user = user
diff --git a/patchwork/serializers.py b/patchwork/serializers.py
index edffb6b..77d9e4d 100644
--- a/patchwork/serializers.py
+++ b/patchwork/serializers.py
@@ -33,7 +33,7 @@  class ProjectSerializer(serializers.HyperlinkedModelSerializer):
                   'webscm_url')
 
 class SeriesSerializer(serializers.ModelSerializer):
-    submitter__name = serializers.CharField(source='submitter.name',
+    submitter__name = serializers.CharField(source='submitter.display_name',
                                             read_only=True)
     reviewer__name = serializers.CharField(source='reviewer.name',
                                            read_only=True)