Add translatable strings support to reports app.

This commit is contained in:
Christopher C. Wells 2019-04-14 13:32:46 -07:00
parent e20903c60b
commit 8ed0e9117a
13 changed files with 56 additions and 42 deletions

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.utils.translation import gettext as _
import plotly.offline as plotly import plotly.offline as plotly
import plotly.graph_objs as go import plotly.graph_objs as go
@ -22,7 +24,7 @@ def diaperchange_lifetimes(changes):
trace = go.Box( trace = go.Box(
y=[round(d.seconds/3600, 2) for d in durations], y=[round(d.seconds/3600, 2) for d in durations],
name='Changes', name=_('Changes'),
jitter=0.3, jitter=0.3,
pointpos=-1.8, pointpos=-1.8,
boxpoints='all' boxpoints='all'
@ -30,8 +32,8 @@ def diaperchange_lifetimes(changes):
layout_args = utils.default_graph_layout_options() layout_args = utils.default_graph_layout_options()
layout_args['height'] = 800 layout_args['height'] = 800
layout_args['title'] = '<b>Diaper Lifetimes</b>' layout_args['title'] = _('<b>Diaper Lifetimes</b>')
layout_args['yaxis']['title'] = 'Time between changes (hours)' layout_args['yaxis']['title'] = _('Time between changes (hours)')
layout_args['yaxis']['zeroline'] = False layout_args['yaxis']['zeroline'] = False
layout_args['yaxis']['dtick'] = 1 layout_args['yaxis']['dtick'] = 1

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.db.models import Count, Case, When from django.db.models import Count, Case, When
from django.db.models.functions import TruncDate from django.db.models.functions import TruncDate
from django.utils.translation import gettext as _
import plotly.offline as plotly import plotly.offline as plotly
import plotly.graph_objs as go import plotly.graph_objs as go
@ -23,28 +24,28 @@ def diaperchange_types(changes):
solid_trace = go.Scatter( solid_trace = go.Scatter(
mode='markers', mode='markers',
name='Solid', name=_('Solid'),
x=list(changes.values_list('date', flat=True)), x=list(changes.values_list('date', flat=True)),
y=list(changes.values_list('solid_count', flat=True)), y=list(changes.values_list('solid_count', flat=True)),
) )
wet_trace = go.Scatter( wet_trace = go.Scatter(
mode='markers', mode='markers',
name='Wet', name=_('Wet'),
x=list(changes.values_list('date', flat=True)), x=list(changes.values_list('date', flat=True)),
y=list(changes.values_list('wet_count', flat=True)) y=list(changes.values_list('wet_count', flat=True))
) )
total_trace = go.Scatter( total_trace = go.Scatter(
name='Total', name=_('Total'),
x=list(changes.values_list('date', flat=True)), x=list(changes.values_list('date', flat=True)),
y=list(changes.values_list('total', flat=True)) y=list(changes.values_list('total', flat=True))
) )
layout_args = utils.default_graph_layout_options() layout_args = utils.default_graph_layout_options()
layout_args['barmode'] = 'stack' layout_args['barmode'] = 'stack'
layout_args['title'] = '<b>Diaper Change Types</b>' layout_args['title'] = _('<b>Diaper Change Types</b>')
layout_args['xaxis']['title'] = 'Date' layout_args['xaxis']['title'] = _('Date')
layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() layout_args['xaxis']['rangeselector'] = utils.rangeselector_date()
layout_args['yaxis']['title'] = 'Number of changes' layout_args['yaxis']['title'] = _('Number of changes')
fig = go.Figure({ fig = go.Figure({
'data': [solid_trace, wet_trace, total_trace], 'data': [solid_trace, wet_trace, total_trace],

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.db.models import Count, Sum from django.db.models import Count, Sum
from django.db.models.functions import TruncDate from django.db.models.functions import TruncDate
from django.utils.translation import gettext as _
import plotly.offline as plotly import plotly.offline as plotly
import plotly.graph_objs as go import plotly.graph_objs as go
@ -32,7 +33,7 @@ def feeding_duration(instances):
averages.append(total['sum']/total['count']) averages.append(total['sum']/total['count'])
trace_avg = go.Scatter( trace_avg = go.Scatter(
name='Average duration', name=_('Average duration'),
line=dict(shape='spline'), line=dict(shape='spline'),
x=list(totals.values_list('date', flat=True)), x=list(totals.values_list('date', flat=True)),
y=[td.seconds/60 for td in averages], y=[td.seconds/60 for td in averages],
@ -40,7 +41,7 @@ def feeding_duration(instances):
text=[_duration_string_ms(td) for td in averages] text=[_duration_string_ms(td) for td in averages]
) )
trace_count = go.Scatter( trace_count = go.Scatter(
name='Total feedings', name=_('Total feedings'),
mode='markers', mode='markers',
x=list(totals.values_list('date', flat=True)), x=list(totals.values_list('date', flat=True)),
y=list(totals.values_list('count', flat=True)), y=list(totals.values_list('count', flat=True)),
@ -49,12 +50,12 @@ def feeding_duration(instances):
) )
layout_args = utils.default_graph_layout_options() layout_args = utils.default_graph_layout_options()
layout_args['title'] = '<b>Average Feeding Durations</b>' layout_args['title'] = _('<b>Average Feeding Durations</b>')
layout_args['xaxis']['title'] = 'Date' layout_args['xaxis']['title'] = _('Date')
layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() layout_args['xaxis']['rangeselector'] = utils.rangeselector_date()
layout_args['yaxis']['title'] = 'Average duration (minutes)' layout_args['yaxis']['title'] = _('Average duration (minutes)')
layout_args['yaxis2'] = dict(layout_args['yaxis']) layout_args['yaxis2'] = dict(layout_args['yaxis'])
layout_args['yaxis2']['title'] = 'Number of feedings' layout_args['yaxis2']['title'] = _('Number of feedings')
layout_args['yaxis2']['overlaying'] = 'y' layout_args['yaxis2']['overlaying'] = 'y'
layout_args['yaxis2']['side'] = 'right' layout_args['yaxis2']['side'] = 'right'

View File

@ -2,6 +2,7 @@
from collections import OrderedDict from collections import OrderedDict
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _
import pandas as pd import pandas as pd
import plotly.offline as plotly import plotly.offline as plotly
@ -124,10 +125,10 @@ def sleep_pattern(instances):
layout_args['barmode'] = 'stack' layout_args['barmode'] = 'stack'
layout_args['hovermode'] = 'closest' layout_args['hovermode'] = 'closest'
layout_args['title'] = '<b>Sleep Pattern</b>' layout_args['title'] = _('<b>Sleep Pattern</b>')
layout_args['height'] = 800 layout_args['height'] = 800
layout_args['xaxis']['title'] = 'Date' layout_args['xaxis']['title'] = _('Date')
layout_args['xaxis']['tickangle'] = -65 layout_args['xaxis']['tickangle'] = -65
layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() layout_args['xaxis']['rangeselector'] = utils.rangeselector_date()
@ -137,7 +138,7 @@ def sleep_pattern(instances):
for i in range(30, 60*24, 30): for i in range(30, 60*24, 30):
ticks[i] = (start + timezone.timedelta(minutes=i)).strftime('%I:%M %p') ticks[i] = (start + timezone.timedelta(minutes=i)).strftime('%I:%M %p')
layout_args['yaxis']['title'] = 'Time of day' layout_args['yaxis']['title'] = _('Time of day')
layout_args['yaxis']['rangemode'] = 'tozero' layout_args['yaxis']['rangemode'] = 'tozero'
layout_args['yaxis']['tickmode'] = 'array' layout_args['yaxis']['tickmode'] = 'array'
layout_args['yaxis']['tickvals'] = list(ticks.keys()) layout_args['yaxis']['tickvals'] = list(ticks.keys())

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _
import plotly.offline as plotly import plotly.offline as plotly
import plotly.graph_objs as go import plotly.graph_objs as go
@ -36,7 +37,7 @@ def sleep_totals(instances):
totals[start.date()] += instance.duration totals[start.date()] += instance.duration
trace = go.Bar( trace = go.Bar(
name='Total sleep', name=_('Total sleep'),
x=list(totals.keys()), x=list(totals.keys()),
y=[td.seconds/3600 for td in totals.values()], y=[td.seconds/3600 for td in totals.values()],
hoverinfo='text', hoverinfo='text',
@ -46,10 +47,10 @@ def sleep_totals(instances):
layout_args = utils.default_graph_layout_options() layout_args = utils.default_graph_layout_options()
layout_args['barmode'] = 'stack' layout_args['barmode'] = 'stack'
layout_args['title'] = '<b>Sleep Totals</b>' layout_args['title'] = _('<b>Sleep Totals</b>')
layout_args['xaxis']['title'] = 'Date' layout_args['xaxis']['title'] = _('Date')
layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() layout_args['xaxis']['rangeselector'] = utils.rangeselector_date()
layout_args['yaxis']['title'] = 'Hours of sleep' layout_args['yaxis']['title'] = _('Hours of sleep')
fig = go.Figure({ fig = go.Figure({
'data': [trace], 'data': [trace],

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.utils.translation import gettext as _
import plotly.offline as plotly import plotly.offline as plotly
import plotly.graph_objs as go import plotly.graph_objs as go
@ -14,7 +16,7 @@ def weight_weight(objects):
objects = objects.order_by('-date') objects = objects.order_by('-date')
trace = go.Scatter( trace = go.Scatter(
name='Weight', name=_('Weight'),
x=list(objects.values_list('date', flat=True)), x=list(objects.values_list('date', flat=True)),
y=list(objects.values_list('weight', flat=True)), y=list(objects.values_list('weight', flat=True)),
fill='tozeroy', fill='tozeroy',
@ -22,10 +24,10 @@ def weight_weight(objects):
layout_args = utils.default_graph_layout_options() layout_args = utils.default_graph_layout_options()
layout_args['barmode'] = 'stack' layout_args['barmode'] = 'stack'
layout_args['title'] = '<b>Weight</b>' layout_args['title'] = _('<b>Weight</b>')
layout_args['xaxis']['title'] = 'Date' layout_args['xaxis']['title'] = _('Date')
layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() layout_args['xaxis']['rangeselector'] = utils.rangeselector_date()
layout_args['yaxis']['title'] = 'Weight' layout_args['yaxis']['title'] = _('Weight')
fig = go.Figure({ fig = go.Figure({
'data': [trace], 'data': [trace],

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Diaper Lifetimes - {{ object }}{% endblock %} {% block title %}{% trans "Diaper Lifetimes" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Diaper Lifetimes</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Diaper Lifetimes" %}</li>
{% endblock %} {% endblock %}

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Diaper Change Types - {{ object }}{% endblock %} {% block title %}{% trans "Diaper Change Types" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Diaper Types</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Diaper Change Types" %}</li>
{% endblock %} {% endblock %}

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Average Feeding Durations - {{ object }}{% endblock %} {% block title %}{% trans "Average Feeding Durations" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Average Feeding Durations</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Average Feeding Durations" %}</li>
{% endblock %} {% endblock %}

View File

@ -1,12 +1,12 @@
{% extends 'babybuddy/page.html' %} {% extends 'babybuddy/page.html' %}
{% load static %} {% load i18n static %}
{% block title %}{% endblock %} {% block title %}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<li class="breadcrumb-item"><a href="{% url 'core:child-list' %}">Children</a></li> <li class="breadcrumb-item"><a href="{% url 'core:child-list' %}">{% trans "Children" %}</a></li>
<li class="breadcrumb-item font-weight-bold"><a href="{% url 'core:child' object.slug %}">{{ object }}</a></li> <li class="breadcrumb-item font-weight-bold"><a href="{% url 'core:child' object.slug %}">{{ object }}</a></li>
<li class="breadcrumb-item">Reports</li> <li class="breadcrumb-item">{% trans "Reports" %}</li>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -16,7 +16,7 @@
{% else %} {% else %}
<div class="jumbotron text-center"> <div class="jumbotron text-center">
<i class="icon icon-sad" aria-hidden="true"></i> <i class="icon icon-sad" aria-hidden="true"></i>
There is no enough data to generate this report. {% trans "There is no enough data to generate this report." %}
<i class="icon icon-sad" aria-hidden="true"></i> <i class="icon icon-sad" aria-hidden="true"></i>
</div> </div>
{% endif %} {% endif %}

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Sleep Patterns - {{ object }}{% endblock %} {% block title %}{% trans "Sleep Pattern" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Sleep Pattern</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Sleep Pattern" %}</li>
{% endblock %} {% endblock %}

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Sleep Totals - {{ object }}{% endblock %} {% block title %}{% trans "Sleep Totals" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Sleep Totals</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Sleep Totals" %}</li>
{% endblock %} {% endblock %}

View File

@ -1,8 +1,9 @@
{% extends 'reports/report_base.html' %} {% extends 'reports/report_base.html' %}
{% load i18n %}
{% block title %}Weight - {{ object }}{% endblock %} {% block title %}{% trans "Weight" %} - {{ object }}{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ block.super }} {{ block.super }}
<li class="breadcrumb-item active" aria-current="page">Weight</li> <li class="breadcrumb-item active" aria-current="page">{% trans "Weight" %}</li>
{% endblock %} {% endblock %}