Mercurial > hgweb > health
changeset 7118:e7461255b276 future
health/core: Add GettextReportMixin and mixin to Report class.
| author | Feng Shu <tumashu@163.com> |
|---|---|
| date | Fri, 15 Mar 2024 08:29:37 +0800 |
| parents | 802d2903439d |
| children | |
| files | tryton/health/__init__.py tryton/health/core.py tryton/health/health.py tryton/health/report/death_certificate.fodt |
| diffstat | 4 files changed, 22 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health/__init__.py +++ b/tryton/health/__init__.py @@ -116,3 +116,7 @@ Pool.register_mixin( core.ImageReportMixin, Report, module='health') + + Pool.register_mixin( + core.GettextReportMixin, Report, + module='health')
--- a/tryton/health/core.py +++ b/tryton/health/core.py @@ -32,13 +32,6 @@ Image = None -def get_yes_or_no_string(yes=True): - if yes: - return gettext('health.msg_yes_str') - else: - return gettext('health.msg_no_str') - - def convert_date_timezone(sdate, target): """ Convert dates from UTC to local timezone and viceversa @@ -305,6 +298,22 @@ print(f'Matplotlib: Use rcParams: {rc_conf}.') +class GettextReportMixin: + 'Mixin gettext function and some strings need translation and used frequently.' + __slots__ = () + + @classmethod + def get_context(cls, records, header, data): + context = super(GettextReportMixin, cls).get_context( + records, header, data) + + context['yes_str'] = gettext('health.msg_yes_str') + context['no_str'] = gettext('health.msg_no_str') + context['gettext'] = gettext + + return context + + class ImageReportMixin: 'Mixin to operate image in report.' __slots__ = ()
--- a/tryton/health/health.py +++ b/tryton/health/health.py @@ -48,7 +48,7 @@ CanNotModifyVaccination ) -from .core import (get_yes_or_no_string, get_institution, +from .core import (get_institution, compute_age_from_dates, get_age_for_comparison, format_years_months_days, @@ -2858,10 +2858,6 @@ "if autopsy has been done", states=STATES) - # Used by report templates. - def yes_no(self, yes=True): - return get_yes_or_no_string(yes) - dod = fields.DateTime('Date', required=True, help="Date and time of Death", states=STATES)
--- a/tryton/health/report/death_certificate.fodt +++ b/tryton/health/report/death_certificate.fodt @@ -1651,7 +1651,7 @@ <table:table-row> <table:covered-table-cell table:style-name="Table7.A2"/> <table:table-cell table:style-name="Table7.B17" office:value-type="string"> - <text:p text:style-name="GH-Table-Contents-Center">Autopsy: <text:placeholder text:placeholder-type="text"><death_cert.autopsy and death_cert.yes_no(yes=True) or death_cert.yes_no(yes=False)></text:placeholder></text:p> + <text:p text:style-name="GH-Table-Contents-Center">Autopsy: <text:placeholder text:placeholder-type="text"><death_cert.autopsy and yes_str or no_str></text:placeholder></text:p> </table:table-cell> <table:covered-table-cell table:style-name="Table7.D2"/> <table:covered-table-cell/>
