From fc2e89ca1a71a4b68cc9efd5f44953821642c4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 8 Jul 2020 11:07:00 +0800 Subject: [PATCH] Added the currently-specified subject to the template variables, and use it in the template. --- accounting/templates/accounting/cash.html | 2 +- accounting/views.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/accounting/templates/accounting/cash.html b/accounting/templates/accounting/cash.html index ab3e707..e479566 100644 --- a/accounting/templates/accounting/cash.html +++ b/accounting/templates/accounting/cash.html @@ -25,7 +25,7 @@ First written: 2020/7/1 {% block settings %} {% trans "Cash Account for {} in {}" context "Accounting|" as title_format %} - {% format title_format "庫存現金" period.description as title %} + {% format title_format subject.title_zhtw period.description as title %} {% setvar "title" title %} {% endblock %} diff --git a/accounting/views.py b/accounting/views.py index d86fb4e..4a78673 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -26,11 +26,11 @@ from django.urls import reverse from django.utils import dateformat from django.utils.decorators import method_decorator from django.utils.timezone import localdate -from django.utils.translation import get_language +from django.utils.translation import get_language, pgettext from django.views import generic from django.views.decorators.http import require_GET -from accounting.models import Record, Transaction +from accounting.models import Record, Transaction, Subject from mia_core.period import Period from mia import settings from mia_core.digest_auth import digest_login_required @@ -73,11 +73,13 @@ class BaseReportView(generic.ListView): page_no (int): The specified page number page_size (int): The specified page size period (Period): The template period helper + subject (Subject): The currently-specified subject """ page_no = None page_size = None pagination = None period = None + subject = None def get(self, request, *args, **kwargs): """Adds object_list to the context. @@ -128,6 +130,7 @@ class BaseReportView(generic.ListView): def get_context_data(self, **kwargs): data = super(BaseReportView, self).get_context_data(**kwargs) data["period"] = self.period + data["subject"] = self.subject data["pagination_links"] = self.pagination.links return data @@ -152,6 +155,9 @@ class CashReportView(BaseReportView): get_language(), data_start, data_end, self.kwargs["period_spec"]) if self.kwargs["subject_code"] == "0": + self.subject = Subject(code="0") + self.subject.title_zhtw = pgettext( + "Accounting|", "Current assets and liabilities") records = Record.objects.raw( """SELECT r.* FROM accounting_records AS r @@ -184,6 +190,8 @@ ORDER BY r.ord""", [self.period.start, self.period.end]) else: + self.subject = Subject.objects.filter( + code=self.kwargs["subject_code"]).first() records = Record.objects.raw( """SELECT r.* FROM accounting_records AS r @@ -210,8 +218,8 @@ ORDER BY r.ord""", [self.period.start, self.period.end, - self.kwargs["subject_code"] + "%", - self.kwargs["subject_code"] + "%"]) + self.subject.code + "%", + self.subject.code + "%"]) self.pagination = Pagination( self.request.get_full_path(), records, self.page_no, self.page_size, True)