Add 24 hour time format override support to input fields (#148)

This commit is contained in:
Christopher C. Wells 2020-07-21 22:03:08 -07:00
parent d5dc329cf8
commit 4d71f9c5ec
8 changed files with 48 additions and 16 deletions

View File

@ -7,6 +7,7 @@ if settings.USE_24_HOUR_TIME_FORMAT:
TIME_FORMAT = 'H:i:s'
DATETIME_INPUT_FORMATS = [
'%m/%d/%Y %H:%I:%S' # '10/25/2006 14:30:59'
'%m/%d/%Y %H:%I' # '10/25/2006 14:30'
]
else:
# These formats are added to support the locale style of Baby Buddy's

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load i18n %}
{% load datetimepicker i18n %}
{% block title %}
{% if request.resolver_match.url_name == 'diaperchange-update' %}
@ -31,6 +31,8 @@
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'));
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'), {
format: '{% datetimepicker_format %}'
});
</script>
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load i18n %}
{% load datetimepicker i18n %}
{% block title %}
{% if request.resolver_match.url_name == 'feeding-update' %}
@ -32,12 +32,15 @@
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false
defaultDate: false,
format: '{% datetimepicker_format %}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'), {
format: '{% datetimepicker_format %}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'));
$('#id_type').change(function() {
var feed_type=$('#id_type').val();
if (feed_type=='formula'||feed_type=='fortified breast milk') {
if (feed_type === 'formula' || feed_type === 'fortified breast milk') {
$('#id_method').val('bottle');
}
});

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load i18n %}
{% load datetimepicker i18n %}
{% block title %}
{% if request.resolver_match.url_name == 'sleep-update' %}
@ -32,8 +32,11 @@
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false
defaultDate: false,
format: '{% datetimepicker_format %}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'), {
format: '{% datetimepicker_format %}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'));
</script>
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load i18n %}
{% load datetimepicker i18n %}
{% block title %}
{% if object %}
@ -31,6 +31,8 @@
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'));
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'), {
format: '{% datetimepicker_format %}'
});
</script>
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load duration i18n %}
{% load datetimepicker duration i18n %}
{% block title %}{% trans "Timer" %}{% endblock %}
@ -27,7 +27,7 @@
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
format: 'L LTS'
format: '{% datetimepicker_format 'L LTS' %}'
});
</script>
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends 'babybuddy/page.html' %}
{% load i18n %}
{% load datetimepicker i18n %}
{% block title %}
{% if request.resolver_match.url_name == 'tummytime-update' %}
@ -33,10 +33,10 @@
<script type="text/javascript">
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false,
format: 'L LTS'
format: '{% datetimepicker_format 'L LTS' %}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'), {
format: 'L LTS'
format: '{% datetimepicker_format 'L LTS' %}'
});
</script>
{% endblock %}

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from django import template
from django.conf import settings
register = template.Library()
@register.simple_tag()
def datetimepicker_format(format_string='L LT'):
"""
Return a datetime format string for momentjs, with support for 24 hour time
override setting.
:param format_string: the default format string (locale based)
:return: the format string to use, as 24 hour time if configured.
"""
if settings.USE_24_HOUR_TIME_FORMAT:
if format_string == 'L LT':
return 'L HH:mm'
elif format_string == 'L LTS':
return 'L HH:mm:ss'
return format_string