[PATCH 46/51] series: Always return a displayable name in submitter__name
Damien Lespiau
damien.lespiau at intel.com
Sat Sep 12 01:55:19 AEST 2015
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 at intel.com>
---
patchwork/models.py | 5 ++++-
patchwork/serializers.py | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
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)
--
2.1.0
More information about the Patchwork
mailing list