diff --git a/core/forms.py b/core/forms.py index f6621ee7..9e9b9a07 100644 --- a/core/forms.py +++ b/core/forms.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from django import forms -from django.utils import timezone from django.conf import settings +from django.utils import timezone +from django.utils.translation import gettext as _ from core import models @@ -77,7 +78,7 @@ class ChildDeleteForm(forms.ModelForm): confirm_name = self.cleaned_data['confirm_name'] if confirm_name != str(self.instance): raise forms.ValidationError( - 'Name does not match child name.', code='confirm_mismatch') + _('Name does not match child name.'), code='confirm_mismatch') return confirm_name def save(self, commit=True): diff --git a/core/models.py b/core/models.py index 38e5c27a..0656b0ad 100644 --- a/core/models.py +++ b/core/models.py @@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError from django.db import models from django.template.defaultfilters import slugify from django.utils import timezone +from django.utils.translation import gettext_lazy as _ def validate_date(date, field_name): @@ -17,7 +18,7 @@ def validate_date(date, field_name): """ if date and date > timezone.localdate(): raise ValidationError( - {field_name: 'Date can not be in the future.'}, + {field_name: _('Date can not be in the future.')}, code='date_invalid') @@ -31,10 +32,10 @@ def validate_duration(model, max_duration=timedelta(hours=24)): if model.start and model.end: if model.start > model.end: raise ValidationError( - 'Start time must come before end time.', + _('Start time must come before end time.'), code='end_before_start') if model.end - model.start > max_duration: - raise ValidationError('Duration too long.', code='max_duration') + raise ValidationError(_('Duration too long.'), code='max_duration') def validate_unique_period(queryset, model): @@ -50,7 +51,7 @@ def validate_unique_period(queryset, model): if model.start and model.end: if queryset.filter(start__lte=model.end, end__gte=model.start): raise ValidationError( - 'Another entry intersects the specified time period.', + _('Another entry intersects the specified time period.'), code='period_intersection') @@ -63,7 +64,7 @@ def validate_time(time, field_name): """ if time and time > timezone.localtime(): raise ValidationError( - {field_name: 'Date/time can not be in the future.'}, + {field_name: _('Date/time can not be in the future.')}, code='time_invalid') @@ -84,7 +85,8 @@ class Child(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['last_name', 'first_name'] - verbose_name_plural = 'Children' + verbose_name = _('Child') + verbose_name_plural = _('Children') def __str__(self): return '{} {}'.format(self.first_name, self.last_name) @@ -103,15 +105,19 @@ class Child(models.Model): class DiaperChange(models.Model): model_name = 'diaperchange' child = models.ForeignKey( - 'Child', related_name='diaper_change', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='diaper_change', + verbose_name=_('Child') + ) time = models.DateTimeField(blank=False, null=False) wet = models.BooleanField() solid = models.BooleanField() color = models.CharField(max_length=255, blank=True, choices=[ - ('black', 'Black'), - ('brown', 'Brown'), - ('green', 'Green'), - ('yellow', 'Yellow'), + ('black', _('Black')), + ('brown', _('Brown')), + ('green', _('Green')), + ('yellow', _('Yellow')), ]) objects = models.Manager() @@ -119,6 +125,8 @@ class DiaperChange(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-time'] + verbose_name = _('Diaper Change') + verbose_name_plural = _('Diaper Changes') def __str__(self): return 'Diaper Change' @@ -139,24 +147,28 @@ class DiaperChange(models.Model): # One or both of Wet and Solid is required. if not self.wet and not self.solid: raise ValidationError( - 'Wet and/or solid is required.', code='wet_or_solid') + _('Wet and/or solid is required.'), code='wet_or_solid') class Feeding(models.Model): model_name = 'feeding' child = models.ForeignKey( - 'Child', related_name='feeding', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='feeding', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) type = models.CharField(max_length=255, choices=[ - ('breast milk', 'Breast milk'), - ('formula', 'Formula'), + ('breast milk', _('Breast milk')), + ('formula', _('Formula')), ]) method = models.CharField(max_length=255, choices=[ - ('bottle', 'Bottle'), - ('left breast', 'Left breast'), - ('right breast', 'Right breast'), + ('bottle', _('Bottle')), + ('left breast', _('Left breast')), + ('right breast', _('Right breast')), ]) amount = models.FloatField(blank=True, null=True) @@ -165,6 +177,8 @@ class Feeding(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] + verbose_name = _('Feeding') + verbose_name_plural = _('Feedings') def __str__(self): return 'Feeding' @@ -184,14 +198,18 @@ class Feeding(models.Model): if self.type == 'formula'and self.method != 'bottle': raise ValidationError( {'method': - 'Only "Bottle" method is allowed with "Formula" type.'}, + _('Only "Bottle" method is allowed with "Formula" type.')}, code='bottle_formula_mismatch') class Note(models.Model): model_name = 'note' child = models.ForeignKey( - 'Child', related_name='note', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='note', + verbose_name=_('Child') + ) note = models.TextField() time = models.DateTimeField(auto_now=True) @@ -200,6 +218,8 @@ class Note(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-time'] + verbose_name = _('Note') + verbose_name_plural = _('Notes') def __str__(self): return 'Note' @@ -214,7 +234,11 @@ class NapsManager(models.Manager): class Sleep(models.Model): model_name = 'sleep' child = models.ForeignKey( - 'Child', related_name='sleep', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='sleep', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) @@ -225,7 +249,8 @@ class Sleep(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] - verbose_name_plural = 'Sleep' + verbose_name = _('Sleep') + verbose_name_plural = _('Sleep') def __str__(self): return 'Sleep' @@ -257,7 +282,7 @@ class Timer(models.Model): start = models.DateTimeField( default=timezone.now, blank=False, - verbose_name='Start Time' + verbose_name=_('Start Time') ) end = models.DateTimeField(blank=True, null=True, editable=False) duration = models.DurationField(null=True, editable=False) @@ -270,6 +295,8 @@ class Timer(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-active', '-start', '-end'] + verbose_name = _('Timer') + verbose_name_plural = _('Timers') def __str__(self): return self.name or 'Timer #{}'.format(self.id) @@ -315,7 +342,11 @@ class Timer(models.Model): class TummyTime(models.Model): model_name = 'tummytime' child = models.ForeignKey( - 'Child', related_name='tummy_time', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='tummy_time', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) @@ -326,6 +357,8 @@ class TummyTime(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] + verbose_name = _('Tummy Time') + verbose_name_plural = _('Tummy Time') def __str__(self): return 'Tummy Time' @@ -346,7 +379,11 @@ class TummyTime(models.Model): class Weight(models.Model): model_name = 'weight' child = models.ForeignKey( - 'Child', related_name='weight', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='weight', + verbose_name=_('Child') + ) weight = models.FloatField(blank=False, null=False) date = models.DateField(blank=False, null=False) @@ -355,7 +392,8 @@ class Weight(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-date'] - verbose_name_plural = 'Weight' + verbose_name = _('Weight') + verbose_name_plural = _('Weight') def __str__(self): return 'Weight' diff --git a/core/templates/core/child_confirm_delete.html b/core/templates/core/child_confirm_delete.html index 07a14a27..a8357fb7 100644 --- a/core/templates/core/child_confirm_delete.html +++ b/core/templates/core/child_confirm_delete.html @@ -1,20 +1,22 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Child{% endblock %} +{% block title %}{% trans "Delete a Child" %}{% endblock %} {% block breadcrumbs %} -
- Born {{ object.birth_date }}
- Age {{ object.birth_date|timesince }}
+ {% trans "Born" %} {{ object.birth_date }}
+ {% trans "Age" %} {{ object.birth_date|timesince }}
Child | -Wet | -Solid | -Color | -Time | -Actions | +{% trans "Child" %} | +{% trans "Wet" %} | +{% trans "Solid" %} | +{% trans "Color" %} | +{% trans "Time" %} | +{% trans "Actions" %} | {{ change.color }} | {{ change.time|date:'n/j/y G:i' }} |
-
+
{% if perms.core.change_diaperchange %}
@@ -51,7 +50,7 @@
{% empty %}
No diaper changes found. |
+ {% trans "No diaper changes found." %} |
|
@@ -61,7 +60,7 @@
{% if perms.core.add_diaperchange %}
- Add a Change
+ {% trans "Add a Change" %}
{% endif %}
diff --git a/core/templates/core/feeding_confirm_delete.html b/core/templates/core/feeding_confirm_delete.html
index 5d294ec1..8d5a0b8f 100644
--- a/core/templates/core/feeding_confirm_delete.html
+++ b/core/templates/core/feeding_confirm_delete.html
@@ -1,18 +1,18 @@
{% extends 'babybuddy/page.html' %}
-{% load widget_tweaks %}
+{% load i18n widget_tweaks %}
-{% block title %}Delete a Feeding{% endblock %}
+{% block title %}{% trans "Delete a Feeding" %}{% endblock %}
{% block breadcrumbs %}
-
---|
Child | -Method | -Type | -Amt. | -Duration | -Date | -Actions | +{% trans "Child" %} | +{% trans "Method" %} | +{% trans "Type" %} | + {% comment %}Abbreviation of "Amount"{% endcomment %} +{% trans "Amt." %} | +{% trans "Duration" %} | +{% trans "Date" %} | +{% trans "Actions" %} | {{ feeding.duration|duration_string }} | {{ feeding.start|date:'n/j/y G:i' }} |
-
+
{% if perms.core.change_feeding %}
@@ -57,7 +57,7 @@
{% empty %}
No feedings found. |
+ {% trans "No feedings found." %} |
|
@@ -67,7 +67,7 @@
{% if perms.core.add_feeding %}
- Add a Feeding
+ {% trans "Add a Feeding" %}
{% endif %}
diff --git a/core/templates/core/note_confirm_delete.html b/core/templates/core/note_confirm_delete.html
index 6fc62977..a70ffa02 100644
--- a/core/templates/core/note_confirm_delete.html
+++ b/core/templates/core/note_confirm_delete.html
@@ -1,18 +1,18 @@
{% extends 'babybuddy/page.html' %}
-{% load widget_tweaks %}
+{% load i18n widget_tweaks %}
-{% block title %}Delete a Note{% endblock %}
+{% block title %}{% trans "Delete a Note" %}{% endblock %}
{% block breadcrumbs %}
-
---|
Child | -Note | -Time | -Actions | +{% trans "Child" %} | +{% trans "Note" %} | +{% trans "Time" %} | +{% trans "Actions" %} | {{ note.note }} | {{ note.time }} |
-
+
{% if perms.core.change_note %}
@@ -46,7 +46,7 @@
{% empty %}
No notes found. |
+ {% trans "No notes found." %} |
|
@@ -56,7 +56,7 @@
{% if perms.core.add_note %}
- Add a Note
+ {% trans "Add a Note" %}
{% endif %}
diff --git a/core/templates/core/sleep_confirm_delete.html b/core/templates/core/sleep_confirm_delete.html
index 1756fdcd..56c265e4 100644
--- a/core/templates/core/sleep_confirm_delete.html
+++ b/core/templates/core/sleep_confirm_delete.html
@@ -1,18 +1,18 @@
{% extends 'babybuddy/page.html' %}
-{% load widget_tweaks %}
+{% load i18n widget_tweaks %}
-{% block title %}Delete a Sleep Entry{% endblock %}
+{% block title %}{% trans "Delete a Sleep Entry" %}{% endblock %}
{% block breadcrumbs %}
-
---|
Child | -Duration | -Start | -End | -Nap | -Actions | +{% trans "Child" %} | +{% trans "Duration" %} | +{% trans "Start" %} | +{% trans "End" %} | +{% trans "Nap" %} | +{% trans "Actions" %} | {{ sleep.end|date:'n/j/y G:i' }} | {{ sleep.nap|bool_icon }} |
-
+
{% if perms.core.change_sleep %}
@@ -50,7 +50,7 @@
{% empty %}
No sleep entries found. |
+ {% trans "No sleep entries found." %} |
|
@@ -60,7 +60,7 @@
{% if perms.core.add_sleep %}
- Add a Sleep Entry
+ {% trans "Add a Sleep Entry" %}
{% endif %}
diff --git a/core/templates/core/timer_confirm_delete.html b/core/templates/core/timer_confirm_delete.html
index 54e56223..853effb8 100644
--- a/core/templates/core/timer_confirm_delete.html
+++ b/core/templates/core/timer_confirm_delete.html
@@ -1,19 +1,19 @@
{% extends 'babybuddy/page.html' %}
-{% load widget_tweaks %}
+{% load i18n widget_tweaks %}
-{% block title %}Delete {{ object }}{% endblock %}
+{% block title %}{% blocktrans %}Delete {{ object }}{% endblocktrans %}{% endblock %}
{% block breadcrumbs %}
-
---|
Name | -Start | -Duration | -End | -Active | -User | +{% trans "Name" %} | +{% trans "Start" %} | +{% trans "Duration" %} | +{% trans "End" %} | +{% trans "Active" %} | +{% trans "User" %} | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
No timer entries found. | +{% trans "No timer entries found." %} |
Child | -Duration | -Start | -End | -Milestone | -Actions | +{% trans "Child" %} | +{% trans "Duration" %} | +{% trans "Start" %} | +{% trans "End" %} | +{% trans "Milestone" %} | +{% trans "Actions" %} | {{ tummytime.end|date:'n/j/y G:i' }} | {{ tummytime.milestone }} |
-
+
{% if perms.core.change_tummytime %}
@@ -51,7 +50,7 @@
{% empty %}
No tummy time entries found. |
+ {% trans "No tummy time entries found." %} |
|
@@ -61,7 +60,7 @@
{% if perms.core.add_tummytime %}
- Add a Tummy Time Entry
+ {% trans "Add a Tummy Time Entry" %}
{% endif %}
{% endblock %}
\ No newline at end of file
diff --git a/core/templates/core/weight_confirm_delete.html b/core/templates/core/weight_confirm_delete.html
index 839a58a1..40cb1759 100644
--- a/core/templates/core/weight_confirm_delete.html
+++ b/core/templates/core/weight_confirm_delete.html
@@ -1,18 +1,18 @@
{% extends 'babybuddy/page.html' %}
-{% load widget_tweaks %}
+{% load i18n widget_tweaks %}
-{% block title %}Delete a Weight Entry{% endblock %}
+{% block title %}{% trans "Delete a Weight Entry" %}{% endblock %}
{% block breadcrumbs %}
-
---|
Child | -Weight | -Date | -Actions | +{% trans "Child" %} | +{% trans "Weight" %} | +{% trans "Date" %} | +{% trans "Actions" %} | {{ object.weight }} | {{ object.date }} |
-
+
{% if perms.core.change_weight %}
@@ -46,7 +46,7 @@
{% empty %}
No weight entries found. |
+ {% trans "No weight entries found." %} |
|
@@ -56,7 +56,7 @@
{% if perms.core.add_weight %}
- Add a Weight Entry
+ {% trans "Add a Weight Entry" %}
{% endif %}
diff --git a/core/views.py b/core/views.py
index cc4b2dfb..783f1116 100644
--- a/core/views.py
+++ b/core/views.py
@@ -3,6 +3,7 @@ from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.urls import reverse, reverse_lazy
from django.utils import timezone
+from django.utils.translation import gettext as _
from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
@@ -16,9 +17,9 @@ class CoreAddView(PermissionRequired403Mixin, SuccessMessageMixin, CreateView):
def get_success_message(self, cleaned_data):
cleaned_data['model'] = self.model._meta.verbose_name.title()
if 'child' in cleaned_data:
- self.success_message = '%(model)s entry for %(child)s added!'
+ self.success_message = _('%(model)s entry for %(child)s added!')
else:
- self.success_message = '%(model)s entry added!'
+ self.success_message = _('%(model)s entry added!')
return self.success_message % cleaned_data
@@ -27,9 +28,9 @@ class CoreUpdateView(PermissionRequired403Mixin, SuccessMessageMixin,
def get_success_message(self, cleaned_data):
cleaned_data['model'] = self.model._meta.verbose_name.title()
if 'child' in cleaned_data:
- self.success_message = '%(model)s entry for %(child)s updated.'
+ self.success_message = _('%(model)s entry for %(child)s updated.')
else:
- self.success_message = '%(model)s entry updated.'
+ self.success_message = _('%(model)s entry updated.')
return self.success_message % cleaned_data
@@ -58,7 +59,7 @@ class ChildAdd(CoreAddView):
permission_required = ('core.add_child',)
form_class = forms.ChildForm
success_url = reverse_lazy('core:child-list')
- success_message = '%(first_name)s %(last_name)s added!'
+ success_message = _('%(first_name)s %(last_name)s added!')
class ChildDetail(PermissionRequired403Mixin, DetailView):
@@ -286,7 +287,7 @@ class TimerRestart(PermissionRequired403Mixin, RedirectView):
class TimerStop(PermissionRequired403Mixin, SuccessMessageMixin, RedirectView):
permission_required = ('core.change_timer',)
- success_message = '%(timer)s stopped.'
+ success_message = _('%(timer)s stopped.')
def get(self, request, *args, **kwargs):
instance = models.Timer.objects.get(id=kwargs['pk'])
---|