Replaced the use of success_redirect with django.contrib.messages in the views of the Mia core application.

This commit is contained in:
依瑪貓 2020-08-08 10:16:30 +08:00
parent c9f21b679b
commit 8793e8bc79

View File

@ -22,6 +22,7 @@ import json
import re import re
from django.conf import settings from django.conf import settings
from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.db.models import Sum, Case, When, F, Q, Max, Count, BooleanField from django.db.models import Sum, Case, When, F, Q, Max, Count, BooleanField
from django.db.models.functions import TruncMonth, Coalesce, Now from django.db.models.functions import TruncMonth, Coalesce, Now
@ -37,7 +38,7 @@ from django.views.generic import RedirectView, ListView
from mia_core.digest_auth import login_required from mia_core.digest_auth import login_required
from mia_core.period import Period from mia_core.period import Period
from mia_core.status import success_redirect, error_redirect from mia_core.status import error_redirect
from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder, \ from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder, \
strip_form, new_pk, PaginationException strip_form, new_pk, PaginationException
from .models import Record, Transaction, Account from .models import Record, Transaction, Account
@ -900,10 +901,11 @@ def txn_store(request, txn_type, txn=None):
old_date = txn.date old_date = txn.date
fill_txn_from_post(txn_type, txn, post) fill_txn_from_post(txn_type, txn, post)
if not txn.is_dirty(): if not txn.is_dirty():
messages.success(request, gettext_noop(
"This transaction was not modified."))
url = reverse("accounting:transactions.show", args=(txn_type, txn)) url = reverse("accounting:transactions.show", args=(txn_type, txn))
url = str(UrlBuilder(url).query(r=request.GET.get("r"))) url = str(UrlBuilder(url).query(r=request.GET.get("r")))
message = gettext_noop("This transaction was not modified.") return HttpResponseRedirect(url)
return success_redirect(request, url, message)
# Prepares the data # Prepares the data
user = request.user user = request.user
@ -946,10 +948,11 @@ def txn_store(request, txn_type, txn=None):
record.save() record.save()
for x in txn_to_sort: for x in txn_to_sort:
x.save() x.save()
messages.success(request, gettext_noop(
"This transaction was saved successfully."))
url = reverse("accounting:transactions.show", args=(txn_type, txn)) url = reverse("accounting:transactions.show", args=(txn_type, txn))
url = str(UrlBuilder(url).query(r=request.GET.get("r"))) url = str(UrlBuilder(url).query(r=request.GET.get("r")))
message = gettext_noop("This transaction was saved successfully.") return HttpResponseRedirect(url)
return success_redirect(request, url, message)
@require_POST @require_POST
@ -979,9 +982,10 @@ def txn_delete(request, txn):
txn.delete() txn.delete()
for x in txn_to_sort: for x in txn_to_sort:
x.save() x.save()
messages.success(request, gettext_noop(
"This transaction was deleted successfully."))
url = request.GET.get("r") or reverse("accounting:home") url = request.GET.get("r") or reverse("accounting:home")
message = gettext_noop("This transaction was deleted successfully.") return HttpResponseRedirect(url)
return success_redirect(request, url, message)
@login_required @login_required
@ -1029,17 +1033,18 @@ def txn_sort(request, date):
modified = [x for x in transactions if x.is_dirty()] modified = [x for x in transactions if x.is_dirty()]
if len(modified) == 0: if len(modified) == 0:
messages.success(request, gettext_noop(
"The transaction orders were not modified."))
url = request.GET.get("r") or reverse("accounting:home") url = request.GET.get("r") or reverse("accounting:home")
message = gettext_noop("The transaction orders were not modified.") return HttpResponseRedirect(url)
return success_redirect(request, url, message)
with transaction.atomic(): with transaction.atomic():
for txn in modified: for txn in modified:
txn.save() txn.save()
messages.success(request, gettext_noop(
"The transaction orders were saved successfully."))
url = request.GET.get("r") or reverse("accounting:home") url = request.GET.get("r") or reverse("accounting:home")
message = gettext_noop( return HttpResponseRedirect(url)
"The transaction orders were saved successfully.")
return success_redirect(request, url, message)
@method_decorator(require_GET, name="dispatch") @method_decorator(require_GET, name="dispatch")