From patchwork Fri Sep 11 15:55:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 516889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 028AB140271 for ; Sat, 12 Sep 2015 02:02:56 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id CFF9E1A2BD8 for ; Sat, 12 Sep 2015 02:02:55 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lists.ozlabs.org (Postfix) with ESMTP id 8D1861A2BB6 for ; Sat, 12 Sep 2015 01:56:18 +1000 (AEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 11 Sep 2015 08:56:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="559867371" Received: from jeffzhua-mobl.amr.corp.intel.com (HELO strange.amr.corp.intel.com) ([10.254.88.85]) by FMSMGA003.fm.intel.com with ESMTP; 11 Sep 2015 08:56:17 -0700 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 46/51] series: Always return a displayable name in submitter__name Date: Fri, 11 Sep 2015 16:55:19 +0100 Message-Id: <1441986924-26689-47-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1441986924-26689-1-git-send-email-damien.lespiau@intel.com> References: <1441986924-26689-1-git-send-email-damien.lespiau@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- 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)