Merge remote-tracking branch 'origin/master' into 333-en-gb-datetimeformat

This commit is contained in:
Christopher C. Wells 2021-11-28 14:44:36 -05:00
commit f0a7f53752
12 changed files with 1055 additions and 972 deletions

View File

@ -61,13 +61,10 @@ jobs:
deploy:
needs: test
runs-on: ubuntu-latest
env:
DEPLOY_DEMO: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
steps:
- if: ${{ env.DEPLOY_DEMO }}
uses: actions/checkout@v2
- if: ${{ env.DEPLOY_DEMO }}
name: Deploy demo
- uses: actions/checkout@v2
- name: Deploy demo
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}

View File

@ -3,64 +3,90 @@ from django_filters import rest_framework as filters
from core import models
class TimeFieldFilter(filters.FilterSet):
date = filters.DateFilter(field_name='date', label='Date')
date_min = filters.DateFilter(field_name='time__date', label='Min. Date',
lookup_expr='gte')
class ChildFieldFilter(filters.FilterSet):
class Meta:
abstract = True
fields = ['child']
class TimeFieldFilter(ChildFieldFilter):
date = filters.DateFilter(field_name='time__date', label='Date')
date_max = filters.DateFilter(field_name='time__date', label='Max. Date',
lookup_expr='lte')
date_min = filters.DateFilter(field_name='time__date', label='Min. Date',
lookup_expr='gte')
class Meta:
abstract = True
fields = sorted(ChildFieldFilter.Meta.fields + [
'date',
'date_max',
'date_min'
])
class StartEndFieldFilter(filters.FilterSet):
class StartEndFieldFilter(ChildFieldFilter):
end = filters.DateFilter(field_name='end__date', label='End Date')
end_min = filters.DateFilter(field_name='end__date', label='Min. End Date',
lookup_expr='gte')
end_max = filters.DateFilter(field_name='end__date', label='Max. End Date',
lookup_expr='lte')
end_min = filters.DateFilter(field_name='end__date', label='Min. End Date',
lookup_expr='gte')
start = filters.DateFilter(field_name='start__date', label='Start Date')
start_min = filters.DateFilter(field_name='start__date', lookup_expr='gte',
label='Min. Start Date',)
start_end = filters.DateFilter(field_name='start__date', lookup_expr='lte',
start_max = filters.DateFilter(field_name='start__date', lookup_expr='lte',
label='Max. End Date')
start_min = filters.DateFilter(field_name='start__date', lookup_expr='gte',
label='Min. Start Date')
class Meta:
abstract = True
fields = sorted(ChildFieldFilter.Meta.fields + [
'end',
'end_max',
'end_min',
'start',
'start_max',
'start_min'
])
class DiaperChangeFilter(TimeFieldFilter):
class Meta:
class Meta(TimeFieldFilter.Meta):
model = models.DiaperChange
fields = ['child', 'wet', 'solid', 'color', 'amount']
fields = sorted(TimeFieldFilter.Meta.fields + [
'wet',
'solid',
'color',
'amount'
])
class FeedingFilter(StartEndFieldFilter):
class Meta:
class Meta(StartEndFieldFilter.Meta):
model = models.Feeding
fields = ['child', 'type', 'method']
fields = sorted(StartEndFieldFilter.Meta.fields + ['type', 'method'])
class NoteFilter(TimeFieldFilter):
class Meta:
class Meta(TimeFieldFilter.Meta):
model = models.Note
fields = ['child']
class SleepFilter(StartEndFieldFilter):
class Meta:
class Meta(StartEndFieldFilter.Meta):
model = models.Sleep
fields = ['child']
class TemperatureFilter(TimeFieldFilter):
class Meta:
class Meta(TimeFieldFilter.Meta):
model = models.Temperature
fields = ['child']
class TimerFilter(StartEndFieldFilter):
class Meta:
class Meta(StartEndFieldFilter.Meta):
model = models.Timer
fields = ['child', 'active', 'user']
fields = sorted(StartEndFieldFilter.Meta.fields + ['active', 'user'])
class TummyTimeFilter(StartEndFieldFilter):
class Meta:
class Meta(StartEndFieldFilter.Meta):
model = models.TummyTime
fields = ['child']

View File

@ -11,4 +11,6 @@ class APIMetadata(metadata.SimpleMetadata):
data.pop('description')
if hasattr(view, 'filterset_fields'):
data.update({'filters': view.filterset_fields})
elif hasattr(view, 'filterset_class'):
data.update({'filters': view.filterset_class.Meta.fields})
return data

View File

@ -3,7 +3,7 @@ import time
import pytz
from django.conf import settings
from django.utils import timezone
from django.utils import timezone, translation
from django.conf.locale.en import formats as formats_en_us
from django.conf.locale.en_GB import formats as formats_en_gb
@ -58,10 +58,6 @@ def update_en_gb_date_formats():
'%d/%m/%Y %I:%M %p', # '25/10/2006 2:30 PM'
]
# Not setting this makes pages display using the the 25/10/2006 as desired
# Add custom "short" version of `MONTH_DAY_FORMAT`.
# formats_en_gb.SHORT_MONTH_DAY_FORMAT = 'j M'
# Append all other input formats from the base locale.
formats_en_gb.DATETIME_INPUT_FORMATS = \
custom_input_formats + formats_en_gb.DATETIME_INPUT_FORMATS
@ -76,11 +72,29 @@ class UserLanguageMiddleware:
def __call__(self, request):
user = request.user
if hasattr(user, 'settings') and user.settings.language == 'en-US':
update_en_us_date_formats()
elif hasattr(user, 'settings') and user.settings.language == 'en-GB':
update_en_gb_date_formats()
return self.get_response(request)
if hasattr(user, 'settings') and user.settings.language:
language = user.settings.language
elif request.LANGUAGE_CODE:
language = request.LANGUAGE_CODE
else:
language = settings.LANGUAGE_CODE
if language:
if language == 'en-US':
update_en_us_date_formats()
elif language == 'en-GB':
update_en_gb_date_formats()
# Set the language before generating the response.
translation.activate(language)
response = self.get_response(request)
# Deactivate the translation before the response is sent so it not
# reused in other threads.
translation.deactivate()
return response
class UserTimezoneMiddleware:

