From c8c276feb7707c446e3814cbae8070dce90f4573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 12 Aug 2020 22:47:55 +0800 Subject: [PATCH] Applied the standardized control flow to the txn_sort view in the accounting application. --- accounting/views.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/accounting/views.py b/accounting/views.py index 01f498c..3995a4d 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -944,15 +944,14 @@ def txn_sort(request, date): if x.ord != post[F"transaction-{x.pk}-ord"]] if len(modified) == 0: - messages.success(request, gettext_noop( - "The transaction orders were not modified.")) - return redirect(request.GET.get("r") or reverse("accounting:home")) - - with transaction.atomic(): - for x in modified: - Transaction.objects.filter(pk=x[0].pk).update(ord=x[1]) - messages.success(request, gettext_noop( - "The transaction orders were saved successfully.")) + message = gettext_noop("The transaction orders were not modified.") + else: + with transaction.atomic(): + for x in modified: + Transaction.objects.filter(pk=x[0].pk).update(ord=x[1]) + message = gettext_noop( + "The transaction orders were saved successfully.") + messages.success(request, message) return redirect(request.GET.get("r") or reverse("accounting:home"))