mirror of https://github.com/snachodog/mybuddy.git
Merge pull request #138 from phardy/method-select
Auto select "bottle" method for formula and fortified milk types
This commit is contained in:
commit
8898a04edf
|
@ -43,12 +43,16 @@ def set_initial_values(kwargs, form_type):
|
|||
'end': timer.end or timezone.now()
|
||||
})
|
||||
|
||||
# Set initial type value for Feeding instance based on last type used.
|
||||
# Set type and method values for Feeding instance based on last feed.
|
||||
if form_type == FeedingForm and 'child' in kwargs['initial']:
|
||||
last_feeding = models.Feeding.objects.filter(
|
||||
child=kwargs['initial']['child']).order_by('end').last()
|
||||
if last_feeding:
|
||||
kwargs['initial'].update({'type': last_feeding.type})
|
||||
last_type = last_feeding.type
|
||||
last_feed_args = {'type': last_feeding.type}
|
||||
if last_type in ['formula', 'fortified breast milk']:
|
||||
last_feed_args['method'] = 'bottle'
|
||||
kwargs['initial'].update(last_feed_args)
|
||||
|
||||
# Remove custom kwargs so they do not interfere with `super` calls.
|
||||
for key in ['child', 'timer']:
|
||||
|
|
|
@ -35,5 +35,11 @@
|
|||
defaultDate: false
|
||||
});
|
||||
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'));
|
||||
$('#id_type').change(function() {
|
||||
var feed_type=$('#id_type').val();
|
||||
if (feed_type=='formula'||feed_type=='fortified breast milk') {
|
||||
$('#id_method').val('bottle');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -87,29 +87,51 @@ class InitialValuesTestCase(FormsTestCaseBase):
|
|||
last_name='Two',
|
||||
birth_date=timezone.localdate()
|
||||
)
|
||||
child_three = models.Child.objects.create(
|
||||
first_name='Child',
|
||||
last_name='Three',
|
||||
birth_date=timezone.localdate()
|
||||
)
|
||||
start_time = timezone.localtime() - timezone.timedelta(hours=4)
|
||||
end_time = timezone.localtime() - timezone.timedelta(hours=3,
|
||||
minutes=30)
|
||||
f_one = models.Feeding.objects.create(
|
||||
child=self.child,
|
||||
start=timezone.localtime() - timezone.timedelta(hours=4),
|
||||
end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30),
|
||||
start=start_time,
|
||||
end=end_time,
|
||||
type='breast milk',
|
||||
method='left breast'
|
||||
)
|
||||
f_two = models.Feeding.objects.create(
|
||||
child=child_two,
|
||||
start=timezone.localtime() - timezone.timedelta(hours=4),
|
||||
end=timezone.localtime() - timezone.timedelta(hours=3, minutes=30),
|
||||
start=start_time,
|
||||
end=end_time,
|
||||
type='formula',
|
||||
method='bottle'
|
||||
)
|
||||
f_three = models.Feeding.objects.create(
|
||||
child=child_three,
|
||||
start=start_time,
|
||||
end=end_time,
|
||||
type='fortified breast milk',
|
||||
method='bottle'
|
||||
)
|
||||
|
||||
page = self.c.get('/feedings/add/')
|
||||
self.assertTrue('type' not in page.context['form'].initial)
|
||||
|
||||
page = self.c.get('/feedings/add/?child={}'.format(self.child.slug))
|
||||
self.assertEqual(page.context['form'].initial['type'], f_one.type)
|
||||
self.assertFalse('method' in page.context['form'].initial)
|
||||
|
||||
page = self.c.get('/feedings/add/?child={}'.format(child_two.slug))
|
||||
self.assertEqual(page.context['form'].initial['type'], f_two.type)
|
||||
self.assertEqual(page.context['form'].initial['method'], f_two.method)
|
||||
|
||||
page = self.c.get('/feedings/add/?child={}'.format(child_three.slug))
|
||||
self.assertEqual(page.context['form'].initial['type'], f_three.type)
|
||||
self.assertEqual(page.context['form'].initial['method'],
|
||||
f_three.method)
|
||||
|
||||
def test_timer_set(self):
|
||||
self.timer.stop()
|
||||
|
|
Loading…
Reference in New Issue