View File

@ -6,6 +6,7 @@ from django.contrib.auth.models import User
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import redirect, render
from django.urls import reverse, reverse_lazy
from django.utils import translation
from django.utils.text import format_lazy
from django.utils.translation import gettext as _, gettext_lazy
from django.views.generic import View
@ -144,7 +145,9 @@ class UserSettings(LoginRequiredMixin, View):
user_settings = form_settings.save(commit=False)
user.settings = user_settings
user.save()
translation.activate(user.settings.language)
messages.success(request, _('Settings saved!'))
translation.deactivate()
return set_language(request)
return render(request, self.template_name, {
'user_form': form_user,

View File

@ -3,7 +3,7 @@ from django.urls import reverse
from django.utils import timezone, timesince
from django.utils.translation import gettext as _
from core.models import DiaperChange, Feeding, Sleep, TummyTime
from core.models import DiaperChange, Feeding, Note, Sleep, TummyTime
from datetime import timedelta
@ -22,6 +22,7 @@ def get_objects(date, child=None):
_add_feedings(min_date, max_date, events, child)
_add_sleeps(min_date, max_date, events, child)
_add_tummy_times(min_date, max_date, events, child)
_add_notes(min_date, max_date, events, child)
events.sort(key=lambda x: x['time'], reverse=True)
@ -169,3 +170,18 @@ def _add_diaper_changes(min_date, max_date, events, child):
args=[instance.id]),
'model_name': instance.model_name
})
def _add_notes(min_date, max_date, events, child):
instances = Note.objects.filter(
time__range=(min_date, max_date)).order_by('-time')
if child:
instances = instances.filter(child=child)
for instance in instances:
events.append({
'time': timezone.localtime(instance.time),
'details': [instance.note],
'edit_link': reverse('core:note-update',
args=[instance.id]),
'model_name': instance.model_name
})

View File

@ -85,7 +85,7 @@ documentation section: [Translation](https://docs.djangoproject.com/en/3.0/topic
### Requirements
- Python 3.6+, pip, pipenv
- NodeJS 14.x and NPM 7.x
- NVM (NodeJS 14.x and NPM 7.x)
- Gulp
- Possibly `libpq-dev`
- This is necessary if `psycopg2` can't find an appropriate prebuilt binary.
@ -96,13 +96,21 @@ documentation section: [Translation](https://docs.djangoproject.com/en/3.0/topic
1. Install required Python packages, including dev packages
pipenv install --three
pipenv install --three --dev
- If this fails, install `libpq-dev` (e.g. `sudo apt install libpq-dev`) and try again.
1. Installed Node 14.x (if necessary)
nvm install 14
1. Activate Node 14.x
nvm use
1. Install Gulp CLI
sudo npm install -g gulp-cli
npm install -g gulp-cli
1. Install required Node packages

View File

@ -45,7 +45,7 @@ python3 /app/babybuddy/manage.py clearsessions
## Heroku
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://dashboard.heroku.com/new?button-url=https%3A%2F%2Fgithub.com%2Fbabybuddy%2Fbabybuddy&template=https%3A%2F%2Fgithub.com%2Fbabybuddy%2Fbabybuddy)
For manual deployments to Heroku without using the "deploy" button, make sure to
create the following settings before pushing:
@ -188,4 +188,4 @@ and 1+ child).
sudo ln -s /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy
sudo service nginx restart
1. That's it (hopefully)! :tada:
1. That's it (hopefully)! :tada:

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
python-3.9.8
python-3.9.9