From patchwork Fri Sep 11 15:55:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Lespiau X-Patchwork-Id: 516890 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 24AE514012C for ; Sat, 12 Sep 2015 02:03:06 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 0442D1A2BE1 for ; Sat, 12 Sep 2015 02:03:06 +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 1D6391A2BB0 for ; Sat, 12 Sep 2015 01:56:19 +1000 (AEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 11 Sep 2015 08:56:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="559867376" 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:18 -0700 From: Damien Lespiau To: patchwork@lists.ozlabs.org Subject: [PATCH 47/51] models: Split the notication logic into its own function Date: Fri, 11 Sep 2015 16:55:20 +0100 Message-Id: <1441986924-26689-48-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" I want to add Series state update on patch change, so start by factoring out the notification code that was already there so we can add the series update at the same level. Signed-off-by: Damien Lespiau --- patchwork/models.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/patchwork/models.py b/patchwork/models.py index 02763c5..e14d843 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -524,12 +524,8 @@ class PatchChangeNotification(models.Model): last_modified = models.DateTimeField(default = datetime.datetime.now) orig_state = models.ForeignKey(State) -def _patch_change_callback(sender, instance, **kwargs): - # we only want notification of modified patches - if instance.pk is None: - return - - if instance.project is None or not instance.project.send_notifications: +def _patch_queue_notifications(instance): + if not instance.project.send_notifications: return try: @@ -560,4 +556,14 @@ def _patch_change_callback(sender, instance, **kwargs): notification.last_modified = datetime.datetime.now() notification.save() +def _patch_change_callback(sender, instance, **kwargs): + # we only want notification of modified patches + if instance.pk is None: + return + + if instance.project is None: + return; + + _patch_queue_notifications(instance) + models.signals.pre_save.connect(_patch_change_callback, sender = Patch